Skip to content

Commit 4967f2c

Browse files
committed
Extend GHA to push images that pass tests
For push actions only (e.g., post-PR merge), after successfully completing the behave-test step, Log into GitHub container registry (ghcr.io) and push the image. Add the necessary permissions to write to the GHCR repository. Adjust the build and test steps to use a predictable, version-independent image name ("localimage") which we can reference in the new steps. Signed-off-by: Jonathan Dowland <[email protected]>
1 parent edd924a commit 4967f2c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

.github/workflows/image-workflow-template.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ on:
77
type: string
88
env:
99
LANG: en_US.UTF-8
10+
IMAGE_URI: ghcr.io/jboss-container-images/${{ inputs.image }}:${{ github.ref_name }}
1011
jobs:
1112
openjdkci:
13+
permissions:
14+
packages: write
1215
name: OpenJDK S2I Build and Test
1316
runs-on: ubuntu-20.04
1417
strategy:
@@ -23,7 +26,7 @@ jobs:
2326

2427
- name: Build
2528
run: |
26-
cekit -v --descriptor ${{ inputs.image }}.yaml build docker --no-squash
29+
cekit -v --descriptor ${{ inputs.image }}.yaml build docker --no-squash --tag localimage
2730
2831
- name: Install and cache S2I CLI tool from GitHub
2932
uses: redhat-actions/openshift-tools-installer@v1
@@ -35,4 +38,18 @@ jobs:
3538
- name: Behave Tests
3639
run: |
3740
echo /home/runner/work/_temp/openshift-bin >> $GITHUB_PATH
38-
cekit -v --descriptor ${{ inputs.image }}.yaml test behave
41+
cekit -v --descriptor ${{ inputs.image }}.yaml test --image localimage behave
42+
43+
- if: github.event_name == 'push'
44+
name: Log in to the Container registry
45+
uses: docker/login-action@v2
46+
with:
47+
registry: ghcr.io
48+
username: ${{ github.actor }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
51+
- if: github.event_name == 'push'
52+
name: Tag and push container image
53+
run: |
54+
docker tag localimage ${{ env.IMAGE_URI }}
55+
docker push ${{ env.IMAGE_URI }}

0 commit comments

Comments
 (0)