From 0ae93453ce22bfc9c34830b5c62ff5fe769a2774 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 17 Nov 2024 22:37:42 -0800 Subject: [PATCH 1/3] 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 b729931ce..7c45d875d 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 000000000..23162a19e --- /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 68d635a94..666434d00 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). From 756c181b89a49e0bcbbb548a3dd6760d9b1d5fab Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 17 Nov 2024 23:15:45 -0800 Subject: [PATCH 2/3] Use a dedicated GitHub Actions workflow for testing 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 running the project's test suites. 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 test run operation is hereby moved to a dedicated workflow, consistent with standard practices for Arduino Tooling projects. --- .github/workflows/build.yml | 8 -- .github/workflows/test-javascript.yml | 134 ++++++++++++++++++++++++++ README.md | 3 +- 3 files changed, 136 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/test-javascript.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7c45d875d..30194a433 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -372,11 +372,6 @@ jobs: IS_NIGHTLY: ${{ needs.build-type-determination.outputs.is-nightly }} IS_RELEASE: ${{ needs.build-type-determination.outputs.is-release }} CAN_SIGN: ${{ secrets[matrix.config.certificate-secret] != '' }} - # The CREATE_* environment vars are only used to run tests. These secrets are optional. Dependent tests will - # be skipped if not available. - CREATE_USERNAME: ${{ secrets.CREATE_USERNAME }} - CREATE_PASSWORD: ${{ secrets.CREATE_PASSWORD }} - CREATE_CLIENT_SECRET: ${{ secrets.CREATE_CLIENT_SECRET }} working-directory: ${{ matrix.config.working-directory || './' }} run: | # See: https://www.electron.build/code-signing @@ -393,9 +388,6 @@ jobs: yarn install --immutable yarn --cwd arduino-ide-extension build - yarn test - yarn --cwd arduino-ide-extension test:slow - yarn --cwd electron-app rebuild yarn --cwd electron-app build yarn --cwd electron-app package diff --git a/.github/workflows/test-javascript.yml b/.github/workflows/test-javascript.yml new file mode 100644 index 000000000..2ae001c7d --- /dev/null +++ b/.github/workflows/test-javascript.yml @@ -0,0 +1,134 @@ +name: Test JavaScript + +env: + # See vars.GO_VERSION field of https://github.com/arduino/arduino-cli/blob/master/DistTasks.yml + GO_VERSION: '1.21' + # See: https://github.com/actions/setup-node/#readme + NODE_VERSION: 18.17 + +on: + push: + paths: + - ".github/workflows/test-javascript.ya?ml" + - "**/.mocharc.js" + - "**/.mocharc.jsonc?" + - "**/.mocharc.ya?ml" + - "**/package.json" + - "**/package-lock.json" + - "**/yarn.lock" + - "tests/testdata/**" + - "**/tsconfig.json" + - "**.[jt]sx?" + pull_request: + paths: + - ".github/workflows/test-javascript.ya?ml" + - "**/.mocharc.js" + - "**/.mocharc.jsonc?" + - "**/.mocharc.ya?ml" + - "**/package.json" + - "**/package-lock.json" + - "**/yarn.lock" + - "tests/testdata/**" + - "**/tsconfig.json" + - "**.[jt]sx?" + 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 + + test: + name: test (${{ matrix.project.path }}, ${{ matrix.operating-system }}) + needs: run-determination + if: needs.run-determination.outputs.result == 'true' + runs-on: ${{ matrix.operating-system }} + defaults: + run: + shell: bash + permissions: + contents: read + + strategy: + fail-fast: false + matrix: + project: + - path: . + operating-system: + - macos-latest + - ubuntu-latest + - windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + cache: yarn + node-version: ${{ env.NODE_VERSION }} + + # See: https://github.com/eclipse-theia/theia/blob/master/doc/Developing.md#prerequisites + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version: '3.11.x' + + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Taskfile + uses: arduino/setup-task@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - 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: Compile TypeScript + run: | + yarn \ + --cwd arduino-ide-extension \ + build + + - name: Run tests + env: + # These secrets are optional. Dependent tests will be skipped if not available. + CREATE_USERNAME: ${{ secrets.CREATE_USERNAME }} + CREATE_PASSWORD: ${{ secrets.CREATE_PASSWORD }} + CREATE_CLIENT_SECRET: ${{ secrets.CREATE_CLIENT_SECRET }} + run: | + yarn test + yarn \ + --cwd arduino-ide-extension \ + test:slow diff --git a/README.md b/README.md index 666434d00..a7a88f491 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,9 @@ # 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) +[![Build status](https://github.com/arduino/arduino-ide/actions/workflows/build.yml/badge.svg)](https://github.com/arduino/arduino-ide/actions/workflows/build.yml) [![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) +[![Test JavaScript status](https://github.com/arduino/arduino-ide/actions/workflows/test-javascript.yml/badge.svg)](https://github.com/arduino/arduino-ide/actions/workflows/test-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). From d41e160f1007e3d1f921db9ea8e9a6ca446ad74c Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 18 Nov 2024 01:09:27 -0800 Subject: [PATCH 3/3] Use a dedicated GitHub workflow to check for problems with Yarn configuration 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 check the sync of the Yarn lockfile. This monolithic approach is harmful for multiple reasons: * Makes it difficult to interpret a failed workflow run * Makes the build workflow more difficult to maintain * Increases the turnaround time for contributors and maintainers to get feedback from the CI system The sync check operation is hereby moved to a dedicated workflow, consistent with standard practices for Arduino Tooling projects. --- .github/workflows/build.yml | 2 +- .github/workflows/check-yarn.yml | 91 ++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/check-yarn.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 30194a433..cd93b347f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -385,7 +385,7 @@ jobs: fi npx node-gyp install - yarn install --immutable + yarn install yarn --cwd arduino-ide-extension build yarn --cwd electron-app rebuild diff --git a/.github/workflows/check-yarn.yml b/.github/workflows/check-yarn.yml new file mode 100644 index 000000000..3b2efe92c --- /dev/null +++ b/.github/workflows/check-yarn.yml @@ -0,0 +1,91 @@ +name: Check Yarn + +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows +on: + create: + push: + paths: + - ".github/workflows/check-yarn.ya?ml" + - "**/.yarnrc" + - "**/package.json" + - "**/package-lock.json" + - "**/yarn.lock" + pull_request: + paths: + - ".github/workflows/check-yarn.ya?ml" + - "**/.yarnrc" + - "**/package.json" + - "**/package-lock.json" + - "**/yarn.lock" + schedule: + # Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema. + - cron: "0 8 * * TUE" + 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-sync: + name: check-sync (${{ matrix.project.path }}) + needs: run-determination + if: needs.run-determination.outputs.result == 'true' + runs-on: ubuntu-latest + permissions: + contents: read + + strategy: + fail-fast: false + matrix: + project: + - path: . + + 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 \ + --ignore-scripts + + - name: Check yarn.lock + run: | + git \ + diff \ + --color \ + --exit-code \ + "${{ matrix.project.path }}/yarn.lock"