|
| 1 | +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-prettier-formatting-task.md |
| 2 | +name: Check Prettier Formatting |
| 3 | + |
| 4 | +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows |
| 5 | +on: |
| 6 | + create: |
| 7 | + push: |
| 8 | + paths: |
| 9 | + - ".github/workflows/check-prettier-formatting-task.ya?ml" |
| 10 | + - "Taskfile.ya?ml" |
| 11 | + - "**/.npmrc" |
| 12 | + - "**/.prettierignore" |
| 13 | + - "**/.prettierrc*" |
| 14 | + # Prettier-covered file patterns are defined by: |
| 15 | + # https://github.com/github-linguist/linguist/blob/master/lib/linguist/languages.yml |
| 16 | + # CSS |
| 17 | + - "**.css" |
| 18 | + - "**.wxss" |
| 19 | + # PostCSS |
| 20 | + - "**.pcss" |
| 21 | + - "**.postcss" |
| 22 | + # Less |
| 23 | + - "**.less" |
| 24 | + # SCSS |
| 25 | + - "**.scss" |
| 26 | + # GraphQL |
| 27 | + - "**.graphqls?" |
| 28 | + - "**.gql" |
| 29 | + # handlebars |
| 30 | + - "**.handlebars" |
| 31 | + - "**.hbs" |
| 32 | + # HTML |
| 33 | + - "**.mjml" |
| 34 | + - "**.html?" |
| 35 | + - "**.html.hl" |
| 36 | + - "**.st" |
| 37 | + - "**.xht" |
| 38 | + - "**.xhtml" |
| 39 | + # Vue |
| 40 | + - "**.vue" |
| 41 | + # JavaScript |
| 42 | + - "**.flow" |
| 43 | + - "**._?jsb?" |
| 44 | + - "**.bones" |
| 45 | + - "**.cjs" |
| 46 | + - "**.es6?" |
| 47 | + - "**.frag" |
| 48 | + - "**.gs" |
| 49 | + - "**.jake" |
| 50 | + - "**.jscad" |
| 51 | + - "**.jsfl" |
| 52 | + - "**.js[ms]" |
| 53 | + - "**.[mn]js" |
| 54 | + - "**.pac" |
| 55 | + - "**.wxs" |
| 56 | + - "**.[xs]s?js" |
| 57 | + - "**.xsjslib" |
| 58 | + # JSX |
| 59 | + - "**.jsx" |
| 60 | + # TypeScript |
| 61 | + - "**.ts" |
| 62 | + # TSX |
| 63 | + - "**.tsx" |
| 64 | + # JSON |
| 65 | + - "**/.eslintrc" |
| 66 | + - "**.json" |
| 67 | + - "**.avsc" |
| 68 | + - "**.geojson" |
| 69 | + - "**.gltf" |
| 70 | + - "**.har" |
| 71 | + - "**.ice" |
| 72 | + - "**.JSON-tmLanguage" |
| 73 | + - "**.mcmeta" |
| 74 | + - "**.tfstate" |
| 75 | + - "**.topojson" |
| 76 | + - "**.webapp" |
| 77 | + - "**.webmanifest" |
| 78 | + - "**.yyp?" |
| 79 | + # JSONC |
| 80 | + - "**/.babelrc" |
| 81 | + - "**/.jscsrc" |
| 82 | + - "**/.js[hl]intrc" |
| 83 | + - "**.jsonc" |
| 84 | + - "**.sublime-*" |
| 85 | + # JSON5 |
| 86 | + - "**.json5" |
| 87 | + # Markdown |
| 88 | + - "**.mdx?" |
| 89 | + - "**.markdown" |
| 90 | + - "**.mk?down" |
| 91 | + - "**.mdwn" |
| 92 | + - "**.mkdn?" |
| 93 | + - "**.ronn" |
| 94 | + - "**.workbook" |
| 95 | + # YAML |
| 96 | + - "**/.clang-format" |
| 97 | + - "**/.clang-tidy" |
| 98 | + - "**/.gemrc" |
| 99 | + - "**/glide.lock" |
| 100 | + - "**.ya?ml*" |
| 101 | + - "**.mir" |
| 102 | + - "**.reek" |
| 103 | + - "**.rviz" |
| 104 | + - "**.sublime-syntax" |
| 105 | + - "**.syntax" |
| 106 | + pull_request: |
| 107 | + paths: |
| 108 | + - ".github/workflows/check-prettier-formatting-task.ya?ml" |
| 109 | + - "Taskfile.ya?ml" |
| 110 | + - "**/.npmrc" |
| 111 | + - "**/.prettierignore" |
| 112 | + - "**/.prettierrc*" |
| 113 | + # CSS |
| 114 | + - "**.css" |
| 115 | + - "**.wxss" |
| 116 | + # PostCSS |
| 117 | + - "**.pcss" |
| 118 | + - "**.postcss" |
| 119 | + # Less |
| 120 | + - "**.less" |
| 121 | + # SCSS |
| 122 | + - "**.scss" |
| 123 | + # GraphQL |
| 124 | + - "**.graphqls?" |
| 125 | + - "**.gql" |
| 126 | + # handlebars |
| 127 | + - "**.handlebars" |
| 128 | + - "**.hbs" |
| 129 | + # HTML |
| 130 | + - "**.mjml" |
| 131 | + - "**.html?" |
| 132 | + - "**.html.hl" |
| 133 | + - "**.st" |
| 134 | + - "**.xht" |
| 135 | + - "**.xhtml" |
| 136 | + # Vue |
| 137 | + - "**.vue" |
| 138 | + # JavaScript |
| 139 | + - "**.flow" |
| 140 | + - "**._?jsb?" |
| 141 | + - "**.bones" |
| 142 | + - "**.cjs" |
| 143 | + - "**.es6?" |
| 144 | + - "**.frag" |
| 145 | + - "**.gs" |
| 146 | + - "**.jake" |
| 147 | + - "**.jscad" |
| 148 | + - "**.jsfl" |
| 149 | + - "**.js[ms]" |
| 150 | + - "**.[mn]js" |
| 151 | + - "**.pac" |
| 152 | + - "**.wxs" |
| 153 | + - "**.[xs]s?js" |
| 154 | + - "**.xsjslib" |
| 155 | + # JSX |
| 156 | + - "**.jsx" |
| 157 | + # TypeScript |
| 158 | + - "**.ts" |
| 159 | + # TSX |
| 160 | + - "**.tsx" |
| 161 | + # JSON |
| 162 | + - "**/.eslintrc" |
| 163 | + - "**.json" |
| 164 | + - "**.avsc" |
| 165 | + - "**.geojson" |
| 166 | + - "**.gltf" |
| 167 | + - "**.har" |
| 168 | + - "**.ice" |
| 169 | + - "**.JSON-tmLanguage" |
| 170 | + - "**.mcmeta" |
| 171 | + - "**.tfstate" |
| 172 | + - "**.topojson" |
| 173 | + - "**.webapp" |
| 174 | + - "**.webmanifest" |
| 175 | + - "**.yyp?" |
| 176 | + # JSONC |
| 177 | + - "**/.babelrc" |
| 178 | + - "**/.jscsrc" |
| 179 | + - "**/.js[hl]intrc" |
| 180 | + - "**.jsonc" |
| 181 | + - "**.sublime-*" |
| 182 | + # JSON5 |
| 183 | + - "**.json5" |
| 184 | + # Markdown |
| 185 | + - "**.mdx?" |
| 186 | + - "**.markdown" |
| 187 | + - "**.mk?down" |
| 188 | + - "**.mdwn" |
| 189 | + - "**.mkdn?" |
| 190 | + - "**.ronn" |
| 191 | + - "**.workbook" |
| 192 | + # YAML |
| 193 | + - "**/.clang-format" |
| 194 | + - "**/.clang-tidy" |
| 195 | + - "**/.gemrc" |
| 196 | + - "**/glide.lock" |
| 197 | + - "**.ya?ml*" |
| 198 | + - "**.mir" |
| 199 | + - "**.reek" |
| 200 | + - "**.rviz" |
| 201 | + - "**.sublime-syntax" |
| 202 | + - "**.syntax" |
| 203 | + schedule: |
| 204 | + # Run periodically to catch breakage caused by external changes. |
| 205 | + - cron: "0 4 * * WED" |
| 206 | + workflow_dispatch: |
| 207 | + repository_dispatch: |
| 208 | + |
| 209 | +jobs: |
| 210 | + run-determination: |
| 211 | + runs-on: ubuntu-latest |
| 212 | + permissions: {} |
| 213 | + outputs: |
| 214 | + result: ${{ steps.determination.outputs.result }} |
| 215 | + steps: |
| 216 | + - name: Determine if the rest of the workflow should run |
| 217 | + id: determination |
| 218 | + run: | |
| 219 | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" |
| 220 | + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. |
| 221 | + if [[ |
| 222 | + "${{ github.event_name }}" != "create" || |
| 223 | + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX |
| 224 | + ]]; then |
| 225 | + # Run the other jobs. |
| 226 | + RESULT="true" |
| 227 | + else |
| 228 | + # There is no need to run the other jobs. |
| 229 | + RESULT="false" |
| 230 | + fi |
| 231 | +
|
| 232 | + echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 233 | +
|
| 234 | + check: |
| 235 | + needs: run-determination |
| 236 | + if: needs.run-determination.outputs.result == 'true' |
| 237 | + runs-on: ubuntu-latest |
| 238 | + permissions: |
| 239 | + contents: read |
| 240 | + |
| 241 | + steps: |
| 242 | + - name: Checkout repository |
| 243 | + uses: actions/checkout@v4 |
| 244 | + |
| 245 | + - name: Setup Node.js |
| 246 | + uses: actions/setup-node@v4 |
| 247 | + with: |
| 248 | + node-version-file: package.json |
| 249 | + |
| 250 | + - name: Install Task |
| 251 | + uses: arduino/setup-task@v2 |
| 252 | + with: |
| 253 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 254 | + version: 3.x |
| 255 | + |
| 256 | + - name: Format with Prettier |
| 257 | + run: | |
| 258 | + task \ |
| 259 | + general:format-prettier |
| 260 | +
|
| 261 | + - name: Check formatting |
| 262 | + run: | |
| 263 | + git \ |
| 264 | + diff \ |
| 265 | + --color \ |
| 266 | + --exit-code |
0 commit comments