From 6e695429ccbc5b8e1f7d1e19d12885519060e28c Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 17 Nov 2024 22:37:42 -0800 Subject: [PATCH] Use a dedicated GitHub Actions workflow for linting TypeScript/JavaScript code The "build" workflow builds the application for all supported targets, generates workflow artifacts from which the builds can be downloaded by users and beta testers, and publishes nightly and production releases. As if that wasn't enough, the workflow was also configured to perform the unrelated operation of linting the project's TypeScript and JavaScript code. This monolithic approach is harmful for multiple reasons: * Makes it difficult to interpret a failed workflow run * Unnecessarily adds a significant amount of extra content to the already extensive logs produced by the build process * Makes the build workflow more difficult to maintain * Increases the length of a build workflow run * Increases the impact of a spurious failure * Increases the turnaround time for contributors and maintainers to get feedback from the CI system The linting operation is hereby moved to a dedicated workflow, consistent with standard practices for Arduino Tooling projects. --- .github/workflows/build.yml | 1 - .github/workflows/check-javascript.yml | 88 ++++++++++++++++++++++++++ README.md | 1 + 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/check-javascript.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b729931c..7c45d875 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -395,7 +395,6 @@ jobs: yarn --cwd arduino-ide-extension build yarn test yarn --cwd arduino-ide-extension test:slow - yarn --cwd arduino-ide-extension lint yarn --cwd electron-app rebuild yarn --cwd electron-app build diff --git a/.github/workflows/check-javascript.yml b/.github/workflows/check-javascript.yml new file mode 100644 index 00000000..23162a19 --- /dev/null +++ b/.github/workflows/check-javascript.yml @@ -0,0 +1,88 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-javascript-task.md +name: Check JavaScript + +env: + # See: https://github.com/actions/setup-node/#readme + NODE_VERSION: 18.17 + +# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows +on: + create: + push: + paths: + - '.github/workflows/check-javascript.ya?ml' + - '**/.eslintignore' + - '**/.eslintrc*' + - '**/.npmrc' + - '**/package.json' + - '**/package-lock.json' + - '**/yarn.lock' + - '**.jsx?' + pull_request: + paths: + - '.github/workflows/check-javascript.ya?ml' + - '**/.eslintignore' + - '**/.eslintrc*' + - '**/.npmrc' + - '**/package.json' + - '**/package-lock.json' + - '**/yarn.lock' + - '**.jsx?' + workflow_dispatch: + repository_dispatch: + +jobs: + run-determination: + runs-on: ubuntu-latest + permissions: {} + outputs: + result: ${{ steps.determination.outputs.result }} + steps: + - name: Determine if the rest of the workflow should run + id: determination + run: | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. + if [[ + "${{ github.event_name }}" != "create" || + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX + ]]; then + # Run the other jobs. + RESULT="true" + else + # There is no need to run the other jobs. + RESULT="false" + fi + + echo "result=$RESULT" >> $GITHUB_OUTPUT + + check: + needs: run-determination + if: needs.run-determination.outputs.result == 'true' + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + cache: yarn + node-version: ${{ env.NODE_VERSION }} + + - name: Install npm package dependencies + env: + # Avoid failure of @vscode/ripgrep installation due to GitHub API rate limiting: + # https://github.com/microsoft/vscode-ripgrep#github-api-limit-note + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + yarn install + + - name: Lint + run: | + yarn \ + --cwd arduino-ide-extension \ + lint diff --git a/README.md b/README.md index 68d635a9..666434d0 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ # Arduino IDE 2.x [![Arduino IDE](https://github.com/arduino/arduino-ide/workflows/Arduino%20IDE/badge.svg)](https://github.com/arduino/arduino-ide/actions?query=workflow%3A%22Arduino+IDE%22) +[![Check JavaScript status](https://github.com/arduino/arduino-ide/actions/workflows/check-javascript.yml/badge.svg)](https://github.com/arduino/arduino-ide/actions/workflows/check-javascript.yml) This repository contains the source code of the Arduino IDE 2.x. If you're looking for the old IDE, go to the [repository of the 1.x version](https://github.com/arduino/Arduino).