-
Notifications
You must be signed in to change notification settings - Fork 1
190 lines (165 loc) · 6.53 KB
/
Copy pathrust-release.yml
File metadata and controls
190 lines (165 loc) · 6.53 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
name: Rust Release
on:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
id-token: write # Required for trusted publishing
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
# Only run for Rust changes
check-changes:
runs-on: ubuntu-latest
outputs:
rust_changed: ${{ steps.changes.outputs.rust_changed }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check for Rust changes
id: changes
run: |
# Use github.event.before to handle multi-commit pushes
BEFORE="${{ github.event.before }}"
# Handle initial push (before is all zeros)
if [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
BEFORE="HEAD~1"
fi
if git diff --name-only "$BEFORE" "${{ github.sha }}" | grep -qE '^(crates/|Cargo\.(toml|lock))'; then
echo "rust_changed=true" >> $GITHUB_OUTPUT
else
echo "rust_changed=false" >> $GITHUB_OUTPUT
fi
# Create/update release PR when Rust files change
release-pr:
name: Release PR
needs: check-changes
if: needs.check-changes.outputs.rust_changed == 'true'
runs-on: ubuntu-latest
concurrency:
group: release-plz-${{ github.ref }}
cancel-in-progress: false
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: release-plz/action@v0.5
with:
command: release-pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Publish when version changes (release PR merged)
release:
name: Release
needs: check-changes
if: needs.check-changes.outputs.rust_changed == 'true'
runs-on: ubuntu-latest
environment: release
outputs:
published: ${{ steps.version-check.outputs.should_publish }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Check if version changed
id: version-check
run: |
# Get current version from Cargo.toml
CURRENT_VERSION=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name == "outlit") | .version')
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Check if this version exists on crates.io
if cargo search outlit --limit 1 | grep -q "^outlit = \"$CURRENT_VERSION\""; then
echo "Version $CURRENT_VERSION already published"
echo "should_publish=false" >> $GITHUB_OUTPUT
else
echo "Version $CURRENT_VERSION not yet published"
echo "should_publish=true" >> $GITHUB_OUTPUT
fi
- name: Setup Rust
if: steps.version-check.outputs.should_publish == 'true'
uses: dtolnay/rust-toolchain@stable
- name: Run tests
if: steps.version-check.outputs.should_publish == 'true'
run: cargo test --all-features
- name: Authenticate with crates.io
if: steps.version-check.outputs.should_publish == 'true'
uses: rust-lang/crates-io-auth-action@v1
id: auth
- name: Publish to crates.io
if: steps.version-check.outputs.should_publish == 'true'
run: cargo publish -p outlit
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
- name: Create git tag
if: steps.version-check.outputs.should_publish == 'true'
run: |
VERSION="${{ steps.version-check.outputs.current_version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "outlit-v$VERSION" -m "outlit v$VERSION"
git push origin "outlit-v$VERSION"
- name: Summary
if: steps.version-check.outputs.should_publish == 'true'
run: |
VERSION="${{ steps.version-check.outputs.current_version }}"
echo "## Rust Crate Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Package:** outlit" >> $GITHUB_STEP_SUMMARY
echo "**Version:** $VERSION" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Install:**" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "cargo add outlit" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
# Publish canary on every push to main (when Rust files change and no stable release)
canary:
name: Publish Canary
needs: [check-changes, release]
# Only run if Rust changed AND no stable release happened
if: |
needs.check-changes.outputs.rust_changed == 'true' &&
needs.release.outputs.published == 'false'
runs-on: ubuntu-latest
environment: release
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Run tests
run: cargo test --all-features
- name: Set canary version
id: version
run: |
BASE_VERSION=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[] | select(.name == "outlit") | .version')
TIMESTAMP=$(date +%Y%m%d%H%M)
SHORT_SHA=$(git rev-parse --short HEAD)
CANARY_VERSION="${BASE_VERSION}-canary.${TIMESTAMP}.${SHORT_SHA}"
echo "canary_version=$CANARY_VERSION" >> $GITHUB_OUTPUT
# Update workspace version in root Cargo.toml
sed -i "s/^version = \"${BASE_VERSION}\"/version = \"${CANARY_VERSION}\"/" Cargo.toml
echo "Updated version to: $(grep '^version' Cargo.toml)"
- name: Authenticate with crates.io
uses: rust-lang/crates-io-auth-action@v1
id: auth
- name: Publish canary to crates.io
run: cargo publish -p outlit --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
- name: Summary
run: |
echo "## Rust Canary Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Package:** outlit" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ steps.version.outputs.canary_version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Install:**" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "cargo add outlit@${{ steps.version.outputs.canary_version }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY