-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (80 loc) · 3.46 KB
/
mvn-release.yml
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Release
on:
push:
branches:
- release
env:
REGISTRY: europe-north1-docker.pkg.dev/artifact-registry-5n/dapla-stat-docker
IMAGE: maskinporten-guardian
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
packages: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
ref: release
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: maven
overwrite-settings: false
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: "projects/848539402404/locations/global/workloadIdentityPools/gh-actions/providers/gh-actions"
service_account: "gh-actions-dapla-stat@artifact-registry-5n.iam.gserviceaccount.com"
token_format: access_token
- name: Setup Maven authentication to GitHub packages
uses: s4u/[email protected]
id: maven_settings
with:
servers: '[{"id": "github","configuration": {"httpHeaders": {"property": {"name": "Authorization","value": "Bearer ${{ secrets.GITHUB_TOKEN }}"}}}}]'
- name: Maven release and deploy to GitHub packages and Artifact Registry
id: release_artifact
env:
MAVEN_USERNAME: ${env.GITHUB_ACTOR}
MAVEN_PASSWORD: ${env.GITHUB_TOKEN}
run: |
git config user.name github-actions
git config user.email [email protected]
# Get the release version from the pom.xml before the next snapshot increment
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed "s/-SNAPSHOT//")
echo "version=${VERSION}" >> $GITHUB_OUTPUT
# Perform the release/deploy and increment the version to the next snapshot
mvn --batch-mode release:prepare -P github,artifact-registry -Darguments="-Dmaven.test.skip=true -Dmaven.deploy.skip=true"
mvn --batch-mode release:perform
TAG=$(git describe --abbrev=0 --tags)
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- name: Create GitHub release draft
uses: release-drafter/release-drafter@v6
id: create_github_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: ${{ steps.release_artifact.outputs.tag }}
- name: Upload assets to GitHub release draft
run: |
ARTIFACT_ID=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)
# Get all files matching the artifact id and version (source, javadoc, etc.)
ARTIFACT_GLOB=(./target/$ARTIFACT_ID-${{ steps.release_artifact.outputs.version }}*.jar)
for file in "${ARTIFACT_GLOB[@]}"; do
echo "Uploading $file"
gh release upload ${{ steps.create_github_release.outputs.tag_name }} $file
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create a pull request with the changes in the branch
run: |
pr_title="Release ${{steps.release_artifact.outputs.tag}}"
pr_body="This PR is autogenerated by a workflow. A release draft has been created and should be published after merging."
gh pr create --title "$pr_title" --body "$pr_body" --head $(git branch --show-current)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}