Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/build-and-deploy-site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build and Deploy Site

on:
push:
branches: [master]
workflow_dispatch:

permissions:
contents: write

defaults:
run:
shell: bash

jobs:
build-and-deploy-site:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Setup Hugo Extended
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.158.0'
extended: true

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Setup site dependencies
run: make setup

- name: Build site
run: make build-production BASE_URL="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/"

- name: Prepare Pages output
run: touch public/.nojekyll

- name: Deploy site to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./public
keep_files: true
100 changes: 100 additions & 0 deletions .github/workflows/build-and-preview-site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Build and Preview Site

on:
pull_request_target:
branches: [master]
types: [opened, synchronize, reopened, closed]

permissions:
contents: write
pull-requests: write

concurrency:
group: preview-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
build-and-deploy-preview:
runs-on: ubuntu-latest

steps:
- name: Checkout PR code
if: github.event.action != 'closed'
uses: actions/checkout@v6
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
fetch-depth: 0

- name: Checkout for cleanup
if: github.event.action == 'closed'
uses: actions/checkout@v6
with:
ref: gh-pages
fetch-depth: 0

- name: Setup Go
if: github.event.action != 'closed'
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Setup Hugo Extended
if: github.event.action != 'closed'
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.158.0'
extended: true

- name: Setup Node
if: github.event.action != 'closed'
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Setup site dependencies
if: github.event.action != 'closed'
run: make setup

- name: Build PR preview
if: github.event.action != 'closed'
run: |
make build-preview BASE_URL="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/"
touch public/.nojekyll

- name: Deploy PR preview
if: github.event.action != 'closed'
uses: rossjrw/pr-preview-action@v1.6.3
with:
source-dir: ./public
preview-branch: gh-pages
umbrella-dir: pr-preview
action: auto
comment: false

- name: Comment PR with Preview URL
if: github.event.action != 'closed'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
message: |
🚀 **Preview deployment for PR #${{ github.event.pull_request.number }}**

🌐 **Preview URL**: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/

_This preview will be updated automatically when you push new commits to this PR._

- name: Cleanup PR preview on close
if: github.event.action == 'closed'
uses: rossjrw/pr-preview-action@v1.6.3
with:
preview-branch: gh-pages
umbrella-dir: pr-preview
action: remove
72 changes: 0 additions & 72 deletions .github/workflows/gh-pages.yml

This file was deleted.

20 changes: 17 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,32 @@ include .github/build/Makefile.show-help.mk
#----------------------------------------------------------------------------
# Academy
# ---------------------------------------------------------------------------
.PHONY: setup build site clean check-go theme-update
.PHONY: setup build build-production build-preview site clean check-go theme-update

BASE_URL ?=

## ------------------------------------------------------------
----LOCAL_BUILDS: Show help for available targets

## Local: Install site dependencies
setup:
npm i
@if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then \
npm ci; \
else \
npm i; \
fi

## Local: Build site for local consumption
build:
hugo build
BASE_URL="$(BASE_URL)" npm run build

## CI: Build production site output
build-production:
BASE_URL="$(BASE_URL)" npm run build:production

## CI: Build preview site output and mark it non-indexable
build-preview:
BASE_URL="$(BASE_URL)" npm run build:preview

## Local: Build and run site locally with draft and future content enabled.
site: check-go
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@
"bugs": "https://github.com/google/docsy-example/issues",
"spelling": "cSpell:ignore docsy hugo htmltest precheck postbuild rtlcss -",
"scripts": {
"_build": "npm run _hugo-dev --",
"_check:links": "echo IMPLEMENTATION PENDING for check-links; echo",
"_hugo": "hugo --cleanDestinationDir",
"_hugo-dev": "npm run _hugo -- -e dev -DFE",
"_local": "npx cross-env HUGO_MODULE_WORKSPACE=docsy.work",
"_serve": "npm run _hugo-dev -- --minify serve --renderToMemory",
"build:preview": "npm run _hugo-dev -- --minify --baseURL \"${DEPLOY_PRIME_URL:-/}\"",
"build:production": "npm run _hugo -- --minify",
"build": "npm run _build -- ",
"build": "sh -c 'hugo build --cleanDestinationDir ${BASE_URL:+--baseURL \"$BASE_URL\"}'",
"build:preview": "cross-env HUGO_ENVIRONMENT=production HUGO_ENV=production HUGO_PREVIEW=true sh -c 'hugo build -D --gc --buildFuture --cleanDestinationDir --minify ${BASE_URL:+--baseURL \"$BASE_URL\"}'",
"build:production": "cross-env HUGO_ENVIRONMENT=production HUGO_ENV=production sh -c 'hugo build -D --gc --buildFuture --cleanDestinationDir --minify ${BASE_URL:+--baseURL \"$BASE_URL\"}'",
"check:links:all": "HTMLTEST_ARGS= npm run _check:links",
"check:links": "npm run _check:links",
"clean": "rm -Rf public/* resources",
"local": "npm run _local -- npm run",
"make:public": "git init -b main public",
"precheck:links:all": "npm run build",
"precheck:links": "npm run build",
"postbuild:preview": "npm run _check:links",
"postbuild:preview": "printf 'User-agent: *\\nDisallow: /\\n' > public/robots.txt && find public -name '*.html' -exec perl -0pi -e 's|<meta name=robots content=\"index, follow\">|<meta name=robots content=\"noindex, nofollow\">|g; s|<meta name=\"robots\" content=\"index, follow\">|<meta name=\"robots\" content=\"noindex, nofollow\">|g; s|</head>|<meta name=\"robots\" content=\"noindex, nofollow\"></head>|i unless /<meta[^>]+name=\"?robots\"?[^>]+noindex, nofollow/i' {} +",
"postbuild:production": "npm run _check:links",
"serve": "npm run _serve",
"test": "npm run check:links",
Expand Down
Loading