Skip to content

Commit 7cc203c

Browse files
authored
Merge pull request #364 from ianlewis/288-feature-create-format-check-makefile-target
chore: add format-check make target
2 parents 70ecbf6 + c89b897 commit 7cc203c

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

.github/workflows/pull_request.tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ permissions:
3131
# just a human-readable label.
3232

3333
jobs:
34-
# formatting
34+
# format-check
3535
###############################
36-
formatting:
37-
uses: ./.github/workflows/workflow_call.formatting.yml
36+
format-check:
37+
uses: ./.github/workflows/workflow_call.format-check.yml
3838

3939
# linters
4040
###############################

.github/workflows/workflow_call.formatting.yml renamed to .github/workflows/workflow_call.format-check.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
name: formatting
15+
name: format-check
1616

1717
on:
1818
workflow_call:
@@ -22,7 +22,7 @@ permissions:
2222

2323
jobs:
2424
formatting:
25-
name: formatting
25+
name: format-check
2626
runs-on: ubuntu-latest
2727
steps:
2828
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
@@ -34,21 +34,10 @@ jobs:
3434
with:
3535
node-version-file: ".node-version"
3636

37-
# TODO(github.com/ianlewis/repo-template/issues/288): Use make format-check target.
38-
- name: format
37+
- name: format-check
3938
env:
4039
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4140
run: |
41+
# Set the git user for the license-headers target.
4242
git config user.name "Unknown"
43-
make format
44-
45-
- name: check diff
46-
run: |
47-
set -euo pipefail
48-
if [ "$(GIT_PAGER="cat" git diff --ignore-space-at-eol | wc -l)" -gt "0" ]; then
49-
echo "Detected formatting changes. See status below:"
50-
echo "::group::git diff"
51-
GIT_PAGER="cat" git diff
52-
echo "::endgroup::"
53-
exit 1
54-
fi
43+
make format-check

Makefile

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,17 @@ $(AQUA_ROOT_DIR)/.installed: .aqua.yaml .bin/aqua-$(AQUA_VERSION)/aqua
157157

158158
# TODO: Add all target dependencies.
159159
.PHONY: all
160-
all: ## Build everything.
160+
all: test ## Build everything.
161161
@# bash \
162162
echo "Nothing to build."
163+
exit 1
163164

164165
## Testing
165166
#####################################################################
166167

167168
# TODO: Add test target dependencies.
168169
.PHONY: test
169-
test: ## Run all tests.
170-
@# bash \
171-
echo "Nothing to test."
170+
test: lint ## Run all tests.
172171

173172
## Formatting
174173
#####################################################################
@@ -285,7 +284,7 @@ yaml-format: node_modules/.installed ## Format YAML files.
285284
#####################################################################
286285

287286
.PHONY: lint
288-
lint: actionlint checkmake commitlint fixme markdownlint renovate-config-validator textlint yamllint zizmor ## Run all linters.
287+
lint: actionlint checkmake commitlint fixme format-check markdownlint renovate-config-validator textlint yamllint zizmor ## Run all linters.
289288

290289
.PHONY: actionlint
291290
actionlint: $(AQUA_ROOT_DIR)/.installed ## Runs the actionlint linter.
@@ -380,6 +379,23 @@ fixme: $(AQUA_ROOT_DIR)/.installed ## Check for outstanding FIXMEs.
380379
--output "$${output}" \
381380
--todo-types="FIXME,Fixme,fixme,BUG,Bug,bug,XXX,COMBAK"
382381

382+
.PHONY: format-check
383+
format-check: ## Check that files are properly formatted.
384+
@# bash \
385+
if [ -n "$$(git diff)" ]; then \
386+
>&2 echo "The working directory is dirty. Please commit, stage, or stash changes and try again."; \
387+
exit 1; \
388+
fi; \
389+
make format; \
390+
exit_code=0; \
391+
if [ -n "$$(git diff)" ]; then \
392+
>&2 echo "Some files need to be formatted. Please run 'make format' and try again."; \
393+
git --no-pager diff; \
394+
exit_code=1; \
395+
fi; \
396+
git restore .; \
397+
exit "$${exit_code}"
398+
383399
.PHONY: markdownlint
384400
markdownlint: node_modules/.installed $(AQUA_ROOT_DIR)/.installed ## Runs the markdownlint linter.
385401
@# bash \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ to achieve the highest Tier and score as possible.
247247
- [ ] `actionlint / actionlint`
248248
- [ ] `checkmake / checkmake`
249249
- [ ] `commitlint / commitlint`
250-
- [ ] `formatting / formatting`
250+
- [ ] `format-check / format-check`
251251
- [ ] `markdownlint / markdownlint`
252252
- [ ] `renovate-config-validator / renovate-config-validator`
253253
- [ ] `textlint / textlint`

0 commit comments

Comments
 (0)