2
0

build-test-image.yml 2.7 KB

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