build-and-publish-develop.yml 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. id-token: write
  22. steps:
  23. - name: Checkout Repo
  24. uses: actions/checkout@v6.0.2
  25. with:
  26. ref: ${{ github.event.workflow_run.head_sha }}
  27. - name: Set SHA
  28. id: sha
  29. run: |
  30. echo "OC_SHORTHASH=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  31. - name: Set OpenCost Image Tags
  32. id: tags
  33. env:
  34. REPO: ${{ github.repository_owner }}
  35. SHORTHASH: ${{ steps.sha.outputs.OC_SHORTHASH }}
  36. run: |
  37. echo "IMAGE_TAG=ghcr.io/$REPO/opencost:develop-$SHORTHASH" >> $GITHUB_OUTPUT
  38. - name: Build and publish container
  39. uses: ./.github/actions/build-container
  40. with:
  41. actor: ${{ github.actor }}
  42. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  43. image_tag: ${{ steps.tags.outputs.IMAGE_TAG }}
  44. release_version: develop-${{ steps.sha.outputs.OC_SHORTHASH }}
  45. - name: Install crane
  46. uses: imjasonh/setup-crane@v0.5
  47. - name: Tag and push latest image
  48. env:
  49. IMAGE_TAG: ${{ steps.tags.outputs.IMAGE_TAG }}
  50. run: |
  51. # Extract the repository part (everything before the last colon)
  52. REPO=$(echo "$IMAGE_TAG" | sed 's/:.*$//')
  53. # Create the new tag
  54. NEW_TAG="${REPO}:develop-latest"
  55. echo "Copying $IMAGE_TAG to ${NEW_TAG}"
  56. crane copy "$IMAGE_TAG" "${NEW_TAG}"
  57. - name: Sign image and attest SLSA provenance
  58. uses: ./.github/actions/sign-image
  59. with:
  60. image: ${{ steps.tags.outputs.IMAGE_TAG }}
  61. workflow-path: .github/workflows/build-and-publish-develop.yml
  62. run-started-at: ${{ github.run_started_at }}