Skip to content

Commit

Permalink
ci: Check consistency of generated files
Browse files Browse the repository at this point in the history
This makes the .github/workflows/check-sourcecode
more a "check-repo" than a "check-sourcecode".
  • Loading branch information
ndim committed Nov 23, 2024
1 parent eddb0d0 commit f85a584
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/check-sourcecode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,21 @@ jobs:

- name: "Check the sourcecode"
run: ./tools/check-sourcecode

check-generated:
name: "Check Generated Files"
runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v4

- name: Install prerequisites
run: >-
sudo apt-get update
sudo apt-get install -y
asciidoctor
- name: "Verify elf2tag.1 consistency"
run: ./src/update-elf2tag-manpage --verify
33 changes: 29 additions & 4 deletions src/update-elf2tag-manpage
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@
#
# Usage:
# ./path/to/update-elf2tag-manpage
# ./path/to/update-elf2tag-manpage --verify
#
# Changes into the directory where update-elf2tag-manpage and
# elf2tag.1.adoc are, runs asciidoctor to produce a man page elf2tag.1
# from elf2tag.1.adoc, but only updates the elf2tag.1 file in the case
# of actual changes.
# Without a command line argument given, changes into the directory
# where update-elf2tag-manpage and elf2tag.1.adoc are, runs
# asciidoctor to produce a man page elf2tag.1 from elf2tag.1.adoc, but
# only updates the elf2tag.1 file in the case of actual changes.
#
# Just the asciidoctor version or the current date being different
# from the last asciidoctor run is not considered an actual change.
#
# With the --verify argument given, only verify that elf2tag.1 and
# elf2tag.1.adoc are consistent with each other, i.e. elf2tag.1 would
# not be changed.
#
# Requires asciidoctor to be installed.
#
# Environment variables used (if unset, uses the command from PATH):
# ASCIIDOCTOR the asciidoctor command to run
# CMP the cmp command to run (e.g. "busybox cmp")
# DIFF the diff command to run with -u (used with --verify only)
# SED the sed command to run (e.g. "busybox sed")

# This script uses the shell feature called "process substitution" which
Expand All @@ -33,6 +39,7 @@ if test "$#" -gt 1; then
exit 2
fi

verify=false
if test "$#" -eq 1; then
case "$1" in
-h | --help )
Expand All @@ -42,6 +49,9 @@ if test "$#" -eq 1; then
| ${SED-sed} 's|^#$||; s|^# ||'
exit 0
;;
--verify )
verify=:
;;
* )
echo "$prog: Unhandled command line argument."
exit 2
Expand Down Expand Up @@ -89,6 +99,11 @@ else
fi

if ! test -e elf2tag.1; then
if "$verify"; then
echo "$prog: Cannot ensure consistency if there is no old elf2tag.1 file"
rm -rf "$tmpdir"
exit 1
fi
echo "$prog: Generate elf2tag.1"
mv -f "$tmpdir/elf2tag.1" elf2tag.1
rmdir "$tmpdir"
Expand All @@ -107,6 +122,16 @@ if ${CMP-cmp} "$tmpdir/elf2tag.1.norm-old" "$tmpdir/elf2tag.1.norm-new" > /dev/n
exit 0
fi

if "$verify"; then
echo "$prog: Error: src/elf2tag.1 is inconsistent with src/elf2tag.1.adoc"
${DIFF-diff} -u "$tmpdir/elf2tag.1.norm-old" "$tmpdir/elf2tag.1.norm-new" ||:
rm -f "$tmpdir/elf2tag.1"
rm -f "$tmpdir/elf2tag.1.norm-old"
rm -f "$tmpdir/elf2tag.1.norm-new"
rmdir "$tmpdir"
exit 1
fi

echo "Updating elf2tag.1"
mv -f "$tmpdir/elf2tag.1" elf2tag.1
rm -f "$tmpdir/elf2tag.1.norm-old"
Expand Down

0 comments on commit f85a584

Please sign in to comment.