-
Notifications
You must be signed in to change notification settings - Fork 1
182 lines (172 loc) · 7.14 KB
/
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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Release
on:
# [impl->dsn~release-workflow.triggers~1]
workflow_call:
inputs:
started-from-ci:
description: "Marks this release as started from CI, skipping precondition check"
type: boolean
required: true
default: false
workflow_dispatch:
inputs:
skip-maven-central:
description: "Skip deployment to Maven Central"
required: true
type: boolean
default: false
skip-github-release:
description: "Skip creating the GitHub release"
required: true
type: boolean
default: false
jobs:
release:
runs-on: ubuntu-latest
defaults:
run:
shell: "bash"
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
permissions:
contents: write
actions: read
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Maven Central Repository
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: |
11
17
cache: "maven"
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
# Check preconditions
- name: Fail if not running on main branch
if: ${{ github.ref != 'refs/heads/main' }}
uses: actions/github-script@v7
with:
script: |
core.setFailed('Not running on main branch, github.ref is ${{ github.ref }}. Please start this workflow only on main')
# [impl->dsn~release-workflow.verify-ci-build-success~1]
- name: Check CI build of this commit succeeded
# We skip this check if this was started from ci-build.yml, because the build status would be "in progress".
if: ${{ ! inputs.started-from-ci }}
run: |
echo "Commit SHA: $COMMIT_SHA"
gh run list --workflow ci-build.yml --branch main --event push --commit $COMMIT_SHA
ci_build_status=$(gh run list --workflow ci-build.yml --branch main --event push --commit $COMMIT_SHA --json conclusion --template '{{range .}}{{.conclusion}}{{"\n"}}{{end}}')
echo "CI build status at commit $COMMIT_SHA was '$ci_build_status'"
if [[ "$ci_build_status" != "success" ]]; then
gh run list --workflow ci-build.yml --commit $COMMIT_SHA >> $GITHUB_STEP_SUMMARY
echo "Status of CI build for commit $COMMIT_SHA was '$ci_build_status', expected 'success'" >> $GITHUB_STEP_SUMMARY
cat $GITHUB_STEP_SUMMARY
exit 1
fi
env:
COMMIT_SHA: ${{ github.sha }}
GH_TOKEN: ${{ github.token }}
# [impl->dsn~release-workflow.run-verify-release~1]
- name: Verify release preconditions
id: verify-release
run: |
mvn --batch-mode -T 1C install -DskipTests
mvn --batch-mode com.exasol:project-keeper-maven-plugin:verify-release --projects .
echo "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ github.token }}
# [impl->dsn~release-workflow.verify-skip-tests~1]
- name: Build project
run: mvn --batch-mode -DskipTests clean verify
# Maven Central Deployment
- name: List secret GPG keys
if: ${{ ! inputs.skip-maven-central }}
run: gpg --list-secret-keys
# [impl->dsn~release-workflow.deploy-maven-central~1]
- name: Publish to Central Repository
if: ${{ ! inputs.skip-maven-central }}
run: |
mvn --batch-mode -Dgpg.skip=false -DskipTests deploy
echo "Published to Maven Central" >> "$GITHUB_STEP_SUMMARY"
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
# Create GitHub releasse
- name: Calculate Artifact Checksums
id: artifact-checksum
if: ${{ ! inputs.skip-github-release }}
run: |
ls target/
echo "Calculating sha256 checksum for artifact files"
echo "artifacts<<EOF" >> "$GITHUB_OUTPUT"
IFS=$'\n' artifacts_array=($ARTIFACTS)
for file in "${artifacts_array[@]}";
do
full_path=$(realpath "$file")
echo "Calculate sha256sum for file '$full_path'"
file_dir="$(dirname "$full_path")"
file_name=$(basename "$full_path")
pushd "$file_dir"
checksum_file_name="${file_name}.sha256"
sha256sum "$file_name" > "$checksum_file_name"
echo "$full_path" >> "$GITHUB_OUTPUT"
echo "${file_dir}/$checksum_file_name" >> "$GITHUB_OUTPUT"
popd
done
echo "EOF" >> "$GITHUB_OUTPUT"
echo "Full artifact file list"
cat "$GITHUB_OUTPUT"
env:
ARTIFACTS: ${{ steps.verify-release.outputs.release-artifacts }}
# [impl->dsn~release-workflow.create-github-release~1]
- name: Create GitHub Release
id: create-github-release
if: ${{ ! inputs.skip-github-release }}
run: |
IFS=$'\n' artifacts_array=($ARTIFACTS)
for file in "${artifacts_array[@]}";
do
echo "Attaching file '$file'"
done
release_url=$(gh release create --draft --latest --title "$TITLE" --notes "$NOTES" --target main $TAG "${artifacts_array[@]}")
echo "Created release $TAG with title '$TITLE' at $release_url" >> "$GITHUB_STEP_SUMMARY"
echo "release-url=$release_url" >> "$GITHUB_OUTPUT"
git fetch --tags origin
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.verify-release.outputs.version }}
NOTES: ${{ steps.verify-release.outputs.release-notes }}
TITLE: ${{ steps.verify-release.outputs.release-title }}
ARTIFACTS: ${{ steps.artifact-checksum.outputs.artifacts }}
- name: Report failure Status to Slack channel
# Also run this step in case of failures
if: ${{ always() }}
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ job.status }}
token: ${{ github.token }}
notification_title: "Release build in {repo} has {status_message}"
message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>"
notify_when: "failure,cancelled,warnings,skipped"
env:
SLACK_WEBHOOK_URL: ${{ secrets.INTEGRATION_TEAM_SLACK_NOTIFICATION_WEBHOOK }}
- name: Report new release to Slack channel
if: ${{ steps.create-github-release.outputs.release-url }}
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ job.status }}
token: ${{ github.token }}
notification_title: "Release build for {repo} created a new release"
message_format: "{workflow} created release ${{ steps.create-github-release.outputs.release-url }}"
env:
SLACK_WEBHOOK_URL: ${{ secrets.INTEGRATION_TEAM_SLACK_NOTIFICATION_WEBHOOK }}