From 9202196c2839ea645f4bd069324a4dfc1ab3fda3 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sat, 18 Nov 2023 14:42:41 -0500 Subject: [PATCH] chore(ci): bump actions, add fuzz, lint, and release workflows --- .gitattributes | 9 ++- .github/workflows/ci.yml | 31 ++++++---- .github/workflows/fuzz.yml | 22 ++++++++ .github/workflows/lint.yml | 19 +++++++ .github/workflows/release.yml | 103 ++++++++++++++++++++++++++++++++++ .gitignore | 14 +---- .npmignore | 10 ++-- README.md | 10 +--- package.json | 7 ++- 9 files changed, 189 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/fuzz.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/release.yml diff --git a/.gitattributes b/.gitattributes index 3aefd516..1491f7e1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,10 @@ /src/** linguist-vendored /examples/* linguist-vendored -/corpus/* linguist-vendored + +src/grammar.json linguist-generated +src/node-types.json linguist-generated +src/parser.c linguist-generated + +src/grammar.json -diff +src/node-types.json -diff +src/parser.c -diff diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79ee1dd9..c47c446c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,22 +1,33 @@ -name: Build/test +name: CI + on: - pull_request: - branches: - - "**" push: branches: - - "master" + - master + pull_request: + branches: + - master + jobs: test: runs-on: ${{ matrix.os }} strategy: - fail-fast: true matrix: - os: [macos-latest, ubuntu-latest, windows-latest] + os: [macos-latest, ubuntu-latest] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 18 - run: npm install - run: npm test + + test_windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 18 + - run: npm install + - run: npm run test-windows diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml new file mode 100644 index 00000000..ce212317 --- /dev/null +++ b/.github/workflows/fuzz.yml @@ -0,0 +1,22 @@ +name: Fuzz Parser + +on: + push: + paths: + - src/scanner.c + pull_request: + paths: + - src/scanner.c + workflow_dispatch: + +jobs: + test: + name: Parser fuzzing + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: vigoux/tree-sitter-fuzz-action@v1 + with: + language: php + external-scanner: src/scanner.c + time: 60 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..103e92ae --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,19 @@ +name: Lint + +on: + push: + branches: + - master + pull_request: + branches: + - "**" + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install modules + run: npm install + - name: Run ESLint + run: npm run lint diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..870eb84b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,103 @@ +name: Release + +on: + workflow_run: + workflows: ["CI"] + branches: + - master + types: + - completed + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get previous commit SHA + id: get_previous_commit + run: | + LATEST_TAG=$(git describe --tags --abbrev=0) + if [[ -z "$LATEST_TAG" ]]; then + echo "No tag found. Failing..." + exit 1 + fi + echo "latest_tag=${LATEST_TAG#v}" >> "$GITHUB_ENV" # Remove 'v' prefix from the tag + + - name: Check if version changed and is greater than the previous + id: version_check + run: | + # Compare the current version with the version from the previous commit + PREVIOUS_NPM_VERSION=${{ env.latest_tag }} + CURRENT_NPM_VERSION=$(jq -r '.version' package.json) + CURRENT_CARGO_VERSION=$(awk -F '"' '/^version/ {print $2}' Cargo.toml) + if [[ "$CURRENT_NPM_VERSION" != "$CURRENT_CARGO_VERSION" ]]; then # Cargo.toml and package.json versions must match + echo "Mismatch: NPM version ($CURRENT_NPM_VERSION) and Cargo.toml version ($CURRENT_CARGO_VERSION)" + echo "version_changed=false" >> "$GITHUB_ENV" + else + if [[ "$PREVIOUS_NPM_VERSION" == "$CURRENT_NPM_VERSION" ]]; then + echo "version_changed=" >> "$GITHUB_ENV" + else + IFS='.' read -ra PREVIOUS_VERSION_PARTS <<< "$PREVIOUS_NPM_VERSION" + IFS='.' read -ra CURRENT_VERSION_PARTS <<< "$CURRENT_NPM_VERSION" + VERSION_CHANGED=false + for i in "${!PREVIOUS_VERSION_PARTS[@]}"; do + if [[ ${CURRENT_VERSION_PARTS[i]} -gt ${PREVIOUS_VERSION_PARTS[i]} ]]; then + VERSION_CHANGED=true + break + elif [[ ${CURRENT_VERSION_PARTS[i]} -lt ${PREVIOUS_VERSION_PARTS[i]} ]]; then + break + fi + done + + echo "version_changed=$VERSION_CHANGED" >> "$GITHUB_ENV" + echo "current_version=${CURRENT_NPM_VERSION}" >> "$GITHUB_ENV" + fi + fi + + - name: Display result + run: | + echo "Version bump detected: ${{ env.version_changed }}" + + - name: Fail if version is lower + if: env.version_changed == 'false' + run: exit 1 + + - name: Setup Node + if: env.version_changed == 'true' + uses: actions/setup-node@v4 + with: + node-version: 18 + registry-url: "https://registry.npmjs.org" + - name: Publish to NPM + if: env.version_changed == 'true' + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + run: npm publish + + - name: Setup Rust + if: env.version_changed == 'true' + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - name: Publish to Crates.io + if: env.version_changed == 'true' + uses: katyo/publish-crates@v2 + with: + registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + - name: Tag versions + if: env.version_changed == 'true' + run: | + git checkout master + git config user.name github-actions[bot] + git config user.email github-actions[bot]@users.noreply.github.com + git tag -d "v${{ env.current_version }}" || true + git push origin --delete "v${{ env.current_version }}" || true + git tag -a "v${{ env.current_version }}" -m "Version ${{ env.current_version }}" + git push origin "v${{ env.current_version }}" diff --git a/.gitignore b/.gitignore index b06b3d31..bd77f411 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,6 @@ -package-lock.json +Cargo.lock node_modules build -*.log -.DS_Store -examples - -*.a -*.dylib -*.so -*.o -bindings/c/*.h -bindings/c/tree-sitter-*.pc +package-lock.json +/target/ .build/ \ No newline at end of file diff --git a/.npmignore b/.npmignore index a6e71d18..194ff845 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1,5 @@ -test -build -script -examples -target +/test +/examples +/build +/script +/target diff --git a/README.md b/README.md index 360d87dc..a29879aa 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,5 @@ -tree-sitter-php -================== +# tree-sitter-php -[![Build/test](https://github.com/tree-sitter/tree-sitter-php/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-php/actions/workflows/ci.yml) - -PHP grammar for [tree-sitter][]. - -[tree-sitter]: https://github.com/tree-sitter/tree-sitter +[![CI](https://github.com/tree-sitter/tree-sitter-php/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-php/actions/workflows/ci.yml) +PHP grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter). diff --git a/package.json b/package.json index 1e5869fb..0f7be175 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "bindings/node", "keywords": [ "parser", + "lexer", "php" ], "author": "Josh Vera", @@ -17,8 +18,10 @@ "nan": "^2.14.0" }, "devDependencies": { - "tree-sitter-cli": "^0.20.0", - "shelljs": "^0.8.4" + "eslint": ">=5.16.0", + "eslint-config-google": "^0.14.0", + "shelljs": "^0.8.4", + "tree-sitter-cli": "^0.20.0" }, "scripts": { "build": "tree-sitter generate && node-gyp build",