-
Notifications
You must be signed in to change notification settings - Fork 53
275 lines (266 loc) · 9.4 KB
/
super_diff.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
name: SuperDiff
on:
push:
branches:
- main
- ci-*
pull_request:
types:
- opened
- closed
- reopened
- synchronize
concurrency:
group: build-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
analyze:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || github.event.action != 'closed' }}
steps:
- uses: actions/checkout@v4
- name: Download actionlint
id: download-actionlint
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/7fdc9630cc360ea1a469eed64ac6d78caeda1234/scripts/download-actionlint.bash) 1.6.23
shell: bash
- name: Check workflow files
run: ${{ steps.download-actionlint.outputs.executable }} -color
shell: bash
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
- name: Install Yarn dependencies
run: yarn --immutable
- name: Lint
run: yarn lint
- name: Audit
run: yarn audit
test:
needs:
- analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby:
- "3.0"
- "3.1"
- "3.2"
- "3.3"
rails_appraisal:
- rails_6_1
- rails_7_0
- no_rails
rspec_appraisal:
- rspec_lt_3_10
- rspec_gte_3_10
env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.rails_appraisal }}_${{ matrix.rspec_appraisal }}.gemfile
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Install Zeus
run: gem install zeus
- name: Start Zeus
uses: JarvusInnovations/background-action@v1
with:
run: zeus start
wait-on: |
socket:.zeus.sock
file:.zeus.sock
wait-for: 15s
log-output-if: failure
- name: Run tests
run: bundle exec rake --trace
ready-to-merge:
runs-on: ubuntu-latest
needs:
- analyze
- test
steps:
- run: echo "Analysis and tests passed. Ready to merge."
collect-release-info:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Run command
id: command
run: scripts/collect-release-info.rb
outputs:
IS_NEW_RELEASE: ${{ steps.command.outputs.IS_NEW_RELEASE }}
RELEASE_VERSION: ${{ steps.command.outputs.RELEASE_VERSION }}
collect-docsite-release-info:
runs-on: ubuntu-latest
needs:
- collect-release-info
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run command
id: command
run: |
set -x
if [[ "$GITHUB_EVENT_NAME" == "push" && "$GITHUB_REF_NAME" == "main" && "$IS_NEW_RELEASE" == "true" ]]; then
DOCSITE_RELEASE_VERSION="$RELEASE_VERSION"
DOCSITE_DESTINATION_PATH="releases/$RELEASE_VERSION"
HAS_DOCS_CHANGES_TO_RELEASE="true"
else
DOCSITE_RELEASE_VERSION="$COMMIT_ID"
DOCSITE_DESTINATION_PATH="branches/$BRANCH_NAME/$COMMIT_ID"
# Check if there any changes to docs/
if git diff --quiet --merge-base "origin/$GITHUB_BASE_REF" -- docs; then
HAS_DOCS_CHANGES_TO_RELEASE="false"
else
HAS_DOCS_CHANGES_TO_RELEASE="true"
fi
fi
{
echo "DOCSITE_RELEASE_VERSION=$DOCSITE_RELEASE_VERSION"
echo "DOCSITE_DESTINATION_PATH=$DOCSITE_DESTINATION_PATH"
echo "HAS_DOCS_CHANGES_TO_RELEASE=$HAS_DOCS_CHANGES_TO_RELEASE"
} >> "$GITHUB_OUTPUT"
env:
IS_NEW_RELEASE: ${{ needs.collect-release-info.outputs.IS_NEW_RELEASE }}
RELEASE_VERSION: ${{ needs.collect-release-info.outputs.RELEASE_VERSION }}
BRANCH_NAME: ${{ github.head_ref }}
COMMIT_ID: ${{ github.event.pull_request.head.sha }}
outputs:
DOCSITE_RELEASE_VERSION: ${{ steps.command.outputs.DOCSITE_RELEASE_VERSION }}
DOCSITE_DESTINATION_PATH: ${{ steps.command.outputs.DOCSITE_DESTINATION_PATH }}
HAS_DOCS_CHANGES_TO_RELEASE: ${{ steps.command.outputs.HAS_DOCS_CHANGES_TO_RELEASE }}
build-docsite:
runs-on: ubuntu-latest
needs:
- analyze
- collect-release-info
- collect-docsite-release-info
if: ${{ needs.collect-docsite-release-info.outputs.HAS_DOCS_CHANGES_TO_RELEASE == 'true' }}
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
- name: Install Python dependencies
run: poetry install
- name: Build docsite
run: poetry run mkdocs build
- name: Save site/ for later jobs
uses: actions/cache/save@v3
with:
path: site
key: docsite-${{ github.sha }}
publish-docsite:
runs-on: ubuntu-latest
needs:
- collect-release-info
- collect-docsite-release-info
# This already runs if there are docs changes to publish, so we don't need
# to check that here
- build-docsite
steps:
- uses: actions/checkout@v4
with:
ref: gh-pages
- name: Restore cache from previous job
uses: actions/cache/restore@v3
with:
path: site
key: docsite-${{ github.sha }}
- name: Update redirect in index (for a release)
if: ${{ needs.collect-release-info.outputs.IS_NEW_RELEASE == 'true' }}
run: |
url="https://${GITHUB_REPOSITORY_OWNER}.github.io/${GITHUB_REPOSITORY#"${GITHUB_REPOSITORY_OWNER}/"}/releases/${DOCSITE_RELEASE_VERSION}"
cat <<-EOT > index.html
<!DOCTYPE html>
<html>
<head>
<title>SuperDiff Documentation</title>
<meta http-equiv="refresh" content="0; url='${url}'" />
</head>
<body>
<p>
This page has moved to a different URL.
Please click
<a href="${url}">
this link
</a>
if you are not redirected.
</p>
</body>
</html>
EOT
env:
DOCSITE_RELEASE_VERSION: ${{ needs.collect-docsite-release-info.outputs.DOCSITE_RELEASE_VERSION }}
- name: Copy site/ to ${{ needs.collect-docsite-release-info.outputs.DOCSITE_DESTINATION_PATH }}
run: |
mkdir -p "$(dirname "$DOCSITE_DESTINATION_PATH")"
mv site "$DOCSITE_DESTINATION_PATH"
env:
DOCSITE_DESTINATION_PATH: ${{ needs.collect-docsite-release-info.outputs.DOCSITE_DESTINATION_PATH }}
- name: Publish new version of docsite
run: |
git add -A .
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git commit -m "Publish docs at $DOCSITE_DESTINATION_PATH"
git push
env:
DOCSITE_DESTINATION_PATH: ${{ needs.collect-docsite-release-info.outputs.DOCSITE_DESTINATION_PATH }}
- name: Announce publishing of docsite as a comment on the PR
if: ${{ github.event_name == 'pull_request' }}
run: |
gh pr comment "$PULL_REQUEST_NUMBER" --body ":book: A new version of the docsite has been published at: <https://${GITHUB_REPOSITORY_OWNER}.github.io/super_diff/$DOCSITE_DESTINATION_PATH>"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST_NUMBER: ${{ github.event.number }}
DOCSITE_DESTINATION_PATH: ${{ needs.collect-docsite-release-info.outputs.DOCSITE_DESTINATION_PATH }}
unpublish_docsite:
runs-on: ubuntu-latest
needs:
- collect-release-info
- collect-docsite-release-info
if: ${{ github.event_name == 'pull_request' && needs.collect-release-info.outputs.IS_NEW_RELEASE == 'false' && github.event.action == 'closed' }}
steps:
- uses: actions/checkout@v4
with:
ref: gh-pages
- name: Set DOCSITE_DESTINATION_PARENT_PATH
run: |
set -x
DOCSITE_DESTINATION_PARENT_PATH="$(dirname "$DOCSITE_DESTINATION_PATH")"
echo "DOCSITE_DESTINATION_PARENT_PATH=$DOCSITE_DESTINATION_PARENT_PATH" >> "$GITHUB_ENV"
env:
DOCSITE_DESTINATION_PATH: ${{ needs.collect-docsite-release-info.outputs.DOCSITE_DESTINATION_PATH }}
- name: Remove ${{ env.DOCSITE_DESTINATION_PARENT_PATH }} on gh-pages
run: |
set -x
if [[ "$DOCSITE_DESTINATION_PARENT_PATH" == "releases" || "$DOCSITE_DESTINATION_PARENT_PATH" == "branches" ]]; then
echo "Not removing $DOCSITE_DESTINATION_PARENT_PATH."
exit 1
fi
rm -rf "$DOCSITE_DESTINATION_PARENT_PATH"
- name: Re-push docsite if necessary
run: |
git add -A .
if ! git diff --cached --quiet; then
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git commit -m "Remove $DOCSITE_DESTINATION_PARENT_PATH"
git push
fi