|
| 1 | +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-shell-task.md |
| 2 | +name: Check Shell Scripts |
| 3 | + |
| 4 | +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows |
| 5 | +on: |
| 6 | + push: |
| 7 | + paths: |
| 8 | + - ".github/workflows/check-shell-task.ya?ml" |
| 9 | + - "Taskfile.ya?ml" |
| 10 | + - "**/.editorconfig" |
| 11 | + - "**.bash" |
| 12 | + - "**.sh" |
| 13 | + pull_request: |
| 14 | + paths: |
| 15 | + - ".github/workflows/check-shell-task.ya?ml" |
| 16 | + - "Taskfile.ya?ml" |
| 17 | + - "**/.editorconfig" |
| 18 | + - "**.bash" |
| 19 | + - "**.sh" |
| 20 | + schedule: |
| 21 | + # Run every Tuesday at 8 AM UTC to catch breakage caused by tool changes. |
| 22 | + - cron: "0 8 * * TUE" |
| 23 | + workflow_dispatch: |
| 24 | + repository_dispatch: |
| 25 | + |
| 26 | +jobs: |
| 27 | + lint: |
| 28 | + name: ${{ matrix.configuration.name }} |
| 29 | + runs-on: ubuntu-latest |
| 30 | + |
| 31 | + env: |
| 32 | + # See: https://github.com/koalaman/shellcheck/releases/latest |
| 33 | + SHELLCHECK_RELEASE_ASSET_SUFFIX: .linux.x86_64.tar.xz |
| 34 | + |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + |
| 38 | + matrix: |
| 39 | + configuration: |
| 40 | + - name: Generate problem matcher output |
| 41 | + # ShellCheck's "gcc" output format is required for annotated diffs, but inferior for humans reading the log. |
| 42 | + format: gcc |
| 43 | + # The other matrix job is used to set the result, so this job is configured to always pass. |
| 44 | + continue-on-error: true |
| 45 | + - name: ShellCheck |
| 46 | + # ShellCheck's "tty" output format is most suitable for humans reading the log. |
| 47 | + format: tty |
| 48 | + continue-on-error: false |
| 49 | + |
| 50 | + steps: |
| 51 | + - name: Set environment variables |
| 52 | + run: | |
| 53 | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable |
| 54 | + echo "INSTALL_PATH=${{ runner.temp }}/shellcheck" >> "$GITHUB_ENV" |
| 55 | +
|
| 56 | + - name: Checkout repository |
| 57 | + uses: actions/checkout@v2 |
| 58 | + |
| 59 | + - name: Install Task |
| 60 | + uses: arduino/setup-task@v1 |
| 61 | + with: |
| 62 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + version: 3.x |
| 64 | + |
| 65 | + - name: Download latest ShellCheck release binary package |
| 66 | + id: download |
| 67 | + |
| 68 | + with: |
| 69 | + repository: koalaman/shellcheck |
| 70 | + excludes: prerelease, draft |
| 71 | + asset: ${{ env.SHELLCHECK_RELEASE_ASSET_SUFFIX }} |
| 72 | + target: ${{ env.INSTALL_PATH }} |
| 73 | + |
| 74 | + - name: Install ShellCheck |
| 75 | + run: | |
| 76 | + cd "${{ env.INSTALL_PATH }}" |
| 77 | + tar --extract --file="${{ steps.download.outputs.name }}" |
| 78 | + EXTRACTION_FOLDER="$(basename "${{ steps.download.outputs.name }}" "${{ env.SHELLCHECK_RELEASE_ASSET_SUFFIX }}")" |
| 79 | + # Add installation to PATH: |
| 80 | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path |
| 81 | + echo "${{ env.INSTALL_PATH }}/$EXTRACTION_FOLDER" >> "$GITHUB_PATH" |
| 82 | +
|
| 83 | + - name: Run ShellCheck |
| 84 | + uses: liskin/gh-problem-matcher-wrap@v1 |
| 85 | + continue-on-error: ${{ matrix.configuration.continue-on-error }} |
| 86 | + with: |
| 87 | + linters: gcc |
| 88 | + run: task --silent shell:check SHELLCHECK_FORMAT=${{ matrix.configuration.format }} |
| 89 | + |
| 90 | + formatting: |
| 91 | + runs-on: ubuntu-latest |
| 92 | + |
| 93 | + steps: |
| 94 | + - name: Set environment variables |
| 95 | + run: | |
| 96 | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable |
| 97 | + echo "SHFMT_INSTALL_PATH=${{ runner.temp }}/shfmt" >> "$GITHUB_ENV" |
| 98 | +
|
| 99 | + - name: Checkout repository |
| 100 | + uses: actions/checkout@v2 |
| 101 | + |
| 102 | + - name: Install Task |
| 103 | + uses: arduino/setup-task@v1 |
| 104 | + with: |
| 105 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + version: 3.x |
| 107 | + |
| 108 | + - name: Download shfmt |
| 109 | + id: download |
| 110 | + |
| 111 | + with: |
| 112 | + repository: mvdan/sh |
| 113 | + excludes: prerelease, draft |
| 114 | + asset: _linux_amd64 |
| 115 | + target: ${{ env.SHFMT_INSTALL_PATH }} |
| 116 | + |
| 117 | + - name: Install shfmt |
| 118 | + run: | |
| 119 | + # Executable permissions of release assets are lost |
| 120 | + chmod +x "${{ env.SHFMT_INSTALL_PATH }}/${{ steps.download.outputs.name }}" |
| 121 | + # Standardize binary name |
| 122 | + mv "${{ env.SHFMT_INSTALL_PATH }}/${{ steps.download.outputs.name }}" "${{ env.SHFMT_INSTALL_PATH }}/shfmt" |
| 123 | + # Add installation to PATH: |
| 124 | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path |
| 125 | + echo "${{ env.SHFMT_INSTALL_PATH }}" >> "$GITHUB_PATH" |
| 126 | +
|
| 127 | + - name: Format shell scripts |
| 128 | + run: task --silent shell:format |
| 129 | + |
| 130 | + - name: Check formatting |
| 131 | + run: git diff --color --exit-code |
0 commit comments