Repository navigation
98 lines (90 loc) · 3.42 KB
/
Copy pathprepare-release.yml
File metadata and controls
98 lines (90 loc) · 3.42 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
name: Prepare signed release tag
on:
workflow_dispatch:
inputs:
version:
description: Semantic version to tag without the v prefix
required: true
type: string
target_sha:
description: Exact full commit SHA on main to release
required: true
type: string
confirm:
description: Enter "tag" to create and push the signed release tag
required: true
type: string
permissions:
contents: write
concurrency:
group: release-tag-preparation
cancel-in-progress: false
jobs:
tag:
if: inputs.confirm == 'tag'
runs-on: ubuntu-latest
environment: maven-central
timeout-minutes: 10
steps:
- name: Check out the exact release commit
uses: actions/checkout@v7
with:
ref: ${{ inputs.target_sha }}
fetch-depth: 0
- name: Validate version, commit, and unused tag
shell: bash
env:
VERSION: ${{ inputs.version }}
TARGET_SHA: ${{ inputs.target_sha }}
run: |
set -euo pipefail
[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
[[ "$TARGET_SHA" =~ ^[0-9a-f]{40}$ ]]
test "$(git rev-parse HEAD)" = "$TARGET_SHA"
git fetch --no-tags origin main
test "$(git rev-parse origin/main)" = "$TARGET_SHA"
set +e
git ls-remote --exit-code --tags origin "refs/tags/v$VERSION" >/dev/null
tag_status=$?
set -e
if [[ "$tag_status" -eq 0 ]]; then
echo "Tag v$VERSION already exists on origin." >&2
exit 1
fi
if [[ "$tag_status" -ne 2 ]]; then
echo "Could not establish whether tag v$VERSION exists (status $tag_status)." >&2
exit "$tag_status"
fi
- name: Create, verify, and push signed tag
shell: bash
env:
VERSION: ${{ inputs.version }}
TARGET_SHA: ${{ inputs.target_sha }}
MAVEN_GPG_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
MAVEN_GPG_KEY_FINGERPRINT: ${{ secrets.MAVEN_GPG_KEY_FINGERPRINT }}
run: |
set -euo pipefail
umask 077
passphrase_file="$RUNNER_TEMP/archunitjava-gpg-passphrase"
gpg_wrapper="$RUNNER_TEMP/archunitjava-gpg-loopback"
trap 'rm -f "$passphrase_file" "$gpg_wrapper"' EXIT
printf '%s' "$MAVEN_GPG_PRIVATE_KEY" | gpg --batch --import
imported_fingerprint="$({
gpg --batch --with-colons --list-secret-keys "$MAVEN_GPG_KEY_FINGERPRINT"
} | awk -F: '$1 == "fpr" { print $10; exit }')"
test "$imported_fingerprint" = "$MAVEN_GPG_KEY_FINGERPRINT"
printf '%s' "$MAVEN_GPG_PASSPHRASE" >"$passphrase_file"
cat >"$gpg_wrapper" <<'EOF'
#!/usr/bin/env bash
exec gpg --batch --yes --pinentry-mode loopback \
--passphrase-file "$RUNNER_TEMP/archunitjava-gpg-passphrase" "$@"
EOF
chmod 700 "$gpg_wrapper"
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
git config user.signingkey "$MAVEN_GPG_KEY_FINGERPRINT"
git config gpg.program "$gpg_wrapper"
git tag -s -m "ArchUnitJava $VERSION" "v$VERSION" "$TARGET_SHA"
git verify-tag "v$VERSION"
git push origin "refs/tags/v$VERSION"