Skip to content

Commit 3a7b597

Browse files
authored
Merge pull request #23 from IABTechLab/tjm-UID2-2325-new-shared-docker-image-pipeline
New shared docker image pipeline
2 parents d1fea4d + 248240f commit 3a7b597

File tree

4 files changed

+121
-164
lines changed

4 files changed

+121
-164
lines changed

.github/workflows/shared-java-publish-versioned-package.yaml

+44-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,29 @@ on:
1919
default: 'true'
2020

2121
env:
22-
BRANCH_NAME: ${{ github.ref }}
22+
IS_RELEASE: ${{ (inputs.release_type == 'Major' || inputs.release_type == 'Minor' || inputs.release_type == 'Patch') && (github.event.repository.default_branch == github.ref_name ) }}
23+
REPO: ${{ github.event.repository.name }}
2324

2425
jobs:
2526
release:
27+
name: ${{ ((inputs.release_type == 'Major' || inputs.release_type == 'Minor' || inputs.release_type == 'Patch') && (github.event.repository.default_branch == github.ref_name )) && 'Create Release' || 'Publish Pre-release' }}
2628
runs-on: ubuntu-latest
2729
steps:
30+
- name: Show Context
31+
run: |
32+
printenv
33+
echo "$GITHUB_CONTEXT"
34+
shell: bash
35+
env:
36+
GITHUB_CONTEXT: ${{ toJson(github) }}
37+
38+
- name: Check branch and release type
39+
uses: IABTechLab/uid2-shared-actions/actions/[email protected]
40+
with:
41+
release_type: ${{ inputs.release_type }}
42+
2843
- name: Checkout repo
29-
uses: actions/checkout@v3
44+
uses: actions/checkout@v4
3045
with:
3146
fetch-depth: 0
3247

@@ -37,12 +52,12 @@ jobs:
3752
java-version: ${{ inputs.java_version }}
3853

3954
- name: Download key
40-
uses: IABTechLab/uid2-shared-actions/actions/download_gpg_key@main
55+
uses: IABTechLab/uid2-shared-actions/actions/download_gpg_key@v1.0
4156
with:
4257
key: ${{ secrets.GPG_KEY }}
4358

4459
- name: Generate Trivy vulnerability scan report
45-
uses: aquasecurity/trivy-action@0.12.0
60+
uses: aquasecurity/trivy-action@0.14.0
4661
if: inputs.publish_vulnerabilities == 'true'
4762
with:
4863
scan-type: 'fs'
@@ -60,7 +75,7 @@ jobs:
6075
sarif_file: 'trivy-results.sarif'
6176

6277
- name: Test with Trivy vulnerability scanner
63-
uses: aquasecurity/trivy-action@0.12.0
78+
uses: aquasecurity/trivy-action@0.14.0
6479
with:
6580
scan-type: 'fs'
6681
format: 'table'
@@ -71,10 +86,10 @@ jobs:
7186

7287
- name: Set version number
7388
id: version
74-
uses: IABTechLab/uid2-shared-actions/actions/version_number@main
89+
uses: IABTechLab/uid2-shared-actions/actions/version_number@v1.0
7590
with:
7691
type: ${{ inputs.release_type }}
77-
branch_name: ${{ env.BRANCH_NAME }}
92+
branch_name: ${{ github.ref }}
7893

7994
- name: Update pom.xml
8095
run: |
@@ -94,3 +109,25 @@ jobs:
94109
author_name: Release Workflow
95110
author_email: [email protected]
96111
message: 'Released ${{ inputs.release_type }} version: ${{ steps.version.outputs.new_version }}'
112+
tag: v${{ steps.version.outputs.new_version }}
113+
114+
- name: Build Changelog
115+
id: github_release
116+
if: ${{ env.IS_RELEASE == 'true' }}
117+
uses: mikepenz/release-changelog-builder-action@v3
118+
with:
119+
configurationJson: |
120+
{
121+
"template": "#{{CHANGELOG}}\n## Maven\n```\n<dependency>\n <groupId>com.uid2</groupId>\n <artifactId>${{ env.REPO }}</artifactId>\n <version>${{ steps.version.outputs.new_version }}</version>\n</dependency>\n```\n\n## Jar Files\n- [${{ env.REPO }}-${{ steps.version.outputs.new_version }}.jar](https://repo1.maven.org/maven2/com/uid2/${{ env.REPO }}/${{ steps.version.outputs.new_version }}/${{ env.REPO }}-${{ steps.version.outputs.new_version }}.jar)\n\n## Changelog\n#{{UNCATEGORIZED}}",
122+
"pr_template": " - #{{TITLE}} - ( PR: ##{{NUMBER}} )"
123+
}
124+
env:
125+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
126+
127+
- name: Create Release
128+
if: ${{ env.IS_RELEASE == 'true' }}
129+
uses: softprops/action-gh-release@v1
130+
with:
131+
name: v${{ steps.version.outputs.new_version }}
132+
body: ${{ steps.github_release.outputs.changelog }}
133+
draft: true

.github/workflows/shared-publish-docker-versioned.yaml

+54-15
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: Shared Publish Docker
22
on:
33
workflow_call:
44
inputs:
5-
tag:
6-
description: 'The tag to apply to the Docker file'
7-
type: string
85
cloud_provider:
96
description: 'Must be one of [aws, gcp, azure, default]'
107
required: false
@@ -15,12 +12,19 @@ on:
1512
required: true
1613
type: string
1714
java_version:
15+
description: The version of Java to use to compile the JAR. Defaults to 11
1816
type: string
1917
default: '11'
2018
publish_vulnerabilities:
19+
description: If true, will attempt to publish any vulnerabilities to GitHub. Defaults to true. Set to false for private repos.
2120
type: string
2221
default: 'true'
2322
version_number_input:
23+
description: If set, the version number will not be incremented and the given number will be used.
24+
type: string
25+
default: ''
26+
force_release:
27+
description: If true, will create a release. Only used for testing.
2428
type: string
2529
default: ''
2630
outputs:
@@ -31,10 +35,11 @@ on:
3135
env:
3236
REGISTRY: ghcr.io
3337
IMAGE_NAME: ${{ github.repository }}
34-
BRANCH_NAME: ${{ github.ref }}
38+
IS_RELEASE: ${{ ((inputs.release_type == 'Major' || inputs.release_type == 'Minor' || inputs.release_type == 'Patch') && (github.event.repository.default_branch == github.ref_name )) || inputs.force_release == 'true' }}
3539

3640
jobs:
37-
build-publish-docker:
41+
release:
42+
name: ${{ (((inputs.release_type == 'Major' || inputs.release_type == 'Minor' || inputs.release_type == 'Patch') && (github.event.repository.default_branch == github.ref_name )) || inputs.force_release == 'true') && 'Create Release' || 'Publish Pre-release' }}
3843
runs-on: ubuntu-latest
3944
permissions:
4045
contents: write
@@ -43,14 +48,27 @@ jobs:
4348
outputs:
4449
jar_version: ${{ steps.version.outputs.new_version }}
4550
steps:
51+
- name: Show Context
52+
run: |
53+
printenv
54+
echo "$GITHUB_CONTEXT"
55+
shell: bash
56+
env:
57+
GITHUB_CONTEXT: ${{ toJson(github) }}
58+
59+
- name: Check branch and release type
60+
uses: IABTechLab/uid2-shared-actions/actions/[email protected]
61+
with:
62+
release_type: ${{ inputs.release_type }}
63+
4664
- name: Set up JDK
4765
uses: actions/setup-java@v3
4866
with:
4967
distribution: 'temurin'
5068
java-version: ${{ inputs.java_version }}
5169

5270
- name: Checkout full history
53-
uses: actions/checkout@v3
71+
uses: actions/checkout@v4
5472
with:
5573
# git-restore-mtime requires full git history. The default fetch-depth value (1) creates a shallow checkout.
5674
fetch-depth: 0
@@ -64,13 +82,13 @@ jobs:
6482
with:
6583
type: ${{ inputs.release_type }}
6684
version_number: ${{ inputs.version_number_input }}
67-
branch_name: ${{ env.BRANCH_NAME }}
85+
branch_name: ${{ github.ref }}
6886

6987
- name: Update pom.xml
7088
run: |
7189
current_version=$(grep -o '<version>.*</version>' pom.xml | head -1 | sed 's/<version>\(.*\)<\/version>/\1/')
7290
new_version=${{ steps.version.outputs.new_version }}
73-
sed -i "0,/$current_version/s//$new_version/" pom.xml
91+
sed -i "0,/$current_version/s/$current_version/$new_version/" pom.xml
7492
echo "Version number updated from $current_version to $new_version"
7593
7694
- name: Package JAR
@@ -88,25 +106,25 @@ jobs:
88106
author_name: Release Workflow
89107
author_email: [email protected]
90108
message: 'Released ${{ inputs.release_type }} version: ${{ steps.version.outputs.new_version }}'
109+
tag: v${{ steps.version.outputs.new_version }}
91110

92111
- name: Log in to the Docker container registry
93-
uses: docker/login-action@v2
112+
uses: docker/login-action@v3
94113
with:
95114
registry: ${{ env.REGISTRY }}
96115
username: ${{ github.actor }}
97116
password: ${{ secrets.GITHUB_TOKEN }}
98117

99118
- name: Extract metadata (tags, labels) for Docker
100119
id: meta
101-
uses: docker/metadata-action@v4
120+
uses: docker/metadata-action@v5
102121
with:
103122
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
104123
tags: |
105124
type=raw,value=${{ steps.version.outputs.new_version }}-${{ inputs.cloud_provider }}
106-
type=raw,value=${{ inputs.tag }}
107125
108126
- name: Build and export to Docker
109-
uses: docker/build-push-action@v3
127+
uses: docker/build-push-action@v5
110128
with:
111129
context: .
112130
load: true
@@ -117,7 +135,7 @@ jobs:
117135
IMAGE_VERSION=${{ steps.version.outputs.new_version }}
118136
119137
- name: Generate Trivy vulnerability scan report
120-
uses: aquasecurity/trivy-action@0.12.0
138+
uses: aquasecurity/trivy-action@0.14.0
121139
if: inputs.publish_vulnerabilities == 'true'
122140
with:
123141
image-ref: ${{ steps.meta.outputs.tags }}
@@ -135,7 +153,7 @@ jobs:
135153
sarif_file: 'trivy-results.sarif'
136154

137155
- name: Test with Trivy vulnerability scanner
138-
uses: aquasecurity/trivy-action@0.12.0
156+
uses: aquasecurity/trivy-action@0.14.0
139157
with:
140158
image-ref: ${{ steps.meta.outputs.tags }}
141159
format: 'table'
@@ -145,7 +163,7 @@ jobs:
145163
hide-progress: true
146164

147165
- name: Push to Docker
148-
uses: docker/build-push-action@v3
166+
uses: docker/build-push-action@v5
149167
with:
150168
context: .
151169
push: true
@@ -154,3 +172,24 @@ jobs:
154172
build-args: |
155173
JAR_VERSION=${{ steps.version.outputs.new_version }}
156174
IMAGE_VERSION=${{ steps.version.outputs.new_version }}
175+
176+
- name: Build Changelog
177+
id: github_release
178+
if: ${{ env.IS_RELEASE == 'true' }}
179+
uses: mikepenz/release-changelog-builder-action@v3
180+
with:
181+
configurationJson: |
182+
{
183+
"template": "#{{CHANGELOG}}\n## Installation\n```\ndocker pull ${{ steps.meta.outputs.tags }}\n```\n\n## Changelog\n#{{UNCATEGORIZED}}",
184+
"pr_template": " - #{{TITLE}} - ( PR: ##{{NUMBER}} )"
185+
}
186+
env:
187+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
188+
189+
- name: Create Release
190+
if: ${{ env.IS_RELEASE == 'true' }}
191+
uses: softprops/action-gh-release@v1
192+
with:
193+
name: ${{ steps.version.outputs.new_version }}
194+
body: ${{ steps.github_release.outputs.changelog }}
195+
draft: true

0 commit comments

Comments
 (0)