|
| 1 | +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-javascript-task.md |
| 2 | +name: Check JavaScript |
| 3 | + |
| 4 | +env: |
| 5 | + # See: https://github.com/actions/setup-node/#readme |
| 6 | + NODE_VERSION: 18.17 |
| 7 | + |
| 8 | +# See: https://docs.github.com/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows |
| 9 | +on: |
| 10 | + create: |
| 11 | + push: |
| 12 | + paths: |
| 13 | + - '.github/workflows/check-javascript.ya?ml' |
| 14 | + - '**/.eslintignore' |
| 15 | + - '**/.eslintrc*' |
| 16 | + - '**/.npmrc' |
| 17 | + - '**/package.json' |
| 18 | + - '**/package-lock.json' |
| 19 | + - '**/yarn.lock' |
| 20 | + - '**.jsx?' |
| 21 | + pull_request: |
| 22 | + paths: |
| 23 | + - '.github/workflows/check-javascript.ya?ml' |
| 24 | + - '**/.eslintignore' |
| 25 | + - '**/.eslintrc*' |
| 26 | + - '**/.npmrc' |
| 27 | + - '**/package.json' |
| 28 | + - '**/package-lock.json' |
| 29 | + - '**/yarn.lock' |
| 30 | + - '**.jsx?' |
| 31 | + workflow_dispatch: |
| 32 | + repository_dispatch: |
| 33 | + |
| 34 | +jobs: |
| 35 | + run-determination: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + permissions: {} |
| 38 | + outputs: |
| 39 | + result: ${{ steps.determination.outputs.result }} |
| 40 | + steps: |
| 41 | + - name: Determine if the rest of the workflow should run |
| 42 | + id: determination |
| 43 | + run: | |
| 44 | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" |
| 45 | + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. |
| 46 | + if [[ |
| 47 | + "${{ github.event_name }}" != "create" || |
| 48 | + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX |
| 49 | + ]]; then |
| 50 | + # Run the other jobs. |
| 51 | + RESULT="true" |
| 52 | + else |
| 53 | + # There is no need to run the other jobs. |
| 54 | + RESULT="false" |
| 55 | + fi |
| 56 | +
|
| 57 | + echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 58 | +
|
| 59 | + check: |
| 60 | + needs: run-determination |
| 61 | + if: needs.run-determination.outputs.result == 'true' |
| 62 | + runs-on: ubuntu-latest |
| 63 | + permissions: |
| 64 | + contents: read |
| 65 | + |
| 66 | + steps: |
| 67 | + - name: Checkout repository |
| 68 | + uses: actions/checkout@v4 |
| 69 | + |
| 70 | + - name: Setup Node.js |
| 71 | + uses: actions/setup-node@v4 |
| 72 | + with: |
| 73 | + cache: yarn |
| 74 | + node-version: ${{ env.NODE_VERSION }} |
| 75 | + |
| 76 | + - name: Install npm package dependencies |
| 77 | + env: |
| 78 | + # Avoid failure of @vscode/ripgrep installation due to GitHub API rate limiting: |
| 79 | + # https://github.com/microsoft/vscode-ripgrep#github-api-limit-note |
| 80 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + run: | |
| 82 | + yarn install |
| 83 | +
|
| 84 | + - name: Lint |
| 85 | + run: | |
| 86 | + yarn \ |
| 87 | + --cwd arduino-ide-extension \ |
| 88 | + lint |
0 commit comments