-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (107 loc) · 4.11 KB
/
release.yml
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
---
name: Release
on:
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
REGISTRY: crates.io
jobs:
github_release:
name: GitHub Release
runs-on: ubuntu-24.04
permissions:
contents: write
issues: write
pull-requests: write
outputs:
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
persist-credentials: false
- name: Configure Git signing
run: |
echo "${{ secrets.BOT_GPG_PRIVATE_KEY }}" | gpg --import
git config --global user.signingkey ${{ secrets.BOT_GPG_KEY_ID }}
git config --global commit.gpgsign true
git config --global commit.signoff true
git config --global user.name 'GitHub Actions Bot'
git config --global user.email '[email protected]'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install semantic release and plugins
run: |
npm install -g [email protected] \
conventional-changelog-cli \
conventional-changelog-conventionalcommits \
@semantic-release/changelog \
@semantic-release/exec \
@semantic-release/git \
@semantic-release/github
- name: Create a release if needed
id: semantic
env:
CI: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_NAME: "GitHub Actions Bot"
GIT_AUTHOR_EMAIL: "[email protected]"
GIT_COMMITTER_NAME: "GitHub Actions Bot"
GIT_COMMITTER_EMAIL: "[email protected]"
run: |
# Create first release if not exists using gh cli - Initial Release Version 0.1.0
# This is an HACK because semantic release doesn't support versions under 1.0.0
# But if we already have a release then it respects it and start to increment from there
if ! gh release view 0.1.0 >/dev/null 2>&1; then
gh release create 0.1.0 --title "Initial Release" --notes "Initial Release" --target main
fi
# Run semantic-release in dry-run first to capture version
DRY_OUTPUT=$(semantic-release --dry-run 2>&1 || true)
# Check if there are no changes
if $(echo "$DRY_OUTPUT" | grep -q "no new version is released"); then
echo "No new release needed"
echo "new_release_published=false" >> $GITHUB_OUTPUT
exit 0
fi
# Extract version from dry run output
VERSION=$(echo "$DRY_OUTPUT" | grep -o "The next release version is [0-9]\+\.[0-9]\+\.[0-9]\+\(-rc\.[0-9]\+\)\?" | cut -d ' ' -f6)
if [ -z "$VERSION" ]; then
echo "Error: Could not determine version"
exit 1
fi
echo "new_release_version=$VERSION" >> $GITHUB_OUTPUT
# Run actual release
if semantic-release; then
echo "Successfully released version $VERSION"
echo "new_release_published=true" >> $GITHUB_OUTPUT
else
echo "Release failed"
exit 1
fi
publish:
needs: github_release
runs-on: ubuntu-24.04
if: needs.github_release.outputs.new_release_published == 'true'
name: Publish
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Update Cargo.toml version
run: |
echo "Updating to version ${{ needs.github_release.outputs.new_release_version }}"
sed -i "s/^version = .*/version = \"${{ needs.github_release.outputs.new_release_version }}\"/" Cargo.toml
- name: Build
run: cargo build --verbose --release
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish