-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from cevich/imgsfx_history
[CI:DOCS] Add pre-commit (app) hook to check IMGSFX
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
|
||
# Ref: https://pre-commit.com/#creating-new-hooks | ||
- id: check-imgsfx | ||
name: Check IMG_SFX for accidental reuse. | ||
description: | | ||
Every PR intended to produce CI VM or container images must update | ||
the `IMG_SFX` file via `make IMG_SFX`. The exact value will be | ||
validated against global suffix usage (encoded as tags on the | ||
`imgts` container image). This pre-commit hook verifies on every | ||
push, the IMG_SFX file's value has not been pushed previously. | ||
It's intended as a simple/imperfect way to save developers time | ||
by avoiding force-pushes that will most certainly fail validation. | ||
entry: ./check-imgsfx.sh | ||
language: system | ||
exclude: '.*' # Not examining any specific file/dir/link | ||
always_run: true # ignore no matching files | ||
fail_fast: true | ||
pass_filenames: false | ||
stages: ["pre-push"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
# | ||
# 2024-01-25 esm | ||
# 2024-06-28 cevich | ||
# | ||
# This script is intended to be used by the `pre-commit` utility, or it may | ||
# be manually copied (or symlinked) as local `.git/hooks/pre-push` file. | ||
# It's purpose is to keep track of image-suffix values which have already | ||
# been pushed, to avoid them being immediately rejected by CI validation. | ||
# To use it with the `pre-commit` utility, simply add something like this | ||
# to your `.pre-commit-config.yaml`: | ||
# | ||
# --- | ||
# repos: | ||
# - repo: https://github.com/containers/automation_images.git | ||
# rev: <tag or commit sha> | ||
# hooks: | ||
# - id: check-imgsfx | ||
|
||
set -eo pipefail | ||
|
||
# Ensure CWD is the repo root | ||
cd $(dirname "${BASH_SOURCE[0]}") | ||
imgsfx=$(<IMG_SFX) | ||
|
||
imgsfx_history=".git/hooks/imgsfx.history" | ||
|
||
if [[ -e $imgsfx_history ]]; then | ||
if grep -q "$imgsfx" $imgsfx_history; then | ||
echo "FATAL: $imgsfx has already been used" >&2 | ||
echo "Please rerun 'make IMG_SFX'" >&2 | ||
exit 1 | ||
fi | ||
fi | ||
|
||
echo $imgsfx >>$imgsfx_history |