Skip to content

feat: ensure Dockerfiles being up-to-date #238

feat: ensure Dockerfiles being up-to-date

feat: ensure Dockerfiles being up-to-date #238

Workflow file for this run

name: Lint
on:
pull_request:
branches:
- master
paths:
- '**/Dockerfile'
- '.github/workflows/lint.yml'
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: false
concurrency:
group: ${{ github.head_ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
hadolint:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: hadolint/hadolint-action@v3.1.0
with:
recursive: true
ensure-dockerfiles-up-to-date:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Install GHC and Stack
uses: haskell-actions/setup@v2.8.2
with:
enable-stack: true
- name: "Cache .stack-work and ~/.stack"
uses: actions/cache@v4.3.0
with:
path: |
~/.stack
**/.stack-work
key: ${{ runner.os }}-stack-${{ hashFiles('**/stack.yaml') }}
restore-keys: |
${{ runner.os }}-stack-
# Enable tmate debugging of manually triggered workflows if the input option was provided
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3.22
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- name: Build dockerfiles generator
run: |
pushd generator
stack setup
stack build --no-terminal
- name: Ensure Dockerfiles are up-to-date
run: |
# Collect the list of Dockerfiles to be built
mapfile -t dockerfiles < <(find . -type f -name 'Dockerfile' | sort)
# Generate Dockerfiles using the generate.sh wrapper tool
for df in "${dockerfiles[@]}"; do
# Get appropriate YAML data file from the Dockerfile path
df_dir=$(dirname "${df}")
df_yaml="${df_dir}.yaml"
if [ ! -f "${df_yaml}" ]; then
echo "Error: Missing YAML data file ${df_yaml} for Dockerfile ${df}"
exit 1
fi
echo "Generating ${df}"
./generate.sh "${df_yaml}" "${df}.generated"
# Compare generated Dockerfile with the existing one
if ! diff -u "${df}" "${df}.generated"; then
echo "Error: Dockerfile ${df} is out of date. Please regenerate it."
exit 1
fi
done