Skip to content

Commit a21fddd

Browse files
committed
Add hygiene workflow.
1 parent f2811d2 commit a21fddd

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

.github/workflows/hygiene.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# SPDX-FileCopyrightText: Copyright 2026 Arm Limited and affiliates.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
name: Hygiene
6+
7+
on:
8+
push:
9+
branches: [main]
10+
pull_request:
11+
types: [opened, synchronize, reopened]
12+
workflow_dispatch:
13+
14+
#* Stop stale workflows when pull requests are updated: https://stackoverflow.com/a/70972844
15+
#* Does not apply to the main branch.
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
19+
20+
# Declare default permissions as read only.
21+
permissions: read-all
22+
23+
jobs:
24+
hygiene:
25+
runs-on: ah-ubuntu_24_04-c7g_2x-50
26+
steps:
27+
- name: Checkout Tool-Solutions
28+
uses: actions/checkout@v6.0.2
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Install hygiene tooling
33+
run: |
34+
python3 -m pip install --user --no-cache-dir pre-commit==4.5.1 reuse==6.2.0
35+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
36+
37+
- name: Run pre-commit on changed files
38+
env:
39+
EVENT_NAME: ${{ github.event_name }}
40+
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
41+
PUSH_BEFORE_SHA: ${{ github.event.before }}
42+
run: |
43+
set -euo pipefail
44+
45+
base_ref=""
46+
if [[ "$EVENT_NAME" == "pull_request" ]]; then
47+
base_ref="$PR_BASE_SHA"
48+
elif [[ -n "${PUSH_BEFORE_SHA:-}" && "$PUSH_BEFORE_SHA" != "0000000000000000000000000000000000000000" ]]; then
49+
base_ref="$PUSH_BEFORE_SHA"
50+
fi
51+
52+
if [[ -n "$base_ref" ]] && git cat-file -e "${base_ref}^{commit}"; then
53+
pre-commit run --from-ref "$base_ref" --to-ref HEAD
54+
else
55+
echo "No base ref available; skipping changed-file pre-commit hooks."
56+
fi
57+
58+
- name: Run whole-repo whitespace check
59+
run: pre-commit run trailing-whitespace --all-files
60+
61+
- name: Run safe whole-repo pre-commit checks
62+
run: |
63+
set -euo pipefail
64+
pre-commit run end-of-file-fixer --all-files
65+
pre-commit run mixed-line-ending --all-files
66+
pre-commit run check-merge-conflict --all-files
67+
pre-commit run check-case-conflict --all-files
68+
pre-commit run check-symlinks --all-files
69+
pre-commit run check-json --all-files
70+
pre-commit run check-yaml --all-files
71+
pre-commit run check-added-large-files --all-files
72+
pre-commit run check-executables-have-shebangs --all-files
73+
pre-commit run check-shebang-scripts-are-executable --all-files
74+
75+
- name: Run whole-repo REUSE lint
76+
run: reuse lint

0 commit comments

Comments
 (0)