Skip to content

Commit

Permalink
GH workflows: publish images for PRs labeled 'publish'
Browse files Browse the repository at this point in the history
  • Loading branch information
dandelany committed Aug 28, 2024
1 parent f57c9a7 commit 1811bed
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ on:
- dev-[0-9]+.[0-9]+.[0-9]+
tags:
- v*
pull_request:
types:
# publish images for PRs labeled "publish" whenever changed/labeled
[opened, reopened, synchronize, labeled]
workflow_dispatch:

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

jobs:
init:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
# set these as outputs to make available later, since `env` context isn't available in `jobs.if`
SHOULD_PUBLISH_IMAGES: ${{ env.SHOULD_PUBLISH_IMAGES }}
SHOULD_PUBLISH_DEPLOYMENT: ${{ env.SHOULD_PUBLISH_DEPLOYMENT }}
steps:
- uses: actions/checkout@v4

Expand All @@ -34,6 +44,7 @@ jobs:
containers:
runs-on: ubuntu-latest
needs: init
if: needs.init.outputs.SHOULD_PUBLISH_IMAGES == 'true'
permissions:
contents: read
packages: write
Expand Down Expand Up @@ -63,6 +74,9 @@ jobs:
file: docker/Dockerfile.postgres
name: ${{ matrix.components.image }}
steps:
- name: Log SHOULD_PUBLISH_IMAGES
run: echo ${{ needs.init.outputs.SHOULD_PUBLISH_IMAGES }}

- uses: actions/checkout@v4

- uses: actions/setup-java@v4
Expand Down Expand Up @@ -119,6 +133,7 @@ jobs:
scan:
runs-on: ubuntu-latest
needs: containers
if: needs.init.outputs.SHOULD_PUBLISH_IMAGES == 'true'
strategy:
matrix:
image:
Expand Down Expand Up @@ -155,6 +170,7 @@ jobs:
name: gradle publish
runs-on: ubuntu-latest
needs: init
if: needs.init.outputs.SHOULD_PUBLISH_DEPLOYMENT == 'true'
permissions:
contents: read
packages: write
Expand Down

0 comments on commit 1811bed

Please sign in to comment.