Skip to content

Commit 0e55808

Browse files
committed
ci: update ci and publish, add fuzz annd lint actions
1 parent 84fbc5c commit 0e55808

File tree

5 files changed

+159
-44
lines changed

5 files changed

+159
-44
lines changed

.github/workflows/ci.yml

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
name: Build/test
1+
name: CI
22
on:
33
push:
44
branches:
55
- master
66
pull_request:
77
branches:
8-
- "**"
9-
8+
- master
109
jobs:
1110
test:
1211
runs-on: ${{ matrix.os }}
@@ -15,19 +14,24 @@ jobs:
1514
matrix:
1615
os: [macos-latest, ubuntu-latest]
1716
steps:
18-
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v2
17+
- uses: actions/checkout@v3
18+
with:
19+
submodules: true
20+
fetch-depth: 0
21+
- uses: actions/setup-node@v3
2022
with:
21-
node-version: 14
23+
node-version: 18
2224
- run: npm install
2325
- run: npm test
24-
2526
test_windows:
26-
runs-on: windows-2019
27+
runs-on: windows-latest
2728
steps:
28-
- uses: actions/checkout@v2
29-
- uses: actions/setup-node@v2
29+
- uses: actions/checkout@v3
30+
with:
31+
submodules: true
32+
fetch-depth: 0
33+
- uses: actions/setup-node@v3
3034
with:
31-
node-version: 14
35+
node-version: 18
3236
- run: npm install
3337
- run: npm run-script test-windows

.github/workflows/fuzz.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Fuzz Parser
2+
3+
on:
4+
push:
5+
paths:
6+
- src/scanner.c
7+
pull_request:
8+
paths:
9+
- src/scanner.c
10+
workflow_dispatch:
11+
12+
jobs:
13+
test:
14+
name: Parser fuzzing
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: vigoux/tree-sitter-fuzz-action@v1
19+
with:
20+
language: bash
21+
external-scanner: src/scanner.c
22+
time: 60

.github/workflows/lint.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- "**"
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Install modules
17+
run: npm install
18+
- name: Run ESLint
19+
run: npm run lint

.github/workflows/publish.yml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Release
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
branches:
7+
- master
8+
types:
9+
- completed
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Get previous commit SHA
21+
id: get_previous_commit
22+
run: |
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
29+
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
55+
56+
echo "version_changed=$VERSION_CHANGED" >> "$GITHUB_ENV"
57+
echo "current_version=${CURRENT_NPM_VERSION}" >> "$GITHUB_ENV"
58+
fi
59+
fi
60+
61+
- name: Display result
62+
run: |
63+
echo "Version bump detected: ${{ env.version_changed }}"
64+
65+
- name: Fail if version is lower
66+
if: env.version_changed == 'false'
67+
run: exit 1
68+
69+
- name: Setup Node
70+
if: env.version_changed == 'true'
71+
uses: actions/setup-node@v3
72+
with:
73+
node-version: 18
74+
registry-url: "https://registry.npmjs.org"
75+
- name: Publish to NPM
76+
if: env.version_changed == 'true'
77+
env:
78+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
79+
run: npm publish
80+
81+
- name: Setup Rust
82+
if: env.version_changed == 'true'
83+
uses: actions-rs/toolchain@v1
84+
with:
85+
profile: minimal
86+
toolchain: stable
87+
override: true
88+
- name: Publish to Crates.io
89+
if: env.version_changed == 'true'
90+
uses: katyo/publish-crates@v2
91+
with:
92+
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
93+
94+
- name: Tag versions
95+
if: env.version_changed == 'true'
96+
run: |
97+
git checkout master
98+
git config user.name github-actions[bot]
99+
git config user.email github-actions[bot]@users.noreply.github.com
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 }}"

.github/workflows/publish_crate.yml

-33
This file was deleted.

0 commit comments

Comments
 (0)