Skip to content

Commit 0128589

Browse files
committed
ci: Add workflow to deploy to GitHub Pages
While it is not necessarily useful to have these demos in their default state published to the web, this workflow can be used by a learner who has customised the demos in their own repo. The workflow is designed to fail gracefully if GitHub Pages is not available (which is typically the case in a private repo owned by a free account) or not configured correctly. It also only runs on releases or when manually triggered, to avoid running it each time a learner pushes or merges to main. https://phabricator.endlessm.com/T35699
1 parent 7ead61f commit 0128589

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

.github/workflows/github-pages.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: "Publish to GitHub Pages"
2+
on:
3+
workflow_dispatch:
4+
release:
5+
types:
6+
- published
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
env:
14+
GODOT_VERSION: 4.3
15+
16+
jobs:
17+
check:
18+
name: Check if GitHub Pages is enabled
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Check
22+
id: check
23+
env:
24+
GH_TOKEN: ${{ github.token }}
25+
run: |
26+
if gh api "repos/${{ github.repository }}/pages" | jq --exit-status '.build_type == "workflow"'
27+
then
28+
echo "enabled=true" >> "$GITHUB_OUTPUT"
29+
else
30+
echo "# Not published to GitHub Pages" >> "$GITHUB_STEP_SUMMARY"
31+
echo "" >> "$GITHUB_STEP_SUMMARY"
32+
echo -n "Check that Pages is enabled, with the source set to GitHub Actions, in the " >> "$GITHUB_STEP_SUMMARY"
33+
echo "[repository settings](https://github.com/${{ github.repository }}/settings/pages)." >> "$GITHUB_STEP_SUMMARY"
34+
fi
35+
outputs:
36+
enabled: ${{ steps.check.outputs.enabled }}
37+
38+
build:
39+
name: Build for web
40+
needs:
41+
- check
42+
if: ${{ needs.check.outputs.enabled }}
43+
runs-on: ubuntu-latest
44+
container:
45+
image: barichello/godot-ci:4.3
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v4
49+
with:
50+
lfs: true
51+
52+
- name: Set up export templates
53+
run: |
54+
mkdir -v -p ~/.local/share/godot/export_templates/
55+
mv /root/.local/share/godot/export_templates/${GODOT_VERSION}.stable ~/.local/share/godot/export_templates/${GODOT_VERSION}.stable
56+
57+
- name: Web Build
58+
run: |
59+
mkdir -v -p build/web
60+
godot --headless --verbose --export-release "Web" ./build/web/index.html
61+
62+
- name: Upload Artifact
63+
uses: actions/upload-pages-artifact@v3
64+
with:
65+
name: web
66+
path: build/web
67+
68+
publish:
69+
name: Publish to GitHub Pages
70+
needs:
71+
- build
72+
runs-on: ubuntu-latest
73+
steps:
74+
- id: deploy
75+
name: Deploy to GitHub Pages
76+
uses: actions/deploy-pages@v4
77+
with:
78+
artifact_name: web
79+
80+
- name: Show URL in summary
81+
if: ${{ steps.deploy.outcome == 'success' }}
82+
run: |
83+
echo "Game published to: <${{ steps.deploy.outputs.page_url }}>" >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)