Skip to content

Commit 31a2dfa

Browse files
authored
[ci] Integrate action-validator into CI and pre-push hooks (#2811)
Integrate the `action-validator` tool into our CI pipeline and pre-push hooks. This tool validates GitHub Actions workflow files to ensure they are syntactically correct and follow best practices. This change adds a new script, `ci/check_actions.sh`, which runs `action-validator` on all YAML files in `.github/`. It also updates the pre-push hook to run this check. Includes a fix for path matching in the exclusion list, ensuring that excluded files are correctly identified by prefixing them with `./`.
1 parent 738e3f2 commit 31a2dfa

File tree

3 files changed

+74
-7
lines changed

3 files changed

+74
-7
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,19 @@ jobs:
689689
690690
./ci/check_fmt.sh
691691
692+
check_actions:
693+
needs: generate_cache
694+
runs-on: ubuntu-latest
695+
name: Check GitHub Actions
696+
steps:
697+
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
698+
699+
- name: Populate cache
700+
uses: ./.github/actions/cache
701+
702+
- name: Check Actions
703+
run: ./ci/check_actions.sh
704+
692705
check_readme:
693706
needs: generate_cache
694707
runs-on: ubuntu-latest
@@ -769,12 +782,13 @@ jobs:
769782
# maybe remove it.
770783
cargo add -p zerocopy-derive 'syn@=2.0.46' &> /dev/null
771784
772-
cargo check --workspace --tests &> /dev/null &
773-
cargo metadata &> /dev/null &
774-
cargo install cargo-readme --version 3.2.0 &> /dev/null &
775-
cargo install --locked kani-verifier &> /dev/null &
776-
cargo install cargo-nextest &> /dev/null &
777-
cargo kani setup &> /dev/null &
785+
cargo check --workspace --tests &> /dev/null &
786+
cargo metadata &> /dev/null &
787+
cargo install cargo-readme --version 3.2.0 &> /dev/null &
788+
cargo install --locked action-validator --version 0.8.0 &> /dev/null &
789+
cargo install --locked kani-verifier &> /dev/null &
790+
cargo install cargo-nextest &> /dev/null &
791+
cargo kani setup &> /dev/null &
778792
779793
wait
780794
@@ -846,7 +860,7 @@ jobs:
846860
# https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks
847861
if: failure()
848862
runs-on: ubuntu-latest
849-
needs: [build_test, kani, check_be_aarch64, check_avr_artmega, check_fmt, check_readme, check_versions, check_msrv_is_minimal, generate_cache, check-all-toolchains-tested, check-job-dependencies, check-todo, run-git-hooks]
863+
needs: [build_test, kani, check_be_aarch64, check_avr_artmega, check_fmt, check_actions, check_readme, check_versions, check_msrv_is_minimal, generate_cache, check-all-toolchains-tested, check-job-dependencies, check-todo, run-git-hooks]
850864
steps:
851865
- name: Mark the job as failed
852866
run: exit 1

ci/check_actions.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2025 The Fuchsia Authors
4+
#
5+
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
6+
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
7+
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
8+
# This file may not be copied, modified, or distributed except according to
9+
# those terms.
10+
11+
set -eo pipefail
12+
13+
script_name="ci/check_actions.sh"
14+
15+
# Ensure action-validator is installed
16+
if [ ! -x "$HOME/.cargo/bin/action-validator" ]; then
17+
echo "$script_name: action-validator not found, installing..." >&2
18+
# Install specific version to ensure reproducibility
19+
cargo install -q action-validator --version 0.8.0 --locked
20+
fi
21+
export PATH="$HOME/.cargo/bin:$PATH"
22+
23+
# Files to exclude from validation (e.g., because they are not Actions/Workflows)
24+
# Use relative paths matching `find .github` output
25+
EXCLUDE_FILES=(
26+
"./.github/dependabot.yml"
27+
"./.github/release.yml"
28+
)
29+
30+
failed=0
31+
32+
# Use process substitution and while loop to handle filenames with spaces robustly
33+
while IFS= read -r -d '' file; do
34+
# Check if file is in exclusion list
35+
for exclude in "${EXCLUDE_FILES[@]}"; do
36+
if [[ "$file" == "$exclude" ]]; then
37+
continue 2
38+
fi
39+
done
40+
41+
if ! output=$(action-validator "$file" 2>&1); then
42+
echo "$script_name: ❌ Validation failed for $file" >&2
43+
echo "$output" | sed "s|^|$script_name: |" >&2
44+
failed=1
45+
fi
46+
done < <(find ./.github -type f \( -iname '*.yml' -o -iname '*.yaml' \) -print0)
47+
48+
if [[ $failed -ne 0 ]]; then
49+
echo "$script_name: One or more files failed validation." >&2
50+
exit 1
51+
fi

githooks/pre-push

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ echo "Running pre-push git hook: $0"
1414
# `cargo fmt` is useful (and the good stuff is not delivered by stderr).
1515
#
1616
# Background all jobs and wait for them so they can run in parallel.
17+
./ci/check_actions.sh & ACTIONS_PID=$!
1718
./ci/check_fmt.sh & FMT_PID=$!
1819
./ci/check_all_toolchains_tested.sh >/dev/null & TOOLCHAINS_PID=$!
1920
./ci/check_job_dependencies.sh >/dev/null & JOB_DEPS_PID=$!
@@ -28,6 +29,7 @@ echo "Running pre-push git hook: $0"
2829
# Note that, while `wait` (with no PID argument) waits for all backgrounded
2930
# jobs, it exits with code 0 even if one of the backgrounded jobs does not, so
3031
# we can't use it here.
32+
wait $ACTIONS_PID
3133
wait $FMT_PID
3234
wait $TOOLCHAINS_PID
3335
wait $JOB_DEPS_PID

0 commit comments

Comments
 (0)