Skip to content

Commit bc3fa72

Browse files
committed
workflows: improve generate dockerfile workflow
- Run under perl:devel container - Run only for changes on selected paths - Install prereqs via cpm - Report possible uncommitted changes back to PR
1 parent 378aed9 commit bc3fa72

File tree

1 file changed

+73
-12
lines changed

1 file changed

+73
-12
lines changed

.github/workflows/generate-dockerfiles-patches.yml

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,93 @@ name: Generate Dockerfiles/patches
33
on:
44
push:
55
branches:
6-
- '**'
6+
- master
77
tags-ignore:
88
- '*'
99
pull_request:
10+
paths:
11+
- cpanfile
12+
- config.yml
13+
- generate.pl
14+
- .github/workflows/generate-dockerfiles-patches.yml
1015

1116
jobs:
1217
generate:
1318
runs-on: ubuntu-latest
19+
container: perl:devel
20+
permissions:
21+
contents: read
22+
pull-requests: write
23+
1424
steps:
25+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
26+
1527
- name: Set up git user name and email
1628
run: |
1729
git config --global user.email "test@github-actions"
1830
git config --global user.name "GitHub Actions"
19-
- uses: actions/checkout@master
20-
- name: Install system perl and cpanm
21-
run: |
22-
sudo apt-get install --no-install-recommends -y perl cpanminus
31+
2332
- name: Install dependencies
2433
run: |
25-
cpanm --quiet --installdeps --notest -L local .
34+
cpm install -g
35+
2636
- name: Generate Dockerfiles/patches
37+
id: generate
38+
shell: bash {0}
2739
run: |
28-
perl -Ilocal/lib/perl5 ./generate.pl
29-
- name: Show diffstat (if any)
30-
run: |
31-
git --no-pager diff --stat HEAD
32-
- name: Show diffstat (if any)
40+
export DOCKER_PERL_DOWNLOADS_DIR=/tmp/docker-perl-downloads
41+
perl ./generate.pl
42+
ls -l $PWD/.git
43+
if [[ $(git --no-pager diff --stat) != '' ]]; then
44+
echo has_extra_diffs=1 >> $GITHUB_OUTPUT
45+
fi
46+
47+
- name: Setup NodeJS in Perl container (for comment to PR)
48+
if: github.event_name == 'pull_request' && steps.generate.outputs.has_extra_diffs
3349
run: |
34-
git --no-pager diff --stat HEAD
50+
if ! command -v node; then
51+
curl -sL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
52+
bash nodesource_setup.sh
53+
apt-get install -y --no-install-recommends nodejs
54+
npm install -g yarn
55+
rm -fr /var/lib/apt/lists/* /var/lib/apt/cache/* nodesource_setup.sh
56+
fi
57+
58+
- name: Comment diffstat of generated changes to PR (if any)
59+
if: github.event_name == 'pull_request' && steps.generate.outputs.has_extra_diffs
60+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
61+
with:
62+
script: |
63+
let out = ''
64+
let err = ''
65+
66+
const options = {}
67+
options.listeners = {
68+
stdout: (data) => {
69+
out += data.toString()
70+
},
71+
stderr: (data) => {
72+
err += data.toString()
73+
}
74+
}
75+
76+
await exec.exec('git', ['--no-pager', 'diff', '--stat'], options)
77+
78+
if (out && context.actor !== 'nektos/act') {
79+
const output = `
80+
#### :warning: Additional changes generated (missing in commit), see diffstat:
81+
<details><summary>Show Output</summary>
82+
83+
\`\`\`diff
84+
${ out.trim() }
85+
\`\`\`
86+
</details>`
87+
88+
github.rest.issues.createComment({
89+
issue_number: context.issue.number,
90+
owner: context.repo.owner,
91+
repo: context.repo.repo,
92+
body: output
93+
})
94+
}
95+

0 commit comments

Comments
 (0)