|
| 1 | +name: Check ClangFormat Configuration |
| 2 | + |
| 3 | +env: |
| 4 | + # See: https://github.com/actions/setup-node/#readme |
| 5 | + NODE_VERSION: 16.x |
| 6 | + |
| 7 | +# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows |
| 8 | +on: |
| 9 | + push: |
| 10 | + paths: |
| 11 | + - ".github/workflows/check-clang-format.yml" |
| 12 | + - "other/clang-format-configuration/scripts/convert-clang-format-configuration.js" |
| 13 | + - "other/clang-format-configuration/testdata/**" |
| 14 | + - "other/clang-format-configuration/.clang-format" |
| 15 | + - "package.json" |
| 16 | + - "package-lock.json" |
| 17 | + - "Taskfile.ya?ml" |
| 18 | + pull_request: |
| 19 | + paths: |
| 20 | + - ".github/workflows/check-clang-format.yml" |
| 21 | + - "other/clang-format-configuration/scripts/convert-clang-format-configuration.js" |
| 22 | + - "other/clang-format-configuration/testdata/**" |
| 23 | + - "other/clang-format-configuration/.clang-format" |
| 24 | + - "package.json" |
| 25 | + - "package-lock.json" |
| 26 | + - "Taskfile.ya?ml" |
| 27 | + schedule: |
| 28 | + # Run periodically to catch breakage caused by external changes. |
| 29 | + - cron: "0 17 * * WED" |
| 30 | + workflow_dispatch: |
| 31 | + inputs: |
| 32 | + clang-format-version: |
| 33 | + description: ClangFormat version (leave empty for standard version) |
| 34 | + type: string |
| 35 | + default: "" |
| 36 | + required: false |
| 37 | + repository_dispatch: |
| 38 | + |
| 39 | +jobs: |
| 40 | + validate: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + |
| 43 | + steps: |
| 44 | + - name: Checkout repository |
| 45 | + uses: actions/checkout@v3 |
| 46 | + |
| 47 | + - name: Setup Node.js |
| 48 | + uses: actions/setup-node@v3 |
| 49 | + with: |
| 50 | + node-version: ${{ env.NODE_VERSION }} |
| 51 | + |
| 52 | + - name: Install Task |
| 53 | + uses: arduino/setup-task@v1 |
| 54 | + with: |
| 55 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + version: 3.x |
| 57 | + |
| 58 | + - name: Validate ClangFormat configuration files |
| 59 | + run: task --silent clang-format:validate |
| 60 | + |
| 61 | + check-config: |
| 62 | + runs-on: ubuntu-latest |
| 63 | + |
| 64 | + steps: |
| 65 | + - name: Checkout repository |
| 66 | + uses: actions/checkout@v3 |
| 67 | + |
| 68 | + - name: Install Task |
| 69 | + uses: arduino/setup-task@v1 |
| 70 | + with: |
| 71 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + version: 3.x |
| 73 | + |
| 74 | + - name: Set environment variables |
| 75 | + run: | |
| 76 | + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable |
| 77 | + if [[ "${{ github.event.inputs.clang-format-version }}" == "" ]]; then |
| 78 | + echo "CLANG_FORMAT_VERSION=$(task clang-format:get-version)" >> "$GITHUB_ENV" |
| 79 | + else |
| 80 | + echo "CLANG_FORMAT_VERSION=${{ github.event.inputs.clang-format-version }}" >> "$GITHUB_ENV" |
| 81 | + fi |
| 82 | + echo "CLANG_FORMAT_INSTALL_PATH=${{ runner.temp }}/clang-format" >> "$GITHUB_ENV" |
| 83 | + echo "WORKING_FOLDER=${{ runner.temp }}" >> "$GITHUB_ENV" |
| 84 | +
|
| 85 | + - name: Download ClangFormat |
| 86 | + id: download |
| 87 | + |
| 88 | + with: |
| 89 | + repository: arduino/clang-static-binaries |
| 90 | + tag: ${{ env.CLANG_FORMAT_VERSION }} |
| 91 | + asset: clang-format_${{ env.CLANG_FORMAT_VERSION }}_Linux_64bit.tar.bz2 |
| 92 | + target: ${{ env.CLANG_FORMAT_INSTALL_PATH }} |
| 93 | + |
| 94 | + - name: Install ClangFormat |
| 95 | + run: | |
| 96 | + cd "${{ env.CLANG_FORMAT_INSTALL_PATH }}" |
| 97 | + tar --extract --file="${{ steps.download.outputs.name }}" |
| 98 | + # Add installation to PATH: |
| 99 | + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path |
| 100 | + echo "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH" |
| 101 | +
|
| 102 | + - name: Check ClangFormat configuration file |
| 103 | + id: check |
| 104 | + run: | |
| 105 | + task \ |
| 106 | + --silent \ |
| 107 | + clang-format:check-config \ |
| 108 | + CLANG_FORMAT_VERSION="${{ env.CLANG_FORMAT_VERSION }}" |
| 109 | +
|
| 110 | + - name: Save effective configuration file to a workflow artifact |
| 111 | + if: > |
| 112 | + always() && |
| 113 | + steps.check.outcome == 'failure' |
| 114 | + uses: actions/upload-artifact@v3 |
| 115 | + with: |
| 116 | + path: ${{ env.WORKING_FOLDER }}/expected/.clang-format |
| 117 | + if-no-files-found: error |
| 118 | + name: config-output |
| 119 | + |
| 120 | + check-output: |
| 121 | + runs-on: ubuntu-latest |
| 122 | + |
| 123 | + steps: |
| 124 | + - name: Checkout repository |
| 125 | + uses: actions/checkout@v3 |
| 126 | + |
| 127 | + - name: Install Task |
| 128 | + uses: arduino/setup-task@v1 |
| 129 | + with: |
| 130 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 131 | + version: 3.x |
| 132 | + |
| 133 | + - name: Set environment variables |
| 134 | + run: | |
| 135 | + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable |
| 136 | + if [[ "${{ github.event.inputs.clang-format-version }}" == "" ]]; then |
| 137 | + echo "CLANG_FORMAT_VERSION=$(task clang-format:get-version)" >> "$GITHUB_ENV" |
| 138 | + else |
| 139 | + echo "CLANG_FORMAT_VERSION=${{ github.event.inputs.clang-format-version }}" >> "$GITHUB_ENV" |
| 140 | + fi |
| 141 | + echo "CLANG_FORMAT_INSTALL_PATH=${{ runner.temp }}/clang-format" >> "$GITHUB_ENV" |
| 142 | + echo "WORKING_FOLDER=${{ runner.temp }}" >> "$GITHUB_ENV" |
| 143 | +
|
| 144 | + - name: Download ClangFormat |
| 145 | + id: download |
| 146 | + |
| 147 | + with: |
| 148 | + repository: arduino/clang-static-binaries |
| 149 | + tag: ${{ env.CLANG_FORMAT_VERSION }} |
| 150 | + asset: clang-format_${{ env.CLANG_FORMAT_VERSION }}_Linux_64bit.tar.bz2 |
| 151 | + target: ${{ env.CLANG_FORMAT_INSTALL_PATH }} |
| 152 | + |
| 153 | + - name: Install ClangFormat |
| 154 | + run: | |
| 155 | + cd "${{ env.CLANG_FORMAT_INSTALL_PATH }}" |
| 156 | + tar --extract --file="${{ steps.download.outputs.name }}" |
| 157 | + # Add installation to PATH: |
| 158 | + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path |
| 159 | + echo "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH" |
| 160 | +
|
| 161 | + - name: Check ClangFormat output |
| 162 | + id: check |
| 163 | + run: | |
| 164 | + task \ |
| 165 | + clang-format:check-output \ |
| 166 | + CLANG_FORMAT_VERSION="${{ env.CLANG_FORMAT_VERSION }}" \ |
| 167 | + WORKING_FOLDER="${{ env.WORKING_FOLDER }}" |
| 168 | +
|
| 169 | + - name: Save formatted test data to a workflow artifact |
| 170 | + if: > |
| 171 | + always() && |
| 172 | + steps.check.outcome == 'failure' |
| 173 | + uses: actions/upload-artifact@v3 |
| 174 | + with: |
| 175 | + path: ${{ env.WORKING_FOLDER }}/output |
| 176 | + if-no-files-found: error |
| 177 | + name: testdata-output |
| 178 | + |
| 179 | + check-testdata: |
| 180 | + runs-on: ubuntu-latest |
| 181 | + |
| 182 | + steps: |
| 183 | + - name: Checkout repository |
| 184 | + uses: actions/checkout@v3 |
| 185 | + |
| 186 | + - name: Install Task |
| 187 | + uses: arduino/setup-task@v1 |
| 188 | + with: |
| 189 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 190 | + version: 3.x |
| 191 | + |
| 192 | + - name: Check ClangFormat test data |
| 193 | + run: task --silent clang-format:check-testdata |
| 194 | + |
| 195 | + convert: |
| 196 | + runs-on: ubuntu-latest |
| 197 | + |
| 198 | + steps: |
| 199 | + - name: Set environment variables |
| 200 | + run: | |
| 201 | + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable |
| 202 | + echo "CONVERSION_OUTPUT_PATH=${{ runner.temp }}/clang-format-js-object.txt" >> "$GITHUB_ENV" |
| 203 | +
|
| 204 | + - name: Checkout repository |
| 205 | + uses: actions/checkout@v3 |
| 206 | + |
| 207 | + - name: Setup Node.js |
| 208 | + uses: actions/setup-node@v3 |
| 209 | + with: |
| 210 | + node-version: ${{ env.NODE_VERSION }} |
| 211 | + |
| 212 | + - name: Install Task |
| 213 | + uses: arduino/setup-task@v1 |
| 214 | + with: |
| 215 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 216 | + version: 3.x |
| 217 | + |
| 218 | + - name: Convert the ClangFormat configuration |
| 219 | + run: | |
| 220 | + task \ |
| 221 | + --silent \ |
| 222 | + clang-format:convert \ |
| 223 | + OUTPUT_PATH="${{ env.CONVERSION_OUTPUT_PATH }}" |
| 224 | +
|
| 225 | + - name: Save conversion to a workflow artifact |
| 226 | + uses: actions/upload-artifact@v3 |
| 227 | + with: |
| 228 | + path: ${{ env.CONVERSION_OUTPUT_PATH }} |
| 229 | + if-no-files-found: error |
| 230 | + name: javascript-configuration-object |
0 commit comments