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