Repository navigation
123 lines (111 loc) · 4.12 KB
/
Copy pathrelease.yml
File metadata and controls
123 lines (111 loc) · 4.12 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
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: read
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
verify:
name: Verify release signature
runs-on: ubuntu-latest
outputs:
commit: ${{ steps.signature.outputs.commit }}
tag_object: ${{ steps.signature.outputs.tag_object }}
steps:
- name: Check out trusted release policy
uses: actions/checkout@v6
with:
ref: ${{ github.event.repository.default_branch }}
path: policy
persist-credentials: false
- name: Check out triggering commit and tags
uses: actions/checkout@v6
with:
ref: ${{ github.sha }}
path: source
fetch-depth: 0
persist-credentials: false
- name: Verify approved OpenPGP signature and release version
id: signature
env:
RELEASE_TAG: ${{ github.ref_name }}
RELEASE_COMMIT: ${{ github.sha }}
run: |
python3 policy/.github/workflows/scripts/verify_release_tag.py verify \
--policy policy --repository source \
--tag "$RELEASE_TAG" --expected-commit "$RELEASE_COMMIT" \
--github-output "$GITHUB_OUTPUT"
release:
needs: verify
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out verified release commit
uses: actions/checkout@v6
with:
ref: ${{ needs.verify.outputs.commit }}
fetch-depth: 0 # release notes need full history and tags
persist-credentials: false
- name: Create release archive
env:
RELEASE_TAG: ${{ github.ref_name }}
run: |
set -euo pipefail
mkdir -p ../luciole-release
rsync -a \
--exclude='.git' \
--exclude='.github' \
--exclude='nix' \
--exclude='flake.nix' \
--exclude='flake.lock' \
--exclude='result*' \
./ ../luciole-release/
tar -C .. -czf "luciole-${RELEASE_TAG}.tar.gz" luciole-release/
cp "luciole-${RELEASE_TAG}.tar.gz" luciole-latest.tar.gz
- name: Generate release notes
env:
RELEASE_TAG: ${{ github.ref_name }}
run: |
set -euo pipefail
# Prefer the previous tag on the same history; otherwise the most recent other tag.
prev_tag=$(git describe --tags --abbrev=0 "${RELEASE_TAG}^" 2>/dev/null || true)
if [[ -z "$prev_tag" ]]; then
prev_tag=$(git tag --sort=-version:refname | grep -vxF "$RELEASE_TAG" | head -n1 || true)
fi
if [[ -z "$prev_tag" ]]; then
range="$(git rev-list --max-parents=0 HEAD)..${RELEASE_TAG}"
since_label="project start"
else
range="${prev_tag}..${RELEASE_TAG}"
since_label="$prev_tag"
fi
{
printf '# Release %s\n\n' "$RELEASE_TAG"
printf '## Changes since %s\n\n' "$since_label"
git log "$range" --pretty=format:"- %s ([%h](https://github.com/${GITHUB_REPOSITORY}/commit/%H)) by %an"
printf '\n'
} > release_notes.md
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ github.ref_name }}
VERIFIED_TAG_OBJECT: ${{ needs.verify.outputs.tag_object }}
run: |
set -euo pipefail
remote_tag=$(git ls-remote --exit-code --refs origin "refs/tags/$RELEASE_TAG")
if [[ "$remote_tag" != "$VERIFIED_TAG_OBJECT"$'\t'"refs/tags/$RELEASE_TAG" ]]; then
printf 'Release tag changed after signature verification.\n' >&2
exit 1
fi
assets=("luciole-${RELEASE_TAG}.tar.gz" luciole-latest.tar.gz)
if gh release view "$RELEASE_TAG" > /dev/null 2>&1; then
printf 'GitHub release %s already exists; refreshing assets only.\n' "$RELEASE_TAG"
gh release upload "$RELEASE_TAG" "${assets[@]}" --clobber
exit 0
fi
gh release create "$RELEASE_TAG" --verify-tag --notes-file release_notes.md "${assets[@]}"