Skip to content

workflows: DevEx improvements #203

workflows: DevEx improvements

workflows: DevEx improvements #203

name: Generate Dockerfiles/patches
on:
push:
branches:
- master
tags-ignore:
- '*'
pull_request:
paths:
- cpanfile
- config.yml
- generate.pl
- .github/workflows/generate-dockerfiles-patches.yml
jobs:
generate:
runs-on: ubuntu-latest
container: perl:devel
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up git user name and email
run: |
git config --global user.email "test@github-actions"
git config --global user.name "GitHub Actions"
- name: Install dependencies
run: |
cpm install -g
- name: Generate Dockerfiles/patches
id: generate
shell: bash -euo pipefail -x {0}
run: |
git config --global --add safe.directory $PWD
export DOCKER_PERL_DOWNLOADS_DIR=/tmp/docker-perl-downloads
perl ./generate.pl
/usr/bin/git --no-pager diff --stat > diffstat.txt
if [[ -s diffstat.txt ]]; then
echo has_extra_diffs=1 >> $GITHUB_OUTPUT
fi
- name: Setup NodeJS in Perl container (for comment to PR)
if: github.event_name == 'pull_request' && steps.generate.outputs.has_extra_diffs
run: |
if ! command -v node; then
curl -sL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
bash nodesource_setup.sh
apt-get install -y --no-install-recommends nodejs
npm install -g yarn
rm -fr /var/lib/apt/lists/* /var/lib/apt/cache/* nodesource_setup.sh
fi
- name: Comment diffstat of generated changes to PR (if any)
if: github.event_name == 'pull_request' && steps.generate.outputs.has_extra_diffs
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const fs = require('node:fs')
let out = fs.readFileSync('diffstat.txt', 'utf8').trim()
if (out && context.actor !== 'nektos/act') {
const output = `
#### :warning: Additional changes generated (missing in commit), see diffstat:
<details><summary>Show Output</summary>
\`\`\`diff
${ out }
\`\`\`
</details>`
github.request('POST /repos/{owner}/{repo}/statuses/{sha}', {
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: 'error',
description: 'Additional changes generated that are missing in this commit!',
context: 'continuous-integration/generate',
})
# github.rest.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: output
# })
console.log(output)
} else {
console.log(out)
}