Skip to content

Commit 6d3b837

Browse files
committed
fix release
1 parent 1ac23f1 commit 6d3b837

2 files changed

Lines changed: 267 additions & 78 deletions

File tree

.github/workflows/release.yml

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,46 @@ name: Release
22

33
on:
44
workflow_dispatch:
5-
inputs:
6-
version-bump:
7-
description: 'Version bump type'
8-
required: true
9-
type: choice
10-
options:
11-
- patch
12-
- minor
13-
- major
145

156
permissions:
167
contents: write
178
id-token: write
189

1910
jobs:
20-
bump-and-tag:
11+
sync-and-tag:
2112
runs-on: ubuntu-latest
2213
outputs:
23-
version: ${{ steps.bump.outputs.VERSION }}
14+
version: ${{ steps.sync.outputs.VERSION }}
2415
steps:
2516
- name: Checkout
2617
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
2718

28-
- name: Setup Node.js
29-
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
30-
with:
31-
node-version: '20'
32-
3319
- name: Configure Git
3420
run: |
3521
git config user.name "github-actions[bot]"
3622
git config user.email "github-actions[bot]@users.noreply.github.com"
3723
38-
- name: Bump version and sync
39-
id: bump
24+
- name: Sync versions and tag
25+
id: sync
4026
run: |
41-
CURRENT=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
42-
VERSION=$(node -e "
43-
const [major, minor, patch] = '$CURRENT'.split('.').map(Number);
44-
const bump = '${{ inputs.version-bump }}';
45-
if (bump === 'major') console.log((major+1)+'.0.0');
46-
else if (bump === 'minor') console.log(major+'.'+(minor+1)+'.0');
47-
else console.log(major+'.'+minor+'.'+(patch+1));
48-
")
49-
bash scripts/version-sync.sh "$VERSION"
27+
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
5028
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
51-
git add Cargo.toml npm/ pypi/
52-
git commit -m "v$VERSION"
29+
bash scripts/version-sync.sh "$VERSION"
30+
if ! git diff --quiet; then
31+
git add Cargo.toml npm/ pypi/
32+
git commit -m "v$VERSION: sync package versions"
33+
fi
34+
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
35+
echo "::error::Tag v$VERSION already exists. Bump the version in Cargo.toml before releasing."
36+
exit 1
37+
fi
5338
git tag "v$VERSION"
5439
5540
- name: Push changes and tag
5641
run: git push && git push --tags
5742

5843
build:
59-
needs: bump-and-tag
44+
needs: sync-and-tag
6045
strategy:
6146
matrix:
6247
include:
@@ -85,7 +70,7 @@ jobs:
8570
- name: Checkout
8671
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
8772
with:
88-
ref: v${{ needs.bump-and-tag.outputs.version }}
73+
ref: v${{ needs.sync-and-tag.outputs.version }}
8974

9075
- name: Install Rust
9176
uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9 # stable
@@ -133,7 +118,7 @@ jobs:
133118
path: socket-patch-${{ matrix.target }}.zip
134119

135120
github-release:
136-
needs: [bump-and-tag, build]
121+
needs: [sync-and-tag, build]
137122
runs-on: ubuntu-latest
138123
steps:
139124
- name: Download all artifacts
@@ -146,14 +131,14 @@ jobs:
146131
env:
147132
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
148133
run: |
149-
TAG="v${{ needs.bump-and-tag.outputs.version }}"
134+
TAG="v${{ needs.sync-and-tag.outputs.version }}"
150135
gh release create "$TAG" \
151136
--repo "$GITHUB_REPOSITORY" \
152137
--generate-notes \
153138
artifacts/*
154139
155140
cargo-publish:
156-
needs: [bump-and-tag, build]
141+
needs: [sync-and-tag, build]
157142
runs-on: ubuntu-latest
158143
permissions:
159144
contents: read
@@ -162,7 +147,7 @@ jobs:
162147
- name: Checkout
163148
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
164149
with:
165-
ref: v${{ needs.bump-and-tag.outputs.version }}
150+
ref: v${{ needs.sync-and-tag.outputs.version }}
166151

167152
- name: Install Rust
168153
uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9 # stable
@@ -182,13 +167,13 @@ jobs:
182167
run: cargo publish -p socket-patch-cli
183168

184169
npm-publish:
185-
needs: [bump-and-tag, build]
170+
needs: [sync-and-tag, build]
186171
runs-on: ubuntu-latest
187172
steps:
188173
- name: Checkout
189174
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
190175
with:
191-
ref: v${{ needs.bump-and-tag.outputs.version }}
176+
ref: v${{ needs.sync-and-tag.outputs.version }}
192177

193178
- name: Download all artifacts
194179
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
@@ -223,13 +208,13 @@ jobs:
223208
run: npm publish npm/socket-patch --provenance --access public
224209

225210
pypi-publish:
226-
needs: [bump-and-tag, build]
211+
needs: [sync-and-tag, build]
227212
runs-on: ubuntu-latest
228213
steps:
229214
- name: Checkout
230215
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
231216
with:
232-
ref: v${{ needs.bump-and-tag.outputs.version }}
217+
ref: v${{ needs.sync-and-tag.outputs.version }}
233218

234219
- name: Download all artifacts
235220
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4

0 commit comments

Comments
 (0)