Skip to content

Deploy website

Deploy website #7241

Workflow file for this run

name: "Deploy website"
env:
HUGO_VERSION: "0.134.1"
on:
schedule:
- cron: "19 */6 * * *"
# push:
# branches:
# - "deploy"
workflow_dispatch: {}
jobs:
"deploy":
name: "Build and deploy"
timeout-minutes: 10
runs-on: "ubuntu-latest"
steps:
- name: "Print environment"
run: |
printenv
pwd
# Check commits of build-archive and roar repositories. If both result in a
# cache hit, then all subsequent steps can be skipped. The steps for both
# repos are the same, other than the repo name. It would be possible to
# combine them into a single job with a matrix. However, them being in a
# separate job means that their caches would save before the main job
# finishes. That is, the repos would still be cached even if the main job
# fails for some reason.
- name: "Fetch latest commit hash of build-archive"
id: "check-fetch-build-archive"
# Emit hash to output, but also store it in a file to be used as the
# cached file, since at least one path is required.
run: |
mkdir -p meta
echo "hash=$(git ls-remote https://github.com/RobloxAPI/build-archive HEAD | cut -f 1)" > meta/commit-build-archive
cat meta/commit-build-archive >> "$GITHUB_OUTPUT"
cat meta/commit-build-archive
- name: "Cache commit hash of build-archive"
id: "check-cache-build-archive"
uses: "actions/cache@v4"
with:
key: "commit-build-archive-${{ steps.check-fetch-build-archive.outputs.hash }}"
path: |
meta/commit-build-archive
- name: "Fetch latest commit hash of roar"
id: "check-fetch-roar"
# Same as with build-archive. The stored file is also used in a later step
# to cache a build result.
run: |
mkdir -p meta
echo "hash=$(git ls-remote https://github.com/RobloxAPI/roar HEAD | cut -f 1)" > meta/commit-roar
cat meta/commit-roar >> "$GITHUB_OUTPUT"
cat meta/commit-roar
- name: "Cache commit hash of roar"
id: "check-cache-roar"
uses: "actions/cache@v4"
with:
key: "commit-roar-${{ steps.check-fetch-roar.outputs.hash }}"
path: |
meta/commit-roar
# If either previous cache did not have a hit, then at least one of them is
# fresh, so the following steps must run.
- name: "Checkout roar"
if: |
steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true'
uses: "actions/checkout@v4"
with:
repository: "RobloxAPI/roar"
path: "roar"
- name: "Checkout ref"
if: |
steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true'
uses: "actions/checkout@v4"
with:
ref: "gh-pages"
path: "ref"
# Check if data schema changed.
- name: "Check manifest"
id: "check-manifest"
if: |
steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true'
run: |
if [ -e "roar/cmd/roar/generate/manifest.json" ]; then
if [ -e "ref/.roar/manifest.json" ]; then
current=$(jq --raw-output ".schema" "roar/cmd/roar/generate/manifest.json")
stored=$(jq --raw-output ".schema" "ref/.roar/manifest.json")
if [ $current != $stored ]; then
echo "refresh=true" >> "$GITHUB_OUTPUT"
fi
fi
else
echo "roar manifest was not found!"
false
fi
- name: "Cache roar"
if: |
steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true'
id: "cache-roar"
uses: "actions/cache@v4"
with:
path: |
bin/roar
# Cache binary by commit hash.
key: "bin-roar-${{ steps.check-fetch-roar.outputs.hash }}"
# The steps to build roar run only if there was no cache hit on the roar
# binary, or if refreshing.
- name: "Setup Go"
if: |
(steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true') &&
(steps.cache-roar.outputs.cache-hit != 'true' ||
steps.check-manifest.outputs.refresh == 'true')
uses: "actions/setup-go@v4"
with:
go-version-file: "roar/go.mod"
cache-dependency-path: |
roar/go.sum
- name: "Build roar"
if: |
(steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true') &&
(steps.cache-roar.outputs.cache-hit != 'true' ||
steps.check-manifest.outputs.refresh == 'true')
run: |
go build -C "roar" -v -o "../bin/roar" "./cmd/roar"
# Full checkout of build-archive, only if refreshing.
- name: "refresh: Checkout build-archive"
if: |
(steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true') &&
steps.check-manifest.outputs.refresh == 'true'
uses: "actions/checkout@v4"
with:
repository: "RobloxAPI/build-archive"
path: "build-archive"
# Only regenerate data if refreshing.
- name: "refresh: Regenerate data"
if: |
(steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true') &&
steps.check-manifest.outputs.refresh == 'true'
run: |
bin/roar generate \
--site "roar/site" \
--source "build-archive/data/" \
--docs "https://github.com/Roblox/creator-docs" \
--update \
--no-cache \
--disable-pages \
--disable-icons
- name: "refresh: Store site data"
if: |
(steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true') &&
steps.check-manifest.outputs.refresh == 'true'
run: |
rm --recursive --force "ref/.roar"
mkdir --parents "ref/.roar"
cp --archive "roar/site/data/." "ref/.roar"
- name: "refresh: Commit refreshed data"
if: |
(steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true') &&
steps.check-manifest.outputs.refresh == 'true'
run: |
cd "ref"
git config user.email 'github-actions@github.com'
git config user.name 'github-actions'
git add -A
git commit -m 'Refresh data.'
continue-on-error: true
# Does not need to run if refreshed.
- name: "Restore site data"
if: |
steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true' &&
steps.check-manifest.outputs.refresh != 'true'
run: |
mkdir --parents "roar/site/data"
cp --archive "ref/.roar/." "roar/site/data"
- name: "Setup Hugo"
if: |
steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true'
uses: "peaceiris/actions-hugo@v2"
with:
hugo-version: ${{ env.HUGO_VERSION }}
extended: true
- name: "Generate data"
if: |
steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true'
run: |
bin/roar generate \
--site "roar/site" \
--source "https://raw.githubusercontent.com/RobloxAPI/build-archive/master/data/" \
--docs "https://github.com/Roblox/creator-docs" \
--update
- name: "Clear website"
if: |
steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true'
# Remove everything except hidden files (.git).
run: |
cd "ref"
rm --recursive --force *
- name: "Build website"
if: |
steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true'
# --destination is relative to --source.
run: |
hugo \
--logLevel info \
--minify \
--source "roar/site" \
--destination "../../ref" \
--baseURL "https://robloxapi.github.io/${{ github.event.repository.name }}/"
- name: "Store site data"
if: |
steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true'
run: |
rm --recursive --force "ref/.roar"
mkdir --parents "ref/.roar"
cp --archive "roar/site/data/." "ref/.roar"
- name: "Commit and push website"
if: |
steps.check-cache-build-archive.outputs.cache-hit != 'true' ||
steps.check-cache-roar.outputs.cache-hit != 'true'
run: |
cd "ref"
git config user.email 'github-actions@github.com'
git config user.name 'github-actions'
git add -A
git commit -m 'Update reference.'
git push
continue-on-error: true