Skip to content

Commit f3033a4

Browse files
committed
ci: add a common release workflow
1 parent 7da5ca7 commit f3033a4

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

.github/workflows/release.yaml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: release
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
8+
init:
9+
runs-on: ubuntu-latest
10+
outputs:
11+
version: ${{steps.version.outputs.version}}
12+
prerelease: ${{steps.state.outputs.prerelease}}
13+
steps:
14+
- name: Evaluate state
15+
id: state
16+
env:
17+
HEAD_REF: ${{github.head_ref}}
18+
run: |
19+
test -z "${HEAD_REF}" && (echo 'do-publish=true' >> $GITHUB_OUTPUT)
20+
if [[ "${{ github.event.ref }}" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
21+
echo release=true >> $GITHUB_OUTPUT
22+
elif [[ "${{ github.event.ref }}" =~ ^refs/tags/v.*$ ]]; then
23+
echo prerelease=true >> $GITHUB_OUTPUT
24+
fi
25+
- name: Set version
26+
id: version
27+
run: |
28+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
29+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
30+
[ "$VERSION" == "main" ] && VERSION=latest
31+
echo "Version: $VERSION"
32+
echo "version=$VERSION" >> $GITHUB_OUTPUT
33+
34+
# ensure that the version of the tag is the version of the crates
35+
ensure-version:
36+
runs-on: ubuntu-latest
37+
needs:
38+
- init
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
- name: Setup cargo-binstall
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
run: |
46+
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
47+
- name: Setup cargo-workspaces
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
run: |
51+
cargo binstall -y cargo-workspaces
52+
- name: Set version
53+
run: |
54+
cargo ws version custom ${{ needs.init.outputs.version }} --all --no-git-commit --force "*" --yes
55+
- name: Ensure this did not change anything
56+
run: |
57+
git diff --exit-code
58+
if [ $? -gt 0 ]; then
59+
echo "::error::Uncommitted changes after setting the version. This indicates that the version of the tag does not align with the version of the crates."
60+
exit 1
61+
fi
62+
63+
# ensure we pass CI
64+
ci:
65+
needs:
66+
- init
67+
uses: scm-rs/shared-workflows/.github/workflows/ci.yaml
68+
69+
release:
70+
needs:
71+
- init
72+
- ci
73+
runs-on: ubuntu-22.04
74+
steps:
75+
- uses: actions/checkout@v4
76+
with:
77+
fetch-depth: 0
78+
79+
- name: Install convco
80+
run: |
81+
curl -sLO https://github.com/convco/convco/releases/download/v0.6.2/convco-ubuntu.zip
82+
unzip convco-ubuntu.zip
83+
chmod a+x convco
84+
sudo mv convco /usr/local/bin
85+
86+
- name: Generate changelog
87+
run: |
88+
convco changelog -s --max-majors=1 --max-minors=1 --max-patches=1 > RELEASE_LOG.md
89+
90+
- name: Create release
91+
env:
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
TAG: v${{ needs.init.outputs.version }}
94+
run: |
95+
OPTS=""
96+
if [[ "${{ needs.init.outputs.prerelease }}" == "true" ]]; then
97+
OPTS="${OPTS} -p"
98+
fi
99+
gh release create ${OPTS} --title "${{ needs.init.outputs.version }}" -F RELEASE_LOG.md ${TAG}
100+
101+
publish:
102+
needs:
103+
- release
104+
runs-on: ubuntu-latest
105+
steps:
106+
- name: Setup | Checkout
107+
uses: actions/checkout@v4
108+
109+
- name: Build | Publish
110+
run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }}

0 commit comments

Comments
 (0)