Skip to content

Commit d6662e3

Browse files
committed
Add support for PR diff comments vs the deployed version
This is copied over from the website repo, which now has these in place. See srobo/website#570 & srobo/website#573.
1 parent 7302bca commit d6662e3

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

.github/workflows/publish.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,130 @@ jobs:
4141
- name: Build site in container
4242
run: docker-compose run docs rake build
4343

44+
changes:
45+
runs-on: ubuntu-latest
46+
if: github.ref != 'refs/heads/main'
47+
outputs:
48+
build-system: ${{ steps.filter.outputs.build-system }}
49+
steps:
50+
- name: Check if build system changed
51+
uses: dorny/paths-filter@v3
52+
id: filter
53+
with:
54+
filters: |
55+
build-system:
56+
- _config.yml
57+
- .github/**/*
58+
- Gemfile*
59+
- Rakefile
60+
61+
build-main:
62+
needs:
63+
- changes
64+
if: needs.changes.outputs.build-system == 'true'
65+
env:
66+
# ruby/setup-ruby@v1 does not offer a way to change the cached gems path.
67+
# See https://github.com/ruby/setup-ruby/issues/291
68+
GLOBAL_GEMS: 1
69+
runs-on: ubuntu-latest
70+
steps:
71+
- uses: actions/checkout@v4
72+
with:
73+
ref: main
74+
submodules: recursive
75+
76+
- name: Set up Ruby
77+
uses: ruby/setup-ruby@v1
78+
with:
79+
bundler-cache: true
80+
cache-version: 2
81+
82+
- name: Build
83+
run: rake build
84+
85+
- name: Upload build site
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: build-from-main
89+
path: _site
90+
91+
diff:
92+
runs-on: ubuntu-latest
93+
needs:
94+
- build-validate
95+
- build-main
96+
permissions:
97+
pull-requests: write
98+
steps:
99+
- name: Download artifact from this branch's build
100+
uses: actions/download-artifact@v4
101+
with:
102+
name: github-pages
103+
104+
- name: Unpack local build
105+
run: |
106+
mkdir local
107+
pushd local
108+
tar --extract --file ../artifact.tar
109+
popd
110+
mv artifact.tar local.tar
111+
112+
- name: Download artifact from main branch build
113+
uses: actions/download-artifact@v4
114+
with:
115+
name: build-from-main
116+
path: main
117+
118+
- name: Replace build timestamps
119+
run: sed -i -r '1 s_<updated>[^/]+</updated>_<updated>NOW</updated>_' {main,local}/feed.xml
120+
121+
- name: Diff
122+
id: diff
123+
run: |
124+
set +e
125+
diff -ru main local > ./result.diff
126+
result=$?
127+
set -euo pipefail
128+
129+
delimiter="gha-delim-$RANDOM-$RANDOM-gha-delim"
130+
{
131+
echo "diff<<${delimiter}"
132+
cat ./result.diff
133+
echo "${delimiter}"
134+
} >> "$GITHUB_OUTPUT"
135+
136+
cat ./result.diff
137+
138+
if [[ $result -ne 0 ]]
139+
then
140+
echo has-changes=true >> "$GITHUB_OUTPUT"
141+
else
142+
echo has-changes=false >> "$GITHUB_OUTPUT"
143+
fi
144+
145+
- name: Build comment
146+
id: build-comment
147+
if: always()
148+
run: |
149+
{
150+
if [[ "${{ steps.diff.outputs.has-changes }}" = "true" ]]
151+
then
152+
echo "🔀 Build diff:"
153+
echo '```diff'
154+
cat ./result.diff
155+
echo '```'
156+
else
157+
echo "Build has no changes."
158+
fi
159+
} > ./comment.md
160+
161+
- name: Post diff to PR
162+
uses: thollander/actions-comment-pull-request@v2
163+
if: always()
164+
with:
165+
comment_tag: build-diff
166+
filePath: ./comment.md
167+
44168
deploy:
45169
name: Deploy to GitHub Pages
46170
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)