Skip to content

Commit 2186764

Browse files
authored
Merge pull request #1540 from NASA-AMMOS/feature/publish-pr-branch-workflow
GH workflow to publish images for PRs labeled 'publish'
2 parents f57c9a7 + 1811bed commit 2186764

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

.github/workflows/publish.yml

+16
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,28 @@ on:
77
- dev-[0-9]+.[0-9]+.[0-9]+
88
tags:
99
- v*
10+
pull_request:
11+
types:
12+
# publish images for PRs labeled "publish" whenever changed/labeled
13+
[opened, reopened, synchronize, labeled]
1014
workflow_dispatch:
1115

1216
env:
1317
REGISTRY: ghcr.io
1418
OWNER: nasa-ammos
1519
IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/v') }}
20+
SHOULD_PUBLISH_IMAGES: ${{ (github.event_name != 'pull_request') || contains(github.event.pull_request.labels.*.name, 'publish') }}
21+
SHOULD_PUBLISH_DEPLOYMENT: ${{ (github.event_name != 'pull_request') }}
1622

1723
jobs:
1824
init:
1925
runs-on: ubuntu-latest
2026
permissions:
2127
contents: read
28+
outputs:
29+
# set these as outputs to make available later, since `env` context isn't available in `jobs.if`
30+
SHOULD_PUBLISH_IMAGES: ${{ env.SHOULD_PUBLISH_IMAGES }}
31+
SHOULD_PUBLISH_DEPLOYMENT: ${{ env.SHOULD_PUBLISH_DEPLOYMENT }}
2232
steps:
2333
- uses: actions/checkout@v4
2434

@@ -34,6 +44,7 @@ jobs:
3444
containers:
3545
runs-on: ubuntu-latest
3646
needs: init
47+
if: needs.init.outputs.SHOULD_PUBLISH_IMAGES == 'true'
3748
permissions:
3849
contents: read
3950
packages: write
@@ -63,6 +74,9 @@ jobs:
6374
file: docker/Dockerfile.postgres
6475
name: ${{ matrix.components.image }}
6576
steps:
77+
- name: Log SHOULD_PUBLISH_IMAGES
78+
run: echo ${{ needs.init.outputs.SHOULD_PUBLISH_IMAGES }}
79+
6680
- uses: actions/checkout@v4
6781

6882
- uses: actions/setup-java@v4
@@ -119,6 +133,7 @@ jobs:
119133
scan:
120134
runs-on: ubuntu-latest
121135
needs: containers
136+
if: needs.init.outputs.SHOULD_PUBLISH_IMAGES == 'true'
122137
strategy:
123138
matrix:
124139
image:
@@ -155,6 +170,7 @@ jobs:
155170
name: gradle publish
156171
runs-on: ubuntu-latest
157172
needs: init
173+
if: needs.init.outputs.SHOULD_PUBLISH_DEPLOYMENT == 'true'
158174
permissions:
159175
contents: read
160176
packages: write

0 commit comments

Comments
 (0)