build-and-publish-develop.yml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. name: Build and Publish Develop
  2. on:
  3. workflow_run:
  4. workflows: [Build/Test]
  5. types: [completed]
  6. branches: [develop]
  7. concurrency:
  8. group: build-opencost-develop
  9. cancel-in-progress: false
  10. permissions: {}
  11. env:
  12. # Use docker.io for Docker Hub if empty
  13. REGISTRY: ghcr.io
  14. jobs:
  15. build-and-publish-opencost:
  16. runs-on: ubuntu-latest
  17. if: ${{ github.event.workflow_run.conclusion == 'success' }}
  18. permissions:
  19. contents: read
  20. packages: write
  21. steps:
  22. - name: Checkout Repo
  23. uses: actions/checkout@v4
  24. - name: Set SHA
  25. id: sha
  26. run: |
  27. echo "OC_SHORTHASH=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  28. - name: Set OpenCost Image Tags
  29. id: tags
  30. env:
  31. REPO: ${{ github.repository_owner }}
  32. SHORTHASH: ${{ steps.sha.outputs.OC_SHORTHASH }}
  33. run: |
  34. echo "IMAGE_TAG=ghcr.io/$REPO/opencost:develop-$SHORTHASH" >> $GITHUB_OUTPUT
  35. - name: Build and publish container
  36. uses: ./.github/actions/build-container
  37. with:
  38. actor: ${{ github.actor }}
  39. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  40. image_tag: ${{ steps.tags.outputs.IMAGE_TAG }}
  41. release_version: develop-${{ steps.sha.outputs.OC_SHORTHASH }}
  42. - name: Install crane
  43. uses: imjasonh/setup-crane@v0.4
  44. - name: Tag and push latest image
  45. env:
  46. IMAGE_TAG: ${{ steps.tags.outputs.IMAGE_TAG }}
  47. run: |
  48. # Extract the repository part (everything before the last colon)
  49. REPO=$(echo "$IMAGE_TAG" | sed 's/:.*$//')
  50. # Create the new tag
  51. NEW_TAG="${REPO}:develop-latest"
  52. echo "Copying $IMAGE_TAG to ${NEW_TAG}"
  53. crane copy "$IMAGE_TAG" "${NEW_TAG}"