Skip to content

Commit 1a2fb63

Browse files
authored
Fix GH workflow so docs deploy on new releases (#245)
Previously, when merging a new release, a new version of the docsite would not get deployed. Apparently I misunderstood the purpose of the `github.event.merged` property. I've changed this so that the step to determine the destination for the docsite (and hence whether the docsite should be deployed) looks for the `main` branch to be pushed and for `version.rb` to be updated. I've also fixed the index page for the docsite so it redirects to the correct release page.
1 parent cca0b34 commit 1a2fb63

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

.github/workflows/super_diff.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,25 @@ jobs:
120120
run: |
121121
set -x
122122
123-
if [[ "$IS_NEW_RELEASE" == "true" ]]; then
123+
if [[ "$GITHUB_EVENT_NAME" == "push" && "$GITHUB_REF_NAME" == "main" && "$IS_NEW_RELEASE" == "true" ]]; then
124124
DOCSITE_RELEASE_VERSION="$RELEASE_VERSION"
125125
DOCSITE_DESTINATION_PATH="releases/$RELEASE_VERSION"
126-
HAS_CHANGES_TO_DOCS="true"
126+
HAS_DOCS_CHANGES_TO_RELEASE="true"
127127
else
128128
DOCSITE_RELEASE_VERSION="$COMMIT_ID"
129129
DOCSITE_DESTINATION_PATH="branches/$BRANCH_NAME/$COMMIT_ID"
130130
# Check if there any changes to docs/
131131
if git diff --quiet --merge-base "origin/$GITHUB_BASE_REF" -- docs; then
132-
HAS_CHANGES_TO_DOCS="false"
132+
HAS_DOCS_CHANGES_TO_RELEASE="false"
133133
else
134-
HAS_CHANGES_TO_DOCS="true"
134+
HAS_DOCS_CHANGES_TO_RELEASE="true"
135135
fi
136136
fi
137137
138138
{
139139
echo "DOCSITE_RELEASE_VERSION=$DOCSITE_RELEASE_VERSION"
140140
echo "DOCSITE_DESTINATION_PATH=$DOCSITE_DESTINATION_PATH"
141-
echo "HAS_CHANGES_TO_DOCS=$HAS_CHANGES_TO_DOCS"
141+
echo "HAS_DOCS_CHANGES_TO_RELEASE=$HAS_DOCS_CHANGES_TO_RELEASE"
142142
} >> "$GITHUB_OUTPUT"
143143
env:
144144
IS_NEW_RELEASE: ${{ needs.collect-release-info.outputs.IS_NEW_RELEASE }}
@@ -148,15 +148,15 @@ jobs:
148148
outputs:
149149
DOCSITE_RELEASE_VERSION: ${{ steps.command.outputs.DOCSITE_RELEASE_VERSION }}
150150
DOCSITE_DESTINATION_PATH: ${{ steps.command.outputs.DOCSITE_DESTINATION_PATH }}
151-
HAS_CHANGES_TO_DOCS: ${{ steps.command.outputs.HAS_CHANGES_TO_DOCS }}
151+
HAS_DOCS_CHANGES_TO_RELEASE: ${{ steps.command.outputs.HAS_DOCS_CHANGES_TO_RELEASE }}
152152

153153
build-docsite:
154154
runs-on: ubuntu-latest
155155
needs:
156156
- analyze
157157
- collect-release-info
158158
- collect-docsite-release-info
159-
if: ${{ github.event_name == 'pull_request' && ((needs.collect-release-info.outputs.IS_NEW_RELEASE == 'false' && needs.collect-docsite-release-info.outputs.HAS_CHANGES_TO_DOCS == 'true') || (needs.collect-release-info.outputs.IS_NEW_RELEASE == 'true' && github.event.merged)) }}
159+
if: ${{ needs.collect-docsite-release-info.outputs.HAS_DOCS_CHANGES_TO_RELEASE == 'true' }}
160160
steps:
161161
- uses: actions/checkout@v4
162162
- name: Install poetry
@@ -178,6 +178,8 @@ jobs:
178178
needs:
179179
- collect-release-info
180180
- collect-docsite-release-info
181+
# This already runs if there are docs changes to publish, so we don't need
182+
# to check that here
181183
- build-docsite
182184
steps:
183185
- uses: actions/checkout@v4
@@ -191,25 +193,28 @@ jobs:
191193
- name: Update redirect in index (for a release)
192194
if: ${{ needs.collect-release-info.outputs.IS_NEW_RELEASE == 'true' }}
193195
run: |
196+
url="https://${GITHUB_REPOSITORY_OWNER}.github.io/${GITHUB_REPOSITORY#"${GITHUB_REPOSITORY_OWNER}/"}/releases/${DOCSITE_RELEASE_VERSION}"
194197
cat <<-EOT > index.html
195198
<!DOCTYPE html>
196199
<html>
197200
<head>
198201
<title>SuperDiff Documentation</title>
199-
<meta http-equiv="refresh" content="0; url='https://mcmire.github.com/super_diff/releases/${RELEASE_VERSION}'" />
202+
<meta http-equiv="refresh" content="0; url='${url}'" />
200203
</head>
201204
<body>
202205
<p>
203206
This page has moved to a different URL.
204207
Please click
205-
<a href="https://mcmire.github.com/super_diff/releases/${RELEASE_VERSION}">
208+
<a href="${url}">
206209
this link
207210
</a>
208211
if you are not redirected.
209212
</p>
210213
</body>
211214
</html>
212215
EOT
216+
env:
217+
DOCSITE_RELEASE_VERSION: ${{ needs.collect-docsite-release-info.outputs.DOCSITE_RELEASE_VERSION }}
213218
- name: Copy site/ to ${{ needs.collect-docsite-release-info.outputs.DOCSITE_DESTINATION_PATH }}
214219
run: |
215220
mkdir -p "$(dirname "$DOCSITE_DESTINATION_PATH")"
@@ -226,6 +231,7 @@ jobs:
226231
env:
227232
DOCSITE_DESTINATION_PATH: ${{ needs.collect-docsite-release-info.outputs.DOCSITE_DESTINATION_PATH }}
228233
- name: Announce publishing of docsite as a comment on the PR
234+
if: ${{ github.event_name == 'pull_request' }}
229235
run: |
230236
gh pr comment "$PULL_REQUEST_NUMBER" --body ":book: A new version of the docsite has been published at: <https://mcmire.github.io/super_diff/$DOCSITE_DESTINATION_PATH>"
231237
env:

0 commit comments

Comments
 (0)