-
-
Notifications
You must be signed in to change notification settings - Fork 13
186 lines (161 loc) · 4.6 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: Build & Publish
on:
push:
branches:
- main
schedule:
# This is here to ensure that the calendar shows the correct next event
- cron: 1 0 * * *
pull_request: {}
jobs:
build:
env:
# ruby/setup-ruby@v1 does not offer a way to change the cached gems path.
# See https://github.com/ruby/setup-ruby/issues/291
GLOBAL_GEMS: 1
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
cache-version: 2
- name: Build & Validate
run: rake validate
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
changes:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
outputs:
build-system: ${{ steps.filter.outputs.build-system }}
steps:
- name: Check if build system changed
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
build-system:
- _config.yml
- .github/**/*
- Gemfile*
- Rakefile
build-main:
needs:
- changes
if: needs.changes.outputs.build-system == 'true'
env:
# ruby/setup-ruby@v1 does not offer a way to change the cached gems path.
# See https://github.com/ruby/setup-ruby/issues/291
GLOBAL_GEMS: 1
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
submodules: recursive
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
cache-version: 2
- name: Build
run: rake build
- name: Upload build site
uses: actions/upload-artifact@v4
with:
name: build-from-main
path: _site
diff:
runs-on: ubuntu-latest
needs:
- build
- build-main
permissions:
pull-requests: write
steps:
- name: Download artifact from this branch's build
uses: actions/download-artifact@v4
with:
name: github-pages
- name: Unpack local build
run: |
mkdir local
pushd local
tar --extract --file ../artifact.tar
popd
mv artifact.tar local.tar
- name: Download artifact from main branch build
uses: actions/download-artifact@v4
with:
name: build-from-main
path: main
- name: Replace build timestamps
run: sed -i -r '1 s_<updated>[^/]+</updated>_<updated>NOW</updated>_' {main,local}/feed.xml
- name: Diff
id: diff
run: |
set +e
diff -ru main local > ./result.diff
result=$?
set -euo pipefail
delimiter="gha-delim-$RANDOM-$RANDOM-gha-delim"
{
echo "diff<<${delimiter}"
cat ./result.diff
echo "${delimiter}"
} >> "$GITHUB_OUTPUT"
cat ./result.diff
if [[ $result -ne 0 ]]
then
echo has-changes=true >> "$GITHUB_OUTPUT"
else
echo has-changes=false >> "$GITHUB_OUTPUT"
fi
- name: Build comment
id: build-comment
if: always()
run: |
{
if [[ "${{ steps.diff.outputs.has-changes }}" = "true" ]]
then
echo "🔀 Build diff:"
echo '```diff'
cat ./result.diff
echo '```'
else
echo "Build has no changes."
fi
} > ./comment.md
- name: Post diff to PR
uses: thollander/actions-comment-pull-request@v2
if: always()
with:
comment_tag: build-diff
filePath: ./comment.md
deploy:
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
needs: build
if: ${{ github.ref == 'refs/heads/main' }}
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
environment:
name: github-pages
# Tell GitHub where we deployed to
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4