| 
 | 1 | +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-npm-task.md  | 
 | 2 | +name: Check npm  | 
 | 3 | + | 
 | 4 | +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows  | 
 | 5 | +on:  | 
 | 6 | +  create:  | 
 | 7 | +  push:  | 
 | 8 | +    paths:  | 
 | 9 | +      - ".github/workflows/check-npm-task.ya?ml"  | 
 | 10 | +      - "**/.npmrc"  | 
 | 11 | +      - "**/package.json"  | 
 | 12 | +      - "**/package-lock.json"  | 
 | 13 | +      - "Taskfile.ya?ml"  | 
 | 14 | +  pull_request:  | 
 | 15 | +    paths:  | 
 | 16 | +      - ".github/workflows/check-npm-task.ya?ml"  | 
 | 17 | +      - "**/.npmrc"  | 
 | 18 | +      - "**/package.json"  | 
 | 19 | +      - "**/package-lock.json"  | 
 | 20 | +      - "Taskfile.ya?ml"  | 
 | 21 | +  schedule:  | 
 | 22 | +    # Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.  | 
 | 23 | +    - cron: "0 8 * * TUE"  | 
 | 24 | +  workflow_dispatch:  | 
 | 25 | +  repository_dispatch:  | 
 | 26 | + | 
 | 27 | +jobs:  | 
 | 28 | +  run-determination:  | 
 | 29 | +    runs-on: ubuntu-latest  | 
 | 30 | +    permissions: {}  | 
 | 31 | +    outputs:  | 
 | 32 | +      result: ${{ steps.determination.outputs.result }}  | 
 | 33 | +    steps:  | 
 | 34 | +      - name: Determine if the rest of the workflow should run  | 
 | 35 | +        id: determination  | 
 | 36 | +        run: |  | 
 | 37 | +          RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"  | 
 | 38 | +          # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.  | 
 | 39 | +          if [[  | 
 | 40 | +            "${{ github.event_name }}" != "create" ||  | 
 | 41 | +            "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX  | 
 | 42 | +          ]]; then  | 
 | 43 | +            # Run the other jobs.  | 
 | 44 | +            RESULT="true"  | 
 | 45 | +          else  | 
 | 46 | +            # There is no need to run the other jobs.  | 
 | 47 | +            RESULT="false"  | 
 | 48 | +          fi  | 
 | 49 | +
  | 
 | 50 | +          echo "result=$RESULT" >> $GITHUB_OUTPUT  | 
 | 51 | +
  | 
 | 52 | +  validate:  | 
 | 53 | +    name: validate (${{ matrix.project.path }})  | 
 | 54 | +    needs: run-determination  | 
 | 55 | +    if: needs.run-determination.outputs.result == 'true'  | 
 | 56 | +    runs-on: ubuntu-latest  | 
 | 57 | +    permissions:  | 
 | 58 | +      contents: read  | 
 | 59 | + | 
 | 60 | +    strategy:  | 
 | 61 | +      fail-fast: false  | 
 | 62 | +      matrix:  | 
 | 63 | +        project:  | 
 | 64 | +          - path: .  | 
 | 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 | +          node-version-file: package.json  | 
 | 74 | + | 
 | 75 | +      - name: Install Task  | 
 | 76 | +        uses: arduino/setup-task@v2  | 
 | 77 | +        with:  | 
 | 78 | +          repo-token: ${{ secrets.GITHUB_TOKEN }}  | 
 | 79 | +          version: 3.x  | 
 | 80 | + | 
 | 81 | +      - name: Validate package.json  | 
 | 82 | +        run: |  | 
 | 83 | +          task \  | 
 | 84 | +            --silent \  | 
 | 85 | +            npm:validate \  | 
 | 86 | +            PROJECT_PATH="${{ matrix.project.path }}"  | 
 | 87 | +
  | 
 | 88 | +  check-sync:  | 
 | 89 | +    name: check-sync (${{ matrix.project.path }})  | 
 | 90 | +    needs: run-determination  | 
 | 91 | +    if: needs.run-determination.outputs.result == 'true'  | 
 | 92 | +    runs-on: ubuntu-latest  | 
 | 93 | +    permissions:  | 
 | 94 | +      contents: read  | 
 | 95 | + | 
 | 96 | +    strategy:  | 
 | 97 | +      fail-fast: false  | 
 | 98 | +      matrix:  | 
 | 99 | +        project:  | 
 | 100 | +          - path: .  | 
 | 101 | + | 
 | 102 | +    steps:  | 
 | 103 | +      - name: Checkout repository  | 
 | 104 | +        uses: actions/checkout@v4  | 
 | 105 | + | 
 | 106 | +      - name: Setup Node.js  | 
 | 107 | +        uses: actions/setup-node@v4  | 
 | 108 | +        with:  | 
 | 109 | +          node-version-file: package.json  | 
 | 110 | + | 
 | 111 | +      - name: Install Task  | 
 | 112 | +        uses: arduino/setup-task@v2  | 
 | 113 | +        with:  | 
 | 114 | +          repo-token: ${{ secrets.GITHUB_TOKEN }}  | 
 | 115 | +          version: 3.x  | 
 | 116 | + | 
 | 117 | +      - name: Install npm dependencies  | 
 | 118 | +        run: |  | 
 | 119 | +          task \  | 
 | 120 | +            npm:install-deps \  | 
 | 121 | +            PROJECT_PATH="${{ matrix.project.path }}"  | 
 | 122 | +
  | 
 | 123 | +      - name: Check package-lock.json  | 
 | 124 | +        run: |  | 
 | 125 | +          git \  | 
 | 126 | +            diff \  | 
 | 127 | +              --color \  | 
 | 128 | +              --exit-code \  | 
 | 129 | +              "${{ matrix.project.path }}/package-lock.json"  | 
0 commit comments