|
| 1 | +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-general-formatting-task.md |
| 2 | +name: Check General Formatting |
| 3 | + |
| 4 | +# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows |
| 5 | +on: |
| 6 | + create: |
| 7 | + push: |
| 8 | + pull_request: |
| 9 | + schedule: |
| 10 | + # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to tools. |
| 11 | + - cron: "0 8 * * TUE" |
| 12 | + workflow_dispatch: |
| 13 | + repository_dispatch: |
| 14 | + |
| 15 | +jobs: |
| 16 | + run-determination: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + result: ${{ steps.determination.outputs.result }} |
| 20 | + steps: |
| 21 | + - name: Determine if the rest of the workflow should run |
| 22 | + id: determination |
| 23 | + run: | |
| 24 | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" |
| 25 | + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. |
| 26 | + if [[ |
| 27 | + "${{ github.event_name }}" != "create" || |
| 28 | + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX |
| 29 | + ]]; then |
| 30 | + # Run the other jobs. |
| 31 | + RESULT="true" |
| 32 | + else |
| 33 | + # There is no need to run the other jobs. |
| 34 | + RESULT="false" |
| 35 | + fi |
| 36 | +
|
| 37 | + echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 38 | +
|
| 39 | + check: |
| 40 | + needs: run-determination |
| 41 | + if: needs.run-determination.outputs.result == 'true' |
| 42 | + runs-on: ubuntu-latest |
| 43 | + |
| 44 | + steps: |
| 45 | + - name: Set environment variables |
| 46 | + run: | |
| 47 | + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable |
| 48 | + echo "EC_INSTALL_PATH=${{ runner.temp }}/editorconfig-checker" >> "$GITHUB_ENV" |
| 49 | +
|
| 50 | + - name: Checkout repository |
| 51 | + uses: actions/checkout@v3 |
| 52 | + |
| 53 | + - name: Install Task |
| 54 | + uses: arduino/setup-task@v1 |
| 55 | + with: |
| 56 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + version: 3.x |
| 58 | + |
| 59 | + - name: Download latest editorconfig-checker release binary package |
| 60 | + id: download |
| 61 | + uses: MrOctopus/download-asset-action@1.0 |
| 62 | + with: |
| 63 | + repository: editorconfig-checker/editorconfig-checker |
| 64 | + excludes: prerelease, draft |
| 65 | + asset: linux-amd64.tar.gz |
| 66 | + target: ${{ env.EC_INSTALL_PATH }} |
| 67 | + |
| 68 | + - name: Install editorconfig-checker |
| 69 | + run: | |
| 70 | + cd "${{ env.EC_INSTALL_PATH }}" |
| 71 | + tar --extract --file="${{ steps.download.outputs.name }}" |
| 72 | + # Give the binary a standard name |
| 73 | + mv "${{ env.EC_INSTALL_PATH }}/bin/ec-linux-amd64" "${{ env.EC_INSTALL_PATH }}/bin/ec" |
| 74 | + # Add installation to PATH: |
| 75 | + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path |
| 76 | + echo "${{ env.EC_INSTALL_PATH }}/bin" >> "$GITHUB_PATH" |
| 77 | +
|
| 78 | + - name: Check formatting |
| 79 | + run: task --silent general:check-formatting |
0 commit comments