feat: add hadolint #5
Workflow file for this run
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
name: Lint Dockerfile | |
on: | |
workflow_dispatch: | |
pull_request: | |
push: | |
paths: | |
- "Dockerfile.template" | |
jobs: | |
lint: | |
name: 'Lint Dockerfile (PHP: ${{ matrix.php-version }})' | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
php-version: | |
- '8.0' | |
- '8.1' | |
- '8.2' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Lint Dockerfile | |
id: hadolint | |
uses: hadolint/hadolint-action@master | |
with: | |
dockerfile: ./${{ matrix.php-version }}/Dockerfile | |
- name: Save hadolint results to artifact | |
if: failure() | |
run: echo "${{ steps.hadolint.outcome }}" > hadolint-${{ matrix.php-version }}.txt | |
- name: Upload artifact | |
if: failure() | |
uses: actions/upload-artifact@v2 | |
with: | |
name: hadolint-results | |
path: hadolint-${{ matrix.php-version }}.txt | |
comment: | |
needs: lint | |
if: always() | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download all artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
path: artifacts | |
- name: Combine outputs and create comment | |
if: github.event_name == 'pull_request' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
const path = require('path'); | |
const resultsDir = './artifacts/hadolint-results'; | |
const files = fs.readdirSync(resultsDir); | |
let combinedOutput = '#### Hadolint Results:\n\n'; | |
for (const file of files) { | |
const content = fs.readFileSync(path.join(resultsDir, file), 'utf8'); | |
combinedOutput += `PHP Version: ${file.replace('hadolint-', '').replace('.txt', '')}:\n`; | |
combinedOutput += '```\n' + content + '\n```\n'; | |
} | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: combinedOutput | |
}) |