build-test-image.yml 2.4 KB

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