Repository navigation
131 lines (125 loc) · 5.19 KB
/
Copy pathrelease.yml
File metadata and controls
131 lines (125 loc) · 5.19 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
# Release Le Space Belege – from a button.
#
# gh workflow run release.yml -R Le-Space/belege # the next patch: 0.2.0 → 0.2.1
# gh workflow run release.yml -R Le-Space/belege -f bump=minor # 0.2.1 → 0.3.0
# gh workflow run release.yml -R Le-Space/belege -f version=1.0.0 # exactly this one
#
# Without a version, it counts up from the highest vX.Y.Z tag (patch unless
# `bump` says minor or major).
# Runs the CI gates on main, writes the version into package.json and app/package.json,
# turns "## [Unreleased]" in CHANGELOG.md into "## [x.y.z] – date", commits, tags vX.Y.Z and
# pushes both, creates the GitHub release with that CHANGELOG section as its notes, and then
# publishes the tag to Aleph and points belege.le-space.de at it (deploy.yml).
# A version that fails its tests never gets a tag.
name: Release
permissions:
contents: read
on:
workflow_dispatch:
inputs:
version:
description: Version to release, e.g. 1.0.0 (empty = count up from the last tag)
required: false
type: string
default: ''
bump:
description: Without a version, which part to count up
required: false
type: choice
options: [patch, minor, major]
default: patch
concurrency:
group: release
cancel-in-progress: false
jobs:
test:
uses: ./.github/workflows/ci.yml
tag:
needs: test
runs-on: ubuntu-latest
permissions:
contents: write # the version commit, the tag and the release
outputs:
tag: ${{ steps.version.outputs.tag }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
- name: Commit the version and tag it
id: version
env:
VERSION: ${{ inputs.version }}
BUMP: ${{ inputs.bump }}
run: |
# The inputs reach the shell as environment variables, never pasted into the script.
if [ -z "$VERSION" ]; then
git fetch --quiet --tags origin
LAST=$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n 1)
LAST=${LAST#v}
[ -n "$LAST" ] || LAST=0.0.0
IFS=. read -r MAJOR MINOR PATCH <<< "$LAST"
case "$BUMP" in
major) VERSION="$((MAJOR + 1)).0.0" ;;
minor) VERSION="$MAJOR.$((MINOR + 1)).0" ;;
*) VERSION="$MAJOR.$MINOR.$((PATCH + 1))" ;;
esac
echo "Counting up from v$LAST ($BUMP): $VERSION"
fi
if ! printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Not a version: $VERSION"; exit 1
fi
TAG="v$VERSION"
if git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null; then
echo "::error::$TAG exists already"; exit 1
fi
grep -q '^## \[Unreleased\]' CHANGELOG.md || { echo "::error::CHANGELOG.md has no [Unreleased] section"; exit 1; }
node -e '
const fs = require("fs");
for (const f of ["package.json", "app/package.json"]) {
const text = fs.readFileSync(f, "utf8");
const p = JSON.parse(text);
p.version = process.env.VERSION;
// Keep the indentation each file has (app/ uses tabs, the root two spaces):
// prettier checks it, and a whole-file reformat collides with every change.
const indent = /^\{\n(\s+)"/.exec(text)?.[1] ?? " ";
fs.writeFileSync(f, JSON.stringify(p, null, indent) + "\n");
}
const today = new Date().toISOString().slice(0, 10);
const log = fs.readFileSync("CHANGELOG.md", "utf8").replace(
/^## \[Unreleased\]/m,
`## [Unreleased]\n\n## [${process.env.VERSION}] – ${today}`
);
fs.writeFileSync("CHANGELOG.md", log);
'
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json app/package.json CHANGELOG.md
git commit -m "release: $TAG"
git tag -a "$TAG" -m "Le Space Belege $TAG"
# Fails if main moved while the tests ran – then run it again.
git push origin HEAD:main "$TAG"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Create the GitHub release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }}
VERSION: ${{ steps.version.outputs.version }}
run: |
# The notes are this version's CHANGELOG section.
awk -v v="$VERSION" '
$0 ~ "^## \\[" v "\\]" { on = 1; next }
on && /^## \[/ { exit }
on { print }
' CHANGELOG.md > notes.md
gh release create "$TAG" --title "Le Space Belege $TAG" --notes-file notes.md --verify-tag
deploy:
needs: tag
permissions:
contents: write # deploy.yml notes the CID on the release
uses: ./.github/workflows/deploy.yml
with:
link_domain: true
ref: ${{ needs.tag.outputs.tag }}
secrets:
ALEPH_PRIVATE_KEY: ${{ secrets.ALEPH_PRIVATE_KEY }}