Skip to content

Commit

Permalink
Add GitHub Actions workflow to publish to GitHub Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
wjt committed Jan 14, 2025
1 parent d57c38d commit 330584e
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
# Set update schedule for GitHub Actions

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
116 changes: 116 additions & 0 deletions .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: "Publish to GitHub Pages"
on:
workflow_dispatch:
release:
types:
- published

# Cancel any ongoing previous run if the job is re-triggered
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

permissions:
contents: read
pages: write
id-token: write

env:
GODOT_VERSION: 4.3

jobs:
check:
name: Check if GitHub Pages is enabled
runs-on: ubuntu-latest
steps:
- name: Check
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh api "repos/${{ github.repository }}/pages" | jq --exit-status '.build_type == "workflow"'
then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "# Not published to GitHub Pages" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo -n "Check that Pages is enabled, with the source set to GitHub Actions, in the " >> "$GITHUB_STEP_SUMMARY"
echo "[repository settings](https://github.com/${{ github.repository }}/settings/pages)." >> "$GITHUB_STEP_SUMMARY"
fi
outputs:
enabled: ${{ steps.check.outputs.enabled }}

build:
name: Build for web
needs:
- check
if: ${{ needs.check.outputs.enabled }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true

- name: Cache Godot Engine downloads
id: cache-godot
uses: actions/cache@v4
with:
path: |
build/godot
build/._sc_
build/editor_data/export_templates/${{ env.GODOT_VERSION }}.stable
key: godot-${{ env.GODOT_VERSION }}

- name: Download Godot Engine from GitHub release
id: download
if: steps.cache-godot.outputs.cache-hit != 'true'
run: |
mkdir -p build && cd build
# Download Godot Engine itself
wget https://github.com/godotengine/godot/releases/download/${GODOT_VERSION}-stable/Godot_v${GODOT_VERSION}-stable_linux.x86_64.zip && \
unzip Godot_v${GODOT_VERSION}-stable_linux.x86_64.zip && \
mv Godot_v${GODOT_VERSION}-stable_linux.x86_64 godot
# Download export templates
mkdir -p editor_data/export_templates
wget https://github.com/godotengine/godot/releases/download/${GODOT_VERSION}-stable/Godot_v${GODOT_VERSION}-stable_export_templates.tpz && \
unzip Godot_v${GODOT_VERSION}-stable_export_templates.tpz && \
mv templates editor_data/export_templates/${GODOT_VERSION}.stable
# Tell Godot Engine to run in "self-contained" mode so it looks for
# templates here instead of in ~/.local/share/godot/
touch ._sc_
- name: Web Build
run: |
mkdir -v -p build/web && cd build
# Note that the export path can be confusing; it's relative to the
# Godot project path, NOT necessarily the current directory or Godot
# binary location
./godot --headless --verbose --path ../ --export-release "Web" ./build/web/index.html
- name: Upload Artifact
uses: actions/upload-pages-artifact@v3
with:
name: web
path: build/web

publish:
name: Publish to GitHub Pages
needs:
- build
runs-on: ubuntu-latest
steps:
- id: deploy
name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4
with:
artifact_name: web

- name: Show URL in summary
if: ${{ steps.deploy.outcome == 'success' }}
run: |
echo "Game published to: <${{ steps.deploy.outputs.page_url }}>" >> "$GITHUB_STEP_SUMMARY"

0 comments on commit 330584e

Please sign in to comment.