Skip to content

Commit 26abfbb

Browse files
Move docs publishing into release workflow
1 parent 7f9dbb7 commit 26abfbb

25 files changed

Lines changed: 108 additions & 8520 deletions

File tree

.github/workflows/release.yml

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: Release
33
on:
44
workflow_dispatch:
55
inputs:
6-
release_tag:
7-
description: "Release tag, e.g. v0.12.0"
6+
release_version:
7+
description: "Release version, e.g. 0.11.0"
88
required: true
99
type: string
1010
pull_request:
@@ -113,6 +113,9 @@ jobs:
113113
- test-bundle
114114
runs-on: ubuntu-24.04
115115
if: github.event_name == 'workflow_dispatch'
116+
outputs:
117+
release_commit: ${{ steps.prepare_release.outputs.release_commit }}
118+
release_tag: ${{ steps.prepare_release.outputs.release_tag }}
116119
permissions:
117120
contents: write
118121
defaults:
@@ -137,46 +140,96 @@ jobs:
137140
with:
138141
version: nightly-new-compiler
139142

140-
- name: Update example package URLs
143+
- name: Prepare release docs and examples
144+
id: prepare_release
141145
env:
142146
BUNDLE_FILENAME: ${{ needs.build-bundle.outputs.bundle_filename }}
143-
RELEASE_TAG: ${{ github.event.inputs.release_tag }}
147+
RAW_RELEASE_VERSION: ${{ github.event.inputs.release_version }}
144148
REF_TYPE: ${{ github.ref_type }}
145149
run: |
146150
if [ "$REF_TYPE" != "branch" ]; then
147151
echo "Release workflow must be run from a branch so it can commit updated example URLs."
148152
exit 1
149153
fi
150154
155+
RELEASE_VERSION="${RAW_RELEASE_VERSION#v}"
156+
if [[ ! "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
157+
echo "Release version must use x.y.z format, e.g. 0.11.0"
158+
exit 1
159+
fi
160+
161+
RELEASE_TAG="$RELEASE_VERSION"
151162
BUNDLE_URL="https://github.com/lukewilliamboswell/roc-parser/releases/download/${RELEASE_TAG}/${BUNDLE_FILENAME}"
152163
set +e
153164
python3 ci/update_example_parser_url.py "$BUNDLE_URL"
154165
UPDATE_STATUS=$?
155166
set -e
156167
157-
if [ "$UPDATE_STATUS" -eq 0 ]; then
158-
git config user.name "github-actions[bot]"
159-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
160-
git add examples
161-
git commit -m "Update examples for ${RELEASE_TAG}"
162-
git push origin HEAD:${{ github.ref_name }}
163-
elif [ "$UPDATE_STATUS" -eq 2 ]; then
168+
if [ "$UPDATE_STATUS" -eq 2 ]; then
164169
echo "Example package URLs are already current."
165-
else
170+
elif [ "$UPDATE_STATUS" -ne 0 ]; then
166171
exit "$UPDATE_STATUS"
167172
fi
168173
174+
DOCS_ROOT=www ./docs.sh "$RELEASE_VERSION"
175+
176+
git config user.name "github-actions[bot]"
177+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
178+
git add examples www
179+
180+
if git diff --cached --quiet; then
181+
echo "Release docs and example URLs are already current."
182+
else
183+
git commit -m "Prepare ${RELEASE_VERSION} release artifacts"
184+
git push origin HEAD:${{ github.ref_name }}
185+
fi
186+
187+
echo "release_commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
188+
echo "release_tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
189+
169190
- name: Create release
170191
env:
171192
GH_TOKEN: ${{ github.token }}
172193
run: |
173194
BUNDLE_FILE="dist/${{ needs.build-bundle.outputs.bundle_filename }}"
174195
ROC_VERSION=$(roc version)
175-
TARGET_COMMIT=$(git rev-parse HEAD)
196+
TARGET_COMMIT="${{ steps.prepare_release.outputs.release_commit }}"
197+
RELEASE_TAG="${{ steps.prepare_release.outputs.release_tag }}"
176198
177-
gh release create "${{ github.event.inputs.release_tag }}" \
199+
gh release create "$RELEASE_TAG" \
178200
"$BUNDLE_FILE" \
179201
--target "$TARGET_COMMIT" \
180-
--title "${{ github.event.inputs.release_tag }}" \
202+
--title "$RELEASE_TAG" \
181203
--generate-notes \
182204
--notes "Parser package bundle built with Roc $ROC_VERSION."
205+
206+
deploy-docs:
207+
name: Deploy docs
208+
needs: create-release
209+
runs-on: ubuntu-latest
210+
if: github.event_name == 'workflow_dispatch'
211+
permissions:
212+
contents: read
213+
pages: write
214+
id-token: write
215+
environment:
216+
name: github-pages
217+
url: ${{ steps.deployment.outputs.page_url }}
218+
219+
steps:
220+
- name: Checkout release commit
221+
uses: actions/checkout@v4
222+
with:
223+
ref: ${{ needs.create-release.outputs.release_commit }}
224+
225+
- name: Setup Pages
226+
uses: actions/configure-pages@v5
227+
228+
- name: Upload docs artifact
229+
uses: actions/upload-pages-artifact@v3
230+
with:
231+
path: "./www"
232+
233+
- name: Deploy to GitHub Pages
234+
id: deployment
235+
uses: actions/deploy-pages@v4

.github/workflows/www.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Includes modules to parse the following (with various levels of maturity);
2727

2828
See [lukewilliamboswell.github.io/roc-parser/](https://lukewilliamboswell.github.io/roc-parser/)
2929

30-
Locally generate docs using `roc docs package/main.roc --output=www`.
30+
Locally generate versioned docs using `./docs.sh 0.11.0`.
3131

3232
## Contributing
3333

@@ -44,3 +44,5 @@ CI skips `examples/markdown.roc` because the latest Roc nightly overflows the co
4444
## Packaging
4545

4646
Bundle the package for distribution using `scripts/bundle.sh --output-dir dist`.
47+
48+
Run the release workflow from GitHub Actions with a release version such as `0.11.0`. It builds and tests the bundle, updates example package URLs, regenerates versioned docs, updates the docs redirect, creates the GitHub release, and deploys the docs to GitHub Pages.

docs.sh

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
4-
set -euxo pipefail
3+
set -euo pipefail
54

65
# Function to validate version number format (x.y.z)
76
validate_version() {
@@ -14,14 +13,46 @@ validate_version() {
1413
# Check if version argument is provided
1514
if [ $# -ne 1 ]; then
1615
echo "Usage: $0 <version>"
17-
echo "Example: $0 0.12.0"
16+
echo "Example: $0 0.11.0"
1817
exit 1
1918
fi
2019

21-
VERSION=$1
20+
VERSION="${1#v}"
21+
DOCS_ROOT="${DOCS_ROOT:-www}"
22+
ROC_BIN="${ROC:-roc}"
23+
24+
if [[ "$ROC_BIN" == */* ]]; then
25+
ROC_BIN="$(cd "$(dirname "$ROC_BIN")" && pwd)/$(basename "$ROC_BIN")"
26+
fi
2227

2328
# Validate version number
2429
validate_version "$VERSION"
2530

26-
# Run roc docs with validated version
27-
roc docs package/main.roc --output="www/$VERSION"
31+
rm -rf "$DOCS_ROOT/$VERSION"
32+
mkdir -p "$DOCS_ROOT"
33+
34+
"$ROC_BIN" docs package/main.roc --output="$DOCS_ROOT/$VERSION"
35+
36+
cat > "$DOCS_ROOT/index.html" <<EOF
37+
<!doctype html>
38+
<html lang="en">
39+
<head>
40+
<meta charset="UTF-8" />
41+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
42+
<title>Redirecting...</title>
43+
<script>
44+
window.location.href = "/roc-parser/$VERSION/";
45+
</script>
46+
</head>
47+
<body>
48+
<noscript>
49+
<p>
50+
If you are not automatically redirected, please
51+
<a href="/roc-parser/$VERSION/">click here</a>.
52+
</p>
53+
</noscript>
54+
</body>
55+
</html>
56+
EOF
57+
58+
echo "Generated docs for $VERSION in $DOCS_ROOT/$VERSION"

0 commit comments

Comments
 (0)