-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cce6a4
commit a9e52dc
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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 | ||
}) |