-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (114 loc) · 4.3 KB
/
cd.yml
File metadata and controls
133 lines (114 loc) · 4.3 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Release
on:
workflow_dispatch:
inputs:
version:
description: Semver version to publish (e.g., 1.2.3)
required: true
type: string
workflow_call:
inputs:
version:
description: Semver version to publish (e.g., 1.2.3)
required: true
type: string
secrets:
MAVEN_CENTRAL_USERNAME:
required: true
MAVEN_CENTRAL_PASSWORD:
required: true
MAVEN_GPG_PRIVATE_KEY:
required: true
MAVEN_GPG_PASSPHRASE:
required: true
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: write
jobs:
validate-version:
runs-on: ubuntu-latest
steps:
- name: Validate SemVer version format
run: |
if ! echo "${{ inputs.version }}" | grep -qE '^[0-9]+(\.[0-9]+)+'
then
echo "Error: '${{ inputs.version }}' is not a valid SemVer version (expected e.g. 1.2.3)"
exit 1
fi
release:
needs: validate-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
java-version: "21"
distribution: temurin
cache: maven
server-id: central
server-username: MAVEN_CENTRAL_USERNAME
server-password: MAVEN_CENTRAL_PASSWORD
- name: Set version
run: mvn versions:set -DnewVersion=${{ inputs.version }} -DgenerateBackupPoms=false
- name: Update changelog for release
run: |
first_non_empty_line=$(grep -m1 -E '\S' CHANGELOG.md || true)
if [ "$first_non_empty_line" != "# Unreleased" ] && [ "$first_non_empty_line" != "Unreleased" ]; then
echo "Error: CHANGELOG.md must start with an Unreleased section"
exit 1
fi
perl -i -0pe 's/\A(\s*(?:#\s*)?)Unreleased\b/$1v${{ inputs.version }}/' CHANGELOG.md
- name: Check Maven Central publication status
id: publication-check
uses: ./.github/actions/check-maven-central-publication
with:
version: ${{ inputs.version }}
- name: Build
if: steps.publication-check.outputs.published != 'true'
run: mvn --batch-mode clean compile
- name: Run unit tests
if: steps.publication-check.outputs.published != 'true'
run: mvn --batch-mode test -Dmaven.main.skip=true
- name: Run integration tests
if: steps.publication-check.outputs.published != 'true'
run: mvn --batch-mode verify -Dmaven.main.skip=true -Dmaven.test.skip=true
- name: Import GPG key
if: steps.publication-check.outputs.published != 'true'
run: echo "${{ secrets.MAVEN_GPG_PRIVATE_KEY }}" | gpg --batch --import
- name: Publish to Maven Central
if: steps.publication-check.outputs.published != 'true'
run: mvn --batch-mode deploy -P release -Dmaven.main.skip=true -Dmaven.test.skip=true -Dverify.skip=true
env:
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
- name: Commit the version update
id: commit
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: Set package version to ${{ inputs.version }}
file_pattern: pom.xml CHANGELOG.md
- name: Determine documentation URL
id: docs-url
run: |
PAGES_URL="https://${GITHUB_REPOSITORY_OWNER}.github.io/${GITHUB_REPOSITORY#*/}"
echo "url=${PAGES_URL}/v${{ inputs.version }}/" >> "$GITHUB_OUTPUT"
- name: Determine target commit
id: target-commit
run: |
if [ -n "${{ steps.commit.outputs.commit_hash }}" ]; then
echo "sha=${{ steps.commit.outputs.commit_hash }}" >> "$GITHUB_OUTPUT"
else
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
fi
- name: Create GitHub release
run: |
gh release create "v${{ inputs.version }}" \
--title "v${{ inputs.version }}" \
--notes "📖 [Documentation](${{ steps.docs-url.outputs.url }})" \
--target ${{ steps.target-commit.outputs.sha }}
env:
GH_TOKEN: ${{ github.token }}