Repository navigation
120 lines (107 loc) · 4.67 KB
/
Copy pathrelease.yml
File metadata and controls
120 lines (107 loc) · 4.67 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
name: Release
on:
workflow_dispatch:
inputs:
bump:
description: "Version component to bump"
required: true
type: choice
options:
- patch
- minor
- major
prerelease:
description: "Release candidate (creates X.Y.Z-rc.N tag without bumping stable)"
type: boolean
default: false
permissions:
contents: write
jobs:
release:
name: Bump version and create release
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.RUDOF_BOT_ID }}
private-key: ${{ secrets.RUDOF_BOT_PK }}
- uses: actions/checkout@v5
with:
token: ${{ steps.app-token.outputs.token }}
fetch-tags: true
- name: Compute new version
id: version
run: |
current=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
# Strip any existing -rc.N suffix to get the base version
base=$(echo "$current" | sed 's/-rc\.[0-9]*//')
IFS='.' read -r major minor patch <<< "$base"
case "${{ inputs.bump }}" in
major) bumped="$((major + 1)).0.0" ;;
minor) bumped="$major.$((minor + 1)).0" ;;
patch) bumped="$major.$minor.$((patch + 1))" ;;
esac
# If current version already had an RC suffix AND this is a stable release,
# promote the RC base version directly instead of bumping again.
# e.g. 0.1.17-rc.1 + patch (stable) → 0.1.17, not 0.1.18
if [ "$current" != "$base" ] && [ "${{ inputs.prerelease }}" = "false" ]; then
bumped="$base"
fi
if [ "${{ inputs.prerelease }}" = "true" ]; then
# Find highest existing rc number for this base version
last_rc=$(git tag --list "${bumped}-rc.*" | grep -oP 'rc\.\K[0-9]+' | sort -n | tail -1)
next_rc=$(( ${last_rc:-0} + 1 ))
new="${bumped}-rc.${next_rc}"
else
new="$bumped"
fi
echo "current=$current" >> "$GITHUB_OUTPUT"
echo "new=$new" >> "$GITHUB_OUTPUT"
echo "prerelease=${{ inputs.prerelease }}" >> "$GITHUB_OUTPUT"
- name: Update version in Cargo.toml
run: |
OLD="${{ steps.version.outputs.current }}"
NEW="${{ steps.version.outputs.new }}"
# Bump workspace version
sed -i "0,/^version = \"${OLD}\"/{s/^version = \"${OLD}\"/version = \"${NEW}\"/}" Cargo.toml
# Bump only internal workspace crates in [workspace.dependencies]
INTERNAL_CRATES="dctap|mie|pgschema|prefixmap|pyrudof|rbe|rbe_testsuite|rdf_config|rudof_cli|rudof_config|rudof_iri|rudof_rdf|rudof_typing|rudof_viz|rudof_generate|rudof_lib|rudof_mcp|shacl|shapes_comparator|shapes_converter|shex_ast|shex_testsuite|shex_validation|sparql_service"
sed -i -E "/^(${INTERNAL_CRATES}) = \{/{s/version = \"${OLD}\"/version = \"${NEW}\"/}" Cargo.toml
for crate in $(echo "$INTERNAL_CRATES" | tr '|' ' '); do
cargo update -p "$crate" --precise "$NEW"
done
- name: Verify version was updated
run: grep '^version = "${{ steps.version.outputs.new }}"' Cargo.toml
- name: Update nix version
if: ${{ !inputs.prerelease }}
run: |
NEW="${{ steps.version.outputs.new }}"
sed -i "s/version = \"[^\"]*\"/version = \"${NEW}\"/" nix/packages.nix
- name: Update the version used by the online demo
if: ${{ !inputs.prerelease }}
run: |
NEW="${{ steps.version.outputs.new }}"
sed -i "s/^const RUDOF_VERSION = \"[^\"]*\";/const RUDOF_VERSION = \"${NEW}\";/" docs/src/demo/demo.js
grep -q "^const RUDOF_VERSION = \"${NEW}\";" docs/src/demo/demo.js
- name: Commit and push
run: |
git config user.name "rudof-bot[bot]"
git config user.email "${{ secrets.RUDOF_BOT_ID }}+rudof-bot[bot]@users.noreply.github.com"
git add Cargo.toml nix/packages.nix docs/src/demo/demo.js
git commit -m "chore: release ${{ steps.version.outputs.new }} [skip ci]"
git push
- name: Create GitHub release
run: |
EXTRA_FLAGS=""
if [ "${{ steps.version.outputs.prerelease }}" = "true" ]; then
EXTRA_FLAGS="--prerelease"
fi
gh release create "${{ steps.version.outputs.new }}" \
--title "${{ steps.version.outputs.new }}" \
--generate-notes \
$EXTRA_FLAGS
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}