Skip to content

Commit ac4d696

Browse files
committed
chore: rework release action to not use release-please
1 parent a07dcf4 commit ac4d696

File tree

1 file changed

+58
-37
lines changed

1 file changed

+58
-37
lines changed

.github/workflows/release.yml

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,101 @@ name: Release
33
on:
44
workflow_run:
55
workflows: ["CI"]
6+
branches:
7+
- master
68
types:
79
- completed
810

9-
permissions:
10-
contents: write
11-
pull-requests: write
12-
1311
jobs:
1412
release:
1513
runs-on: ubuntu-latest
16-
if: ${{ github.event.workflow_run.conclusion == 'success' && github.ref == 'refs/heads/master' }}
1714
steps:
18-
- uses: google-github-actions/release-please-action@v3
19-
id: release
20-
with:
21-
release-type: node
22-
package-name: tree-sitter-regex
23-
24-
- uses: actions/checkout@v3
15+
- name: Checkout code
16+
uses: actions/checkout@v3
2517
with:
26-
token: ${{ secrets.GITHUB_TOKEN }}
18+
fetch-depth: 0
2719

28-
- name: Update Rust version
20+
- name: Get previous commit SHA
21+
id: get_previous_commit
2922
run: |
30-
git fetch origin release-please--branches--master--components--tree-sitter-regex
31-
git checkout release-please--branches--master--components--tree-sitter-regex
23+
LATEST_TAG=$(git describe --tags --abbrev=0)
24+
if [[ -z "$LATEST_TAG" ]]; then
25+
echo "No tag found. Failing..."
26+
exit 1
27+
fi
28+
echo "latest_tag=${LATEST_TAG#v}" >> "$GITHUB_ENV" # Remove 'v' prefix from the tag
3229
33-
git config user.name github-actions[bot]
34-
git config user.email github-actions[bot]@users.noreply.github.com
30+
- name: Check if version changed and is greater than the previous
31+
id: version_check
32+
run: |
33+
# Compare the current version with the version from the previous commit
34+
PREVIOUS_NPM_VERSION=${{ env.latest_tag }}
35+
CURRENT_NPM_VERSION=$(jq -r '.version' package.json)
36+
CURRENT_CARGO_VERSION=$(awk -F '"' '/^version/ {print $2}' Cargo.toml)
37+
if [[ "$CURRENT_NPM_VERSION" != "$CURRENT_CARGO_VERSION" ]]; then # Cargo.toml and package.json versions must match
38+
echo "Mismatch: NPM version ($CURRENT_NPM_VERSION) and Cargo.toml version ($CURRENT_CARGO_VERSION)"
39+
echo "version_changed=false" >> "$GITHUB_ENV"
40+
else
41+
if [[ "$PREVIOUS_NPM_VERSION" == "$CURRENT_NPM_VERSION" ]]; then
42+
echo "version_changed=" >> "$GITHUB_ENV"
43+
else
44+
IFS='.' read -ra PREVIOUS_VERSION_PARTS <<< "$PREVIOUS_NPM_VERSION"
45+
IFS='.' read -ra CURRENT_VERSION_PARTS <<< "$CURRENT_NPM_VERSION"
46+
VERSION_CHANGED=false
47+
for i in "${!PREVIOUS_VERSION_PARTS[@]}"; do
48+
if [[ ${CURRENT_VERSION_PARTS[i]} -gt ${PREVIOUS_VERSION_PARTS[i]} ]]; then
49+
VERSION_CHANGED=true
50+
break
51+
elif [[ ${CURRENT_VERSION_PARTS[i]} -lt ${PREVIOUS_VERSION_PARTS[i]} ]]; then
52+
break
53+
fi
54+
done
3555
36-
repo_name="${{ github.repository }}"
37-
repo_name="${repo_name##*/}"
38-
version=$(grep -o '"version": *"[^"]*"' package.json | sed 's/"version": "\(.*\)"/\1/')
56+
echo "version_changed=$VERSION_CHANGED" >> "$GITHUB_ENV"
57+
echo "current_version=${CURRENT_NPM_VERSION}" >> "$GITHUB_ENV"
58+
fi
59+
fi
3960
40-
sed -i "s/version = \"[^\"]*\"/version = \"$version\"/g" Cargo.toml
41-
sed -i "s/$repo_name = \"[^\"]*\"/$repo_name = \"$version\"/g" bindings/rust/README.md
61+
- name: Display result
62+
run: |
63+
echo "Version bump detected: ${{ env.version_changed }}"
4264
43-
git add Cargo.toml bindings/rust/README.md
44-
git commit --amend --no-edit
45-
git push -f
65+
- name: Fail if version is lower
66+
if: env.version_changed == 'false'
67+
run: exit 1
4668

4769
- name: Setup Node
48-
if: ${{ steps.release.outputs.release_created }}
70+
if: env.version_changed == 'true'
4971
uses: actions/setup-node@v3
5072
with:
5173
node-version: 18
5274
registry-url: "https://registry.npmjs.org"
5375
- name: Publish to NPM
54-
if: ${{ steps.release.outputs.release_created }}
76+
if: env.version_changed == 'true'
5577
env:
5678
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
5779
run: npm publish
5880

5981
- name: Setup Rust
60-
if: ${{ steps.release.outputs.release_created }}
82+
if: env.version_changed == 'true'
6183
uses: actions-rs/toolchain@v1
6284
with:
6385
profile: minimal
6486
toolchain: stable
6587
override: true
6688
- name: Publish to Crates.io
67-
if: ${{ steps.release.outputs.release_created }}
89+
if: env.version_changed == 'true'
6890
uses: katyo/publish-crates@v2
6991
with:
7092
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
7193

72-
- name: Tag stable versions
73-
if: ${{ steps.release.outputs.release_created }}
94+
- name: Tag versions
95+
if: env.version_changed == 'true'
7496
run: |
7597
git checkout master
7698
git config user.name github-actions[bot]
7799
git config user.email github-actions[bot]@users.noreply.github.com
78-
git remote add gh-token "https://${{ secrets.GITHUB_TOKEN }}@github.com/google-github-actions/release-please-action.git"
79-
git tag -d stable || true
80-
git push origin :stable || true
81-
git tag -a stable -m "Last Stable Release"
82-
git push origin stable
100+
git tag -d "v${{ env.current_version }}" || true
101+
git push origin --delete "v${{ env.current_version }}" || true
102+
git tag -a "v${{ env.current_version }}" -m "Version ${{ env.current_version }}"
103+
git push origin "v${{ env.current_version }}"

0 commit comments

Comments
 (0)