Skip to content

Commit bcfe95b

Browse files
committed
feat: ensure Dockerfiles being up-to-date
1 parent 151e400 commit bcfe95b

File tree

3 files changed

+68
-6
lines changed

3 files changed

+68
-6
lines changed

.github/workflows/generator.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
paths:
55
- generator
6+
- .github/workflows/generator.yml
67
workflow_dispatch:
78
inputs:
89
debug_mode:
@@ -56,4 +57,4 @@ jobs:
5657
prerelease: true
5758
overwrite_files: 'true'
5859
files: |
59-
artifacts/generator
60+
artifacts/generator

.github/workflows/lint.yml

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Hadolint
1+
name: Lint
22

33
on:
44
pull_request:
@@ -8,6 +8,10 @@ on:
88
- '**/Dockerfile'
99
- '.github/workflows/lint.yml'
1010

11+
concurrency:
12+
group: ${{ github.head_ref }}-${{ github.workflow }}
13+
cancel-in-progress: true
14+
1115
jobs:
1216
hadolint:
1317
runs-on: ubuntu-24.04
@@ -16,3 +20,56 @@ jobs:
1620
- uses: hadolint/[email protected]
1721
with:
1822
recursive: true
23+
ensure-dockerfiles-up-to-date:
24+
runs-on: ubuntu-24.04
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Install GHC and Stack
28+
uses: haskell-actions/[email protected]
29+
with:
30+
enable-stack: true
31+
32+
- name: Cache ~/.stack
33+
uses: actions/[email protected]
34+
with:
35+
path: ~/.stack
36+
key: ${{ runner.os }}-stack-home-${{ hashFiles('**/stack.yaml') }}
37+
restore-keys: |
38+
${{ runner.os }}-stack-home-
39+
- name: "Cache generator binaries at generator/.stack-work"
40+
uses: actions/[email protected]
41+
with:
42+
path: |
43+
generator/.stack-work
44+
key: ${{ runner.os }}-stack-${{ hashFiles('**/stack.yaml') }}
45+
restore-keys: |
46+
${{ runner.os }}-stack-
47+
48+
- name: Download generator-binary release
49+
run: |
50+
gh release download generator-binary --repo haskell/docker-haskell --pattern 'generator' --dir artifacts
51+
chmod +x artifacts/generator
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Ensure Dockerfiles are up-to-date
56+
run: |
57+
# Collect the list of Dockerfiles to be built
58+
mapfile -t dockerfiles < <(find . -type f -name 'Dockerfile' | sort)
59+
# Generate Dockerfiles using the generate.sh wrapper tool
60+
for df in "${dockerfiles[@]}"; do
61+
# Get appropriate YAML data file from the Dockerfile path
62+
df_dir=$(dirname "${df}")
63+
df_yaml="${df_dir}.yaml"
64+
if [ ! -f "${df_yaml}" ]; then
65+
echo "Error: Missing YAML data file ${df_yaml} for Dockerfile ${df}"
66+
else
67+
echo "Generating ${df}"
68+
./generate.sh "${df_yaml}" "${df}.generated"
69+
# Compare generated Dockerfile with the existing one
70+
if ! diff -u "${df}" "${df}.generated"; then
71+
echo "Error: Dockerfile ${df} is out of date. Please regenerate it."
72+
exit 1
73+
fi
74+
fi
75+
done

generate.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ main() {
1616
abs_output_file=$(realpath "$2")
1717
local template_path
1818
template_path=$(realpath ./template/Dockerfile.jinja)
19-
# run the generator
20-
pushd generator || exit 1
21-
stack run -- -t "$template_path" --data-file "$abs_data_file" > "$abs_output_file"
22-
popd || exit 1
19+
if [ "$CI" == "true" ] && [ "$GITHUB_ACTIONS" == "true" ]; then
20+
./artifacts/generator -t "$template_path" --data-file "$abs_data_file" > "$abs_output_file"
21+
else
22+
# run the generator
23+
pushd generator || exit 1
24+
stack run -- -t "$template_path" --data-file "$abs_data_file" > "$abs_output_file"
25+
popd || exit 1
26+
fi
2327
}
2428
main "$@"

0 commit comments

Comments
 (0)