build-and-publish-develop.yml 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. env:
  11. # Use docker.io for Docker Hub if empty
  12. REGISTRY: ghcr.io
  13. jobs:
  14. build-and-publish-opencost:
  15. runs-on: ubuntu-latest
  16. if: ${{ github.event.workflow_run.conclusion == 'success' }}
  17. permissions:
  18. contents: read
  19. packages: write
  20. steps:
  21. - name: Checkout Repo
  22. uses: actions/checkout@v4
  23. - name: Set SHA
  24. id: sha
  25. run: |
  26. echo "OC_SHORTHASH=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  27. - name: Set OpenCost Image Tags
  28. id: tags
  29. run: |
  30. echo "IMAGE_TAG=ghcr.io/${{ github.repository_owner }}/opencost:develop-${{ steps.sha.outputs.OC_SHORTHASH }}" >> $GITHUB_OUTPUT
  31. - name: Build and publish container
  32. uses: ./.github/actions/build-container
  33. with:
  34. actor: ${{ github.actor }}
  35. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  36. image_tag: ${{ steps.tags.outputs.IMAGE_TAG }}
  37. release_version: develop-${{ steps.sha.outputs.OC_SHORTHASH }}
  38. - name: Install crane
  39. uses: imjasonh/crane@v0.12.0
  40. - name: Tag and push latest image
  41. run: |
  42. # Extract the repository part (everything before the last colon)
  43. REPO=$(echo "${{ steps.tags.outputs.IMAGE_TAG }}" | sed 's/:.*$//')
  44. # Create the new tag
  45. NEW_TAG="${REPO}:develop-latest"
  46. echo "Copying ${{ steps.tags.outputs.IMAGE_TAG }} to ${NEW_TAG}"
  47. crane copy "${{ steps.tags.outputs.IMAGE_TAG }}" "${NEW_TAG}"