Skip to content

Commit a1c0ef4

Browse files
committed
Add reusable HTML formatting workflow
1 parent 6012e00 commit a1c0ef4

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

.github/workflows/check-html.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: check html
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
files:
7+
type: string
8+
default: "**/*.html"
9+
prettier_version:
10+
type: string
11+
default: "latest"
12+
13+
jobs:
14+
format:
15+
name: format
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout source code
19+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
20+
with:
21+
persist-credentials: false
22+
23+
- name: Check HTML file formatting
24+
env:
25+
INPUTS_PRETTIER_VERSION: ${{ inputs.prettier_version }}
26+
INPUTS_FILES: ${{ inputs.files }}
27+
run: |
28+
set -euo pipefail
29+
30+
# Split INPUTS_FILES into an array (space-separated)
31+
IFS=' ' read -r -a files <<<"$INPUTS_FILES"
32+
33+
npx --yes "prettier@${INPUTS_PRETTIER_VERSION}" \
34+
--check \
35+
--debug-check \
36+
--color \
37+
-- "${files[@]}"

.github/workflows/detect-changed-files.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ on:
1919
value: ${{ jobs.filter_changes.outputs.github_actions }}
2020
github_actions_files:
2121
value: ${{ jobs.filter_changes.outputs.github_actions_files }}
22+
html:
23+
value: ${{ jobs.filter_changes.outputs.html }}
24+
html_files:
25+
value: ${{ jobs.filter_changes.outputs.html_files }}
2226
markdown:
2327
value: ${{ jobs.filter_changes.outputs.markdown }}
2428
markdown_files:
@@ -47,6 +51,8 @@ jobs:
4751
flutter_files: ${{ steps.filter.outputs.flutter_files }}
4852
github_actions: ${{ steps.filter.outputs.github_actions }}
4953
github_actions_files: ${{ steps.filter.outputs.github_actions_files }}
54+
html: ${{ steps.filter.outputs.html }}
55+
html_files: ${{ steps.filter.outputs.html_files }}
5056
markdown: ${{ steps.filter.outputs.markdown }}
5157
markdown_files: ${{ steps.filter.outputs.markdown_files }}
5258
rust: ${{ steps.filter.outputs.rust }}
@@ -77,6 +83,8 @@ jobs:
7783
github_actions:
7884
- added|modified: .github/workflows/*.yml
7985
- added|modified: .github/workflows/*.yaml
86+
html:
87+
- added|modified: '**/*.html'
8088
markdown:
8189
- added|modified: '**/*.md'
8290
rust:
@@ -96,6 +104,8 @@ jobs:
96104
FLUTTER_FILES: ${{ steps.filter.outputs.flutter_files }}
97105
GH_ACTIONS: ${{ steps.filter.outputs.github_actions }}
98106
GH_ACTIONS_FILES: ${{ steps.filter.outputs.github_actions_files }}
107+
HTML: ${{ steps.filter.outputs.html }}
108+
HTML_FILES: ${{ steps.filter.outputs.html_files }}
99109
MARKDOWN: ${{ steps.filter.outputs.markdown }}
100110
MARKDOWN_FILES: ${{ steps.filter.outputs.markdown_files }}
101111
RUST: ${{ steps.filter.outputs.rust }}
@@ -137,6 +147,7 @@ jobs:
137147
emit_category "CSS" "${CSS}" "${CSS_FILES}"
138148
emit_category "Flutter" "${FLUTTER}" "${FLUTTER_FILES}"
139149
emit_category "GitHub Actions" "${GH_ACTIONS}" "${GH_ACTIONS_FILES}"
150+
emit_category "HTML" "${HTML}" "${HTML_FILES}"
140151
emit_category "Markdown" "${MARKDOWN}" "${MARKDOWN_FILES}"
141152
emit_category "Rust" "${RUST}" "${RUST_FILES}"
142153
emit_category "Zig" "${ZIG}" "${ZIG_FILES}"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ General-purpose workflows intended for use by any repository:
4646

4747
- `detect-changed-files.yml` – Expose paths-filter outputs for conditional jobs
4848
- `check-github-actions.yml` – Lint workflows via actionlint
49+
- `check-html.yml` – Format and lint HTML via Prettier
4950
- `check-markdown.yml` – Format and lint Markdown via Prettier
5051
- `check-shell.yml` – Format and lint shell scripts
5152
- `check-spelling.yml` – Spellcheck via typos

docs/common.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ For each filter name listed below:
4040
| `css` | CSS changes |
4141
| `flutter` | Dart / pubspec / analysis options changes |
4242
| `github_actions` | Workflow changes under `.github/workflows/` |
43+
| `html` | HTML changes |
4344
| `markdown` | Markdown changes |
4445
| `rust` | Rust / Cargo changes |
4546
| `zig` | Zig / zon changes |
@@ -78,6 +79,36 @@ Lints GitHub Actions workflow files using
7879

7980
---
8081

82+
## check-html.yml
83+
84+
Checks HTML formatting using [Prettier](https://prettier.io/).
85+
86+
**Inputs**
87+
88+
| Name | Required | Default |
89+
| ------------------ | -------- | ----------- |
90+
| `files` | false | `**/*.html` |
91+
| `prettier_version` | false | `latest` |
92+
93+
**Typical usage with changed files**
94+
95+
```yml
96+
jobs:
97+
detect_changed_files:
98+
permissions:
99+
pull-requests: read
100+
uses: EarthmanMuons/reusable-workflows/.github/workflows/detect-changed-files.yml@main
101+
102+
check_html:
103+
needs: detect_changed_files
104+
if: needs.detect_changed_files.outputs.html == 'true'
105+
uses: EarthmanMuons/reusable-workflows/.github/workflows/check-html.yml@main
106+
with:
107+
files: ${{ needs.detect_changed_files.outputs.html_files }}
108+
```
109+
110+
---
111+
81112
## check-markdown.yml
82113

83114
Checks Markdown formatting using [Prettier](https://prettier.io/).

0 commit comments

Comments
 (0)