From a9e52dc2e85e1f9a15b2164efd61bc37f2a9002f Mon Sep 17 00:00:00 2001 From: Stefan Poensgen Date: Sun, 24 Sep 2023 20:34:03 +0200 Subject: [PATCH] feat: add hadolint --- .github/workflows/lint.yml | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..664c099 --- /dev/null +++ b/.github/workflows/lint.yml @@ -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 + })