From 86af80b50d31160ec50619a8a0a467a2839bc24b Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Mon, 6 May 2024 00:45:10 -0400 Subject: [PATCH] ci: update workflows --- .github/pull_request_template.md | 7 --- .github/workflows/ci.yml | 63 +++++++++++++------ .github/workflows/fuzz.yml | 29 +++++++++ .github/workflows/lint.yml | 19 ++++-- .github/workflows/publish.yml | 23 +++++++ .github/workflows/release.yml | 103 ------------------------------- script/check-generated-files | 19 ------ script/known-failures.txt | 1 - script/parse-examples | 55 ----------------- 9 files changed, 109 insertions(+), 210 deletions(-) delete mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/fuzz.yml create mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/release.yml delete mode 100755 script/check-generated-files delete mode 100644 script/known-failures.txt delete mode 100755 script/parse-examples diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index d6ee77b2..00000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,7 +0,0 @@ -# Checklist - -- [ ] All tests pass in CI. -- [ ] There are sufficient tests for the new fix/feature. -- [ ] Grammar rules have not been renamed unless absolutely necessary. -- [ ] The conflicts section hasn't grown too much. -- [ ] The parser size hasn't grown too much (check the value of STATE_COUNT in src/parser.c). diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08448036..a2f1238c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,30 +1,55 @@ name: CI + on: - workflow_dispatch: - pull_request: push: + branches: [master] + paths: + - "scripts.js" + - "common/*" + - "*/grammar.js" + - "*/src/**" + - "bindings/**" + - "binding.gyp" + pull_request: + paths: + - "scripts.js" + - "common/*" + - "*/grammar.js" + - "*/src/**" + - "bindings/**" + - "binding.gyp" + +concurrency: + group: ${{github.workflow}}-${{github.ref}} + cancel-in-progress: true jobs: test: - runs-on: ${{ matrix.os }} + name: Test parsers + runs-on: ${{matrix.os}} strategy: - fail-fast: true + fail-fast: false matrix: - os: [macos-latest, ubuntu-latest] + os: [ubuntu-latest, windows-latest, macos-14] steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up tree-sitter + uses: tree-sitter/setup-action/cli@v1 + - name: Set up examples + run: |- + git clone https://github.com/desktop/desktop examples/desktop --single-branch --depth=1 --filter=blob:none + git clone https://github.com/reduxjs/redux examples/redux --single-branch --depth=1 --filter=blob:none + git clone https://github.com/microsoft/vscode examples/vscode --single-branch --depth=1 --filter=blob:none + - name: Run tests + uses: tree-sitter/parser-test-action@v2 with: - 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 + test-rust: ${{runner.os == 'Linux'}} + - name: Parse examples + id: test + uses: tree-sitter/parse-action@v4 with: - node-version: 18 - - run: npm install - - run: npm run test-windows + files: | + examples/**/*.ts + examples/**/*.tsx + !examples/redux/src/types/store.ts diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml new file mode 100644 index 00000000..fdb88d57 --- /dev/null +++ b/.github/workflows/fuzz.yml @@ -0,0 +1,29 @@ +name: Fuzz Parser + +on: + push: + branches: [master] + paths: + - typescript/src/scanner.c + - tsx/src/scanner.c + - common/scanner.h + pull_request: + paths: + - typescript/src/scanner.c + - tsx/src/scanner.c + - common/scanner.h + +jobs: + fuzz: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + language: [typescript, tsx] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Fuzz ${{matrix.language}} parser + uses: tree-sitter/fuzz-action@v4 + with: + directory: ${{matrix.language}} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 103e92ae..11562607 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,18 +2,25 @@ name: Lint on: push: - branches: - - master + branches: [master] + paths: + - common/define-grammar.js pull_request: - branches: - - "**" + paths: + - common/define-grammar.js jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + cache: npm + node-version: ${{vars.NODE_VERSION}} - name: Install modules - run: npm install + run: npm ci --legacy-peer-deps - name: Run ESLint run: npm run lint diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..ac31648d --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,23 @@ +name: Publish package + +on: + push: + tags: ["*"] + +concurrency: + group: ${{github.workflow}}-${{github.ref}} + cancel-in-progress: true + +jobs: + npm: + uses: tree-sitter/workflows/.github/workflows/package-npm.yml@main + secrets: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + crates: + uses: tree-sitter/workflows/.github/workflows/package-crates.yml@main + secrets: + CARGO_REGISTRY_TOKEN: ${{secrets.CARGO_REGISTRY_TOKEN}} + pypi: + uses: tree-sitter/workflows/.github/workflows/package-pypi.yml@main + secrets: + PYPI_API_TOKEN: ${{secrets.PYPI_API_TOKEN}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 870eb84b..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,103 +0,0 @@ -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/script/check-generated-files b/script/check-generated-files deleted file mode 100755 index c1f216dd..00000000 --- a/script/check-generated-files +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -set -eu - -## Update index to make sure the subsequent diff-index command only reports -## a change if the file content actually changed. Not updating the index can -## give incorrect results when this script is run right after a build. - -git update-index -q --really-refresh - -if ! git diff-index --exit-code --name-status HEAD -- {tsx,typescript}/src/; then - echo "The following files are not up to date in the repository:" 1>&2 - git diff-index --name-status HEAD 1>&2 - echo "Run a build and commit the generated files to resolve this issue." 1>&2 - git diff-index -p HEAD - exit 1 -fi - -exit 0 diff --git a/script/known-failures.txt b/script/known-failures.txt deleted file mode 100644 index 63c51c8d..00000000 --- a/script/known-failures.txt +++ /dev/null @@ -1 +0,0 @@ -examples/redux/src/types/store.ts diff --git a/script/parse-examples b/script/parse-examples deleted file mode 100755 index 68df2397..00000000 --- a/script/parse-examples +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -set -e - -cd "$(dirname "$0")/.." -root="$PWD" - -clone_repo() { - local owner=$1 - local name=$2 - local sha=$3 - local path="$root/examples/$name" - - if [ -d "$path" ]; then - pushd "$path" >/dev/null - if [ "$(git rev-parse HEAD 2>/dev/null)" == "$sha" ]; then - popd >/dev/null - return - else - popd >/dev/null - rm -rf "$path" - echo "Updating $owner/$name to $sha" - fi - else - echo "Cloning $owner/$name" - fi - - mkdir -p "$path" - pushd "$path" >/dev/null - git init - git remote add origin "https://github.com/$owner/$name" - git pull --ff-only --depth 1 origin "$sha" - popd >/dev/null -} - -clone_repo desktop desktop 7c5111425cab9de911f82dd7e42f92d8f7927bb1 -clone_repo reduxjs redux 936e134b827a2f8022d51f6a42942e935ee2a935 -clone_repo microsoft vscode 4acf2d9fd883d247b903cc9c33221e18e39bffd8 - -known_failures="$(cat script/known-failures.txt)" - -# shellcheck disable=SC2046 -tree-sitter parse -q \ - 'examples/**/*.ts' \ - 'examples/**/*.tsx' \ - $(for failure in $known_failures; do echo "!${failure}"; done) - -example_count=$(find examples -name '*.ts*' -or -name '*.tx' | wc -l) -failure_count=$(wc -w <<<"$known_failures") -success_count=$((example_count - failure_count)) -success_percent=$(bc -l <<<"100*${success_count}/${example_count}") - -printf \ - "Successfully parsed %d of %d example files (%.1f%%)\n" \ - "$success_count" "$example_count" "$success_percent"