|
1 | | -name: Hadolint |
| 1 | +name: Lint |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request: |
|
7 | 7 | paths: |
8 | 8 | - '**/Dockerfile' |
9 | 9 | - '.github/workflows/lint.yml' |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + debug_enabled: |
| 13 | + type: boolean |
| 14 | + description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' |
| 15 | + required: false |
| 16 | + default: false |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: ${{ github.head_ref }}-${{ github.workflow }} |
| 20 | + cancel-in-progress: true |
10 | 21 |
|
11 | 22 | jobs: |
12 | 23 | hadolint: |
|
16 | 27 | - uses: hadolint/[email protected] |
17 | 28 | with: |
18 | 29 | recursive: true |
| 30 | + ensure-dockerfiles-up-to-date: |
| 31 | + runs-on: ubuntu-24.04 |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + - name: Install GHC and Stack |
| 35 | + uses: haskell-actions/[email protected] |
| 36 | + with: |
| 37 | + enable-stack: true |
| 38 | + |
| 39 | + - name: "Cache .stack-work and ~/.stack" |
| 40 | + |
| 41 | + with: |
| 42 | + path: | |
| 43 | + ~/.stack |
| 44 | + **/.stack-work |
| 45 | + key: ${{ runner.os }}-stack-${{ hashFiles('**/stack.yaml') }} |
| 46 | + restore-keys: | |
| 47 | + ${{ runner.os }}-stack- |
| 48 | +
|
| 49 | + # Enable tmate debugging of manually triggered workflows if the input option was provided |
| 50 | + - name: Setup tmate session |
| 51 | + |
| 52 | + if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} |
| 53 | + |
| 54 | + - name: Build dockerfiles generator |
| 55 | + run: | |
| 56 | + pushd generator |
| 57 | + stack setup |
| 58 | + stack build --no-terminal |
| 59 | + - name: Ensure Dockerfiles are up-to-date |
| 60 | + run: | |
| 61 | + # Collect the list of Dockerfiles to be built |
| 62 | + mapfile -t dockerfiles < <(find . -type f -name 'Dockerfile' | sort) |
| 63 | + # Generate Dockerfiles using the generate.sh wrapper tool |
| 64 | + for df in "${dockerfiles[@]}"; do |
| 65 | + # Get appropriate YAML data file from the Dockerfile path |
| 66 | + df_dir=$(dirname "${df}") |
| 67 | + df_yaml="${df_dir}.yaml" |
| 68 | + if [ ! -f "${df_yaml}" ]; then |
| 69 | + echo "Error: Missing YAML data file ${df_yaml} for Dockerfile ${df}" |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | + echo "Generating ${df}" |
| 73 | + ./generate.sh "${df_yaml}" "${df}.generated" |
| 74 | + # Compare generated Dockerfile with the existing one |
| 75 | + if ! diff -u "${df}" "${df}.generated"; then |
| 76 | + echo "Error: Dockerfile ${df} is out of date. Please regenerate it." |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | + done |
0 commit comments