build-test-image.yml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. name: Build and Publish Test Image
  2. on:
  3. merge_group:
  4. types: [checks_requested]
  5. pull_request_target:
  6. branches:
  7. - develop
  8. env:
  9. REGISTRY: ghcr.io
  10. jobs:
  11. check_actor_permissions:
  12. runs-on: ubuntu-latest
  13. outputs:
  14. ismaintainer: ${{ steps.determine-maintainer.outputs.ismaintainer }}
  15. steps:
  16. - name: Check team membership
  17. uses: tspascoal/get-user-teams-membership@v2
  18. id: teamAffiliation
  19. with:
  20. GITHUB_TOKEN: ${{ secrets.ORG_READER_PAT }}
  21. username: ${{ github.actor }}
  22. organization: opencost
  23. - name: determine if actor is a maintainer
  24. id: determine-maintainer
  25. run: |
  26. echo "Actor: ${{ github.actor }}"
  27. echo "teams: ${{ join(steps.teamAffiliation.outputs.teams, ',') }}"
  28. echo "Is maintainer: ${{ contains(steps.teamAffiliation.outputs.teams, 'OpenCost Maintainers') }}"
  29. echo "ismaintainer=${{ contains(steps.teamAffiliation.outputs.teams, 'OpenCost Maintainers') }}" >> $GITHUB_OUTPUT
  30. build-and-publish-test-image:
  31. runs-on: ubuntu-latest
  32. needs: check_actor_permissions
  33. if: ${{ (always() && !cancelled()) && ( github.event_name == 'merge_group' || needs.check_actor_permissions.outputs.ismaintainer == 'true') }}
  34. permissions:
  35. contents: read
  36. packages: write
  37. steps:
  38. - name: Checkout Repo
  39. uses: actions/checkout@v4
  40. with:
  41. ref: ${{ github.event.merge_group.head_sha || github.event.pull_request.head.sha }}
  42. - name: Set SHA
  43. id: sha
  44. run: |
  45. echo "OC_SHORTHASH=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  46. - name: Set OpenCost Image Tags
  47. id: tags
  48. run: |
  49. echo "IMAGE_TAG=ghcr.io/${{ github.repository_owner }}/opencost:test-${{ steps.sha.outputs.OC_SHORTHASH }}" >> $GITHUB_OUTPUT
  50. - name: Build and publish container
  51. uses: ./.github/actions/build-container
  52. with:
  53. actor: ${{ github.actor }}
  54. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  55. image_tag: ${{ steps.tags.outputs.IMAGE_TAG }}
  56. release_version: test-${{ steps.sha.outputs.OC_SHORTHASH }}