|
| 1 | +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-yaml-task.md |
| 2 | +name: Check YAML |
| 3 | + |
| 4 | +# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows |
| 5 | +on: |
| 6 | + create: |
| 7 | + push: |
| 8 | + paths: |
| 9 | + - ".python-version" |
| 10 | + - ".yamllint*" |
| 11 | + - "poetry.lock" |
| 12 | + - "pyproject.toml" |
| 13 | + # Source: https://github.com/ikatyang/linguist-languages/blob/master/data/YAML.json (used by Prettier) |
| 14 | + - "**/.clang-format" |
| 15 | + - "**/.clang-tidy" |
| 16 | + - "**/.gemrc" |
| 17 | + - "**/glide.lock" |
| 18 | + - "**.ya?ml*" |
| 19 | + - "**.mir" |
| 20 | + - "**.reek" |
| 21 | + - "**.rviz" |
| 22 | + - "**.sublime-syntax" |
| 23 | + - "**.syntax" |
| 24 | + pull_request: |
| 25 | + paths: |
| 26 | + - ".python-version" |
| 27 | + - ".yamllint*" |
| 28 | + - "poetry.lock" |
| 29 | + - "pyproject.toml" |
| 30 | + # Source: https://github.com/ikatyang/linguist-languages/blob/master/data/YAML.json (used by Prettier) |
| 31 | + - "**/.clang-format" |
| 32 | + - "**/.clang-tidy" |
| 33 | + - "**/.gemrc" |
| 34 | + - "**/glide.lock" |
| 35 | + - "**.ya?ml*" |
| 36 | + - "**.mir" |
| 37 | + - "**.reek" |
| 38 | + - "**.rviz" |
| 39 | + - "**.sublime-syntax" |
| 40 | + - "**.syntax" |
| 41 | + schedule: |
| 42 | + # Run periodically to catch breakage caused by external changes. |
| 43 | + - cron: "0 9 * * WED" |
| 44 | + workflow_dispatch: |
| 45 | + repository_dispatch: |
| 46 | + |
| 47 | +jobs: |
| 48 | + run-determination: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + outputs: |
| 51 | + result: ${{ steps.determination.outputs.result }} |
| 52 | + steps: |
| 53 | + - name: Determine if the rest of the workflow should run |
| 54 | + id: determination |
| 55 | + run: | |
| 56 | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" |
| 57 | + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. |
| 58 | + if [[ |
| 59 | + "${{ github.event_name }}" != "create" || |
| 60 | + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX |
| 61 | + ]]; then |
| 62 | + # Run the other jobs. |
| 63 | + RESULT="true" |
| 64 | + else |
| 65 | + # There is no need to run the other jobs. |
| 66 | + RESULT="false" |
| 67 | + fi |
| 68 | +
|
| 69 | + echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 70 | +
|
| 71 | + check: |
| 72 | + name: ${{ matrix.configuration.name }} |
| 73 | + needs: run-determination |
| 74 | + if: needs.run-determination.outputs.result == 'true' |
| 75 | + runs-on: ubuntu-latest |
| 76 | + |
| 77 | + strategy: |
| 78 | + fail-fast: false |
| 79 | + |
| 80 | + matrix: |
| 81 | + configuration: |
| 82 | + - name: Generate problem matcher output |
| 83 | + # yamllint's "github" output type produces annotated diffs, but is not useful to humans reading the log. |
| 84 | + format: github |
| 85 | + # The other matrix job is used to set the result, so this job is configured to always pass. |
| 86 | + continue-on-error: true |
| 87 | + - name: Check formatting |
| 88 | + # yamllint's "colored" output type is most suitable for humans reading the log. |
| 89 | + format: colored |
| 90 | + continue-on-error: false |
| 91 | + |
| 92 | + steps: |
| 93 | + - name: Checkout repository |
| 94 | + uses: actions/checkout@v3 |
| 95 | + |
| 96 | + - name: Install Python |
| 97 | + uses: actions/setup-python@v4 |
| 98 | + with: |
| 99 | + python-version-file: .python-version |
| 100 | + |
| 101 | + - name: Install Poetry |
| 102 | + run: | |
| 103 | + pipx install \ |
| 104 | + --python "$(which python)" \ |
| 105 | + poetry |
| 106 | +
|
| 107 | + - name: Install Task |
| 108 | + uses: arduino/setup-task@v1 |
| 109 | + with: |
| 110 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + version: 3.x |
| 112 | + |
| 113 | + - name: Check YAML |
| 114 | + continue-on-error: ${{ matrix.configuration.continue-on-error }} |
| 115 | + run: task yaml:lint YAMLLINT_FORMAT=${{ matrix.configuration.format }} |
0 commit comments