|
1 | 1 | # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-taskfiles.md
|
2 | 2 | name: Check Taskfiles
|
3 | 3 |
|
4 |
| -# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows |
| 4 | +env: |
| 5 | + # See: https://github.com/actions/setup-node/#readme |
| 6 | + NODE_VERSION: 16.x |
| 7 | + |
| 8 | +# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows |
5 | 9 | on:
|
| 10 | + create: |
6 | 11 | push:
|
7 | 12 | paths:
|
8 | 13 | - ".github/workflows/check-taskfiles.ya?ml"
|
| 14 | + - "package.json" |
| 15 | + - "package-lock.json" |
9 | 16 | - "**/Taskfile.ya?ml"
|
10 | 17 | - "**/DistTasks.ya?ml"
|
11 | 18 | pull_request:
|
12 | 19 | paths:
|
13 | 20 | - ".github/workflows/check-taskfiles.ya?ml"
|
| 21 | + - "package.json" |
| 22 | + - "package-lock.json" |
14 | 23 | - "**/Taskfile.ya?ml"
|
15 | 24 | - "**/DistTasks.ya?ml"
|
16 | 25 | schedule:
|
|
20 | 29 | repository_dispatch:
|
21 | 30 |
|
22 | 31 | jobs:
|
| 32 | + run-determination: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + outputs: |
| 35 | + result: ${{ steps.determination.outputs.result }} |
| 36 | + steps: |
| 37 | + - name: Determine if the rest of the workflow should run |
| 38 | + id: determination |
| 39 | + run: | |
| 40 | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" |
| 41 | + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. |
| 42 | + if [[ |
| 43 | + "${{ github.event_name }}" != "create" || |
| 44 | + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX |
| 45 | + ]]; then |
| 46 | + # Run the other jobs. |
| 47 | + RESULT="true" |
| 48 | + else |
| 49 | + # There is no need to run the other jobs. |
| 50 | + RESULT="false" |
| 51 | + fi |
| 52 | +
|
| 53 | + echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 54 | +
|
23 | 55 | validate:
|
24 | 56 | name: Validate ${{ matrix.file }}
|
| 57 | + needs: run-determination |
| 58 | + if: needs.run-determination.outputs.result == 'true' |
25 | 59 | runs-on: ubuntu-latest
|
26 | 60 |
|
27 | 61 | strategy:
|
28 | 62 | fail-fast: false
|
29 | 63 |
|
30 | 64 | matrix:
|
31 | 65 | file:
|
32 |
| - # TODO: add paths to any additional Taskfiles here |
33 | 66 | - ./**/Taskfile.yml
|
34 |
| - - ./DistTasks.yml |
| 67 | + - ./**/DistTasks.yml |
35 | 68 |
|
36 | 69 | steps:
|
37 | 70 | - name: Checkout repository
|
38 | 71 | uses: actions/checkout@v3
|
39 | 72 |
|
| 73 | + - name: Setup Node.js |
| 74 | + uses: actions/setup-node@v3 |
| 75 | + with: |
| 76 | + node-version: ${{ env.NODE_VERSION }} |
| 77 | + |
40 | 78 | - name: Download JSON schema for Taskfiles
|
41 | 79 | id: download-schema
|
42 | 80 | uses: carlosperate/download-file-action@v2
|
43 | 81 | with:
|
44 |
| - # See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/taskfile.json |
45 |
| - file-url: https://json.schemastore.org/taskfile.json |
| 82 | + # Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/taskfile.json |
| 83 | + file-url: https://taskfile.dev/schema.json |
46 | 84 | location: ${{ runner.temp }}/taskfile-schema
|
47 | 85 |
|
48 | 86 | - name: Install JSON schema validator
|
49 |
| - run: | |
50 |
| - sudo npm install \ |
51 |
| - --global \ |
52 |
| - ajv-cli \ |
53 |
| - ajv-formats |
| 87 | + run: npm install |
54 | 88 |
|
55 | 89 | - name: Validate ${{ matrix.file }}
|
56 | 90 | run: |
|
57 | 91 | # See: https://github.com/ajv-validator/ajv-cli#readme
|
58 |
| - ajv validate \ |
59 |
| - --all-errors \ |
60 |
| - --strict=false \ |
61 |
| - -c ajv-formats \ |
62 |
| - -s "${{ steps.download-schema.outputs.file-path }}" \ |
63 |
| - -d "${{ matrix.file }}" |
| 92 | + npx \ |
| 93 | + --package=ajv-cli \ |
| 94 | + --package=ajv-formats \ |
| 95 | + ajv validate \ |
| 96 | + --all-errors \ |
| 97 | + --strict=false \ |
| 98 | + -c ajv-formats \ |
| 99 | + -s "${{ steps.download-schema.outputs.file-path }}" \ |
| 100 | + -d "${{ matrix.file }}" |
0 commit comments