Skip to content

Commit 86cd9c9

Browse files
committed
add github workflows
1 parent f36dee9 commit 86cd9c9

File tree

7 files changed

+414
-0
lines changed

7 files changed

+414
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "HugoBlox Codespace",
3+
"image": "ghcr.io/HugoBlox/hugo-blox-dev:hugo0.154.5",
4+
"updateContentCommand": "pnpm install --frozen-lockfile --prefer-offline",
5+
"postCreateCommand": "pnpm --version && hugo version",
6+
"customizations": {
7+
"vscode": {
8+
"extensions": [
9+
"hugoblox.hugoblox-studio"
10+
]
11+
}
12+
},
13+
"mounts": [
14+
"source=pnpm-store,target=/home/vscode/.local/share/pnpm,type=volume"
15+
],
16+
"remoteUser": "vscode",
17+
"forwardPorts": [
18+
1313
19+
],
20+
"portsAttributes": {
21+
"1313": {
22+
"label": "Hugo Server"
23+
}
24+
}
25+
}

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: modelscope

.github/preview.png

62.6 KB
Loading

.github/workflows/build.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: Build
2+
3+
env:
4+
NODE_VERSION: '20'
5+
6+
on:
7+
# Standalone trigger for PR validation
8+
pull_request:
9+
branches: ['main']
10+
# Reusable workflow trigger - called by deploy.yml
11+
workflow_call:
12+
outputs:
13+
artifact-id:
14+
description: 'The ID of the uploaded artifact'
15+
value: ${{ jobs.build.outputs.artifact-id }}
16+
# Allow manual trigger for testing
17+
workflow_dispatch:
18+
19+
# Read-only permissions for security
20+
permissions:
21+
contents: read
22+
23+
# Prevent duplicate builds for the same PR
24+
concurrency:
25+
group: build-${{ github.head_ref || github.run_id }}
26+
cancel-in-progress: true
27+
28+
jobs:
29+
build:
30+
if: github.repository_owner != 'HugoBlox'
31+
runs-on: ubuntu-latest
32+
timeout-minutes: 10
33+
outputs:
34+
artifact-id: ${{ steps.upload.outputs.artifact-id }}
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v4
38+
with:
39+
# Fetch history for Hugo's .GitInfo and .Lastmod
40+
fetch-depth: 0
41+
42+
- name: Setup Node.js
43+
uses: actions/setup-node@v6
44+
with:
45+
node-version: ${{ env.NODE_VERSION }}
46+
47+
- name: Setup pnpm
48+
if: hashFiles('package.json') != ''
49+
uses: pnpm/action-setup@v4
50+
51+
- name: Get Hugo Version
52+
id: hugo-version
53+
run: |
54+
# Install pinned yq version for robust YAML parsing
55+
YQ_VERSION="v4.44.1"
56+
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
57+
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
58+
echo "::error::Failed to download yq"
59+
exit 1
60+
fi
61+
sudo mv /tmp/yq /usr/local/bin/yq
62+
sudo chmod +x /usr/local/bin/yq
63+
64+
# Read hugo_version from hugoblox.yaml (nested under build.hugo_version)
65+
VERSION=$(yq '.build.hugo_version // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
66+
67+
# Fallback to a known stable version if not specified
68+
DEFAULT_VERSION="0.154.5"
69+
VERSION=${VERSION:-$DEFAULT_VERSION}
70+
71+
# Validate version format (basic check)
72+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
73+
echo "::warning::Invalid hugo_version format '$VERSION', using default $DEFAULT_VERSION"
74+
VERSION="$DEFAULT_VERSION"
75+
fi
76+
77+
echo "HUGO_VERSION=$VERSION" >> $GITHUB_ENV
78+
echo "Using Hugo version: $VERSION"
79+
80+
- name: Install dependencies
81+
run: |
82+
# Install Tailwind CLI if package.json exists
83+
if [ -f "package.json" ]; then
84+
echo "Installing Tailwind dependencies..."
85+
pnpm install --no-frozen-lockfile || npm install
86+
fi
87+
88+
- name: Setup Hugo
89+
uses: peaceiris/actions-hugo@v3
90+
with:
91+
hugo-version: ${{ env.HUGO_VERSION }}
92+
extended: true
93+
94+
# Cache dependencies (Go modules, node_modules) - stable, rarely changes
95+
- uses: actions/cache@v4
96+
with:
97+
path: |
98+
/tmp/hugo_cache_runner/
99+
node_modules/
100+
modules/*/node_modules/
101+
key: ${{ runner.os }}-hugo-deps-${{ hashFiles('**/go.mod', '**/package-lock.json',
102+
'**/pnpm-lock.yaml') }}
103+
restore-keys: |
104+
${{ runner.os }}-hugo-deps-
105+
106+
# Cache Hugo resources (processed images, CSS) - invalidates only when assets/config change
107+
- uses: actions/cache@v4
108+
with:
109+
path: resources/
110+
key: ${{ runner.os }}-hugo-resources-${{ hashFiles('assets/**/*', 'config/**/*',
111+
'hugo.yaml', 'package.json') }}
112+
restore-keys: |
113+
${{ runner.os }}-hugo-resources-
114+
115+
- name: Build with Hugo
116+
env:
117+
HUGO_ENVIRONMENT: production
118+
HUGO_BLOX_LICENSE: ${{ secrets.HUGO_BLOX_LICENSE }}
119+
run: |
120+
echo "Hugo Cache Dir: $(hugo config | grep cachedir)"
121+
hugo --minify
122+
123+
- name: Generate Pagefind search index (if applicable)
124+
run: |
125+
# Check if site uses Pagefind search
126+
if [ -f "package.json" ] && grep -q "pagefind" package.json; then
127+
pnpm run pagefind || npx pagefind --site "public"
128+
fi
129+
130+
- name: Upload artifact
131+
id: upload
132+
uses: actions/upload-pages-artifact@v4
133+
with:
134+
path: ./public

.github/workflows/deploy.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Deploy website to GitHub Pages
2+
3+
on:
4+
# Trigger the workflow every time you push to the `main` branch
5+
push:
6+
branches: ['main']
7+
# Allows you to run this workflow manually from the Actions tab on GitHub
8+
workflow_dispatch:
9+
10+
# Provide permission to clone the repo and deploy it to GitHub Pages
11+
permissions:
12+
contents: read
13+
pages: write
14+
id-token: write
15+
16+
concurrency:
17+
group: 'pages'
18+
cancel-in-progress: false
19+
20+
jobs:
21+
# Check deployment configuration
22+
config:
23+
if: github.repository_owner != 'HugoBlox'
24+
runs-on: ubuntu-latest
25+
outputs:
26+
deploy-host: ${{ steps.check.outputs.host }}
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
with:
31+
sparse-checkout: hugoblox.yaml
32+
sparse-checkout-cone-mode: false
33+
34+
- name: Check deploy host
35+
id: check
36+
run: |
37+
# Install pinned yq version for robust YAML parsing
38+
YQ_VERSION="v4.44.1"
39+
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
40+
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
41+
echo "::error::Failed to download yq"
42+
exit 1
43+
fi
44+
sudo mv /tmp/yq /usr/local/bin/yq
45+
sudo chmod +x /usr/local/bin/yq
46+
47+
# Read deploy.host from hugoblox.yaml, default to github-pages
48+
HOST=$(yq '.deploy.host // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
49+
HOST=${HOST:-github-pages}
50+
51+
# Validate known hosts
52+
if [[ ! "$HOST" =~ ^(github-pages|netlify|vercel|cloudflare|none)$ ]]; then
53+
echo "::warning::Unknown deploy host '$HOST', defaulting to github-pages"
54+
HOST="github-pages"
55+
fi
56+
57+
echo "host=$HOST" >> $GITHUB_OUTPUT
58+
echo "Deployment target: $HOST"
59+
60+
# Build website using reusable workflow (always runs for CI)
61+
build:
62+
needs: config
63+
if: github.repository_owner != 'HugoBlox'
64+
uses: ./.github/workflows/build.yml
65+
secrets: inherit
66+
67+
# Deploy website to GitHub Pages hosting (only if configured)
68+
deploy:
69+
needs: [config, build]
70+
if: needs.config.outputs.deploy-host == 'github-pages'
71+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
72+
permissions:
73+
pages: write # to deploy to Pages
74+
id-token: write # to verify the deployment originates from an appropriate source
75+
# Deploy to the github-pages environment
76+
environment:
77+
name: github-pages
78+
url: ${{ steps.deployment.outputs.page_url }}
79+
runs-on: ubuntu-latest
80+
steps:
81+
- name: Deploy to GitHub Pages
82+
id: deployment
83+
uses: actions/deploy-pages@v4

.github/workflows/upgrade.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Upgrade HugoBlox
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_type:
7+
description: 'Upgrade to version'
8+
required: true
9+
default: 'Stable'
10+
type: choice
11+
options:
12+
- Stable
13+
- Beta (Preview)
14+
schedule:
15+
# Run at 05:00 on Monday
16+
- cron: '0 5 * * 1'
17+
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
22+
# Prevent duplicate upgrade runs
23+
concurrency:
24+
group: upgrade-${{ github.ref }}
25+
cancel-in-progress: true
26+
27+
jobs:
28+
upgrade:
29+
name: Upgrade
30+
if: github.repository_owner != 'HugoBlox'
31+
runs-on: ubuntu-latest
32+
timeout-minutes: 15
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 0
38+
39+
- name: Setup Node.js
40+
uses: actions/setup-node@v6
41+
with:
42+
node-version: '22'
43+
44+
- name: Setup pnpm
45+
uses: pnpm/action-setup@v4
46+
with:
47+
package_json_path: ./package.json
48+
run_install: false
49+
50+
- name: Setup Go
51+
uses: actions/setup-go@v5
52+
with:
53+
go-version: '1.23'
54+
55+
- name: Setup Hugo
56+
uses: peaceiris/actions-hugo@v3
57+
with:
58+
hugo-version: 'latest'
59+
extended: true
60+
61+
- name: Run Upgrade CLI
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
# Use manual input or default to stable for scheduled runs
65+
VERSION_TYPE: ${{ inputs.version_type || 'Stable' }}
66+
run: |
67+
FLAGS="--yes --ci"
68+
69+
if [ "$VERSION_TYPE" == "Beta (Preview)" ]; then
70+
FLAGS="$FLAGS --canary"
71+
fi
72+
73+
echo "Running upgrade with flags: $FLAGS"
74+
pnpm dlx hugoblox@latest upgrade $FLAGS
75+
76+
77+
- name: Create Pull Request
78+
uses: peter-evans/create-pull-request@v6
79+
with:
80+
token: ${{ secrets.GITHUB_TOKEN }}
81+
commit-message: "chore(deps): upgrade hugoblox modules"
82+
title: "⬆️ Upgrade HugoBlox Modules"
83+
body: |
84+
This PR upgrades the [HugoBlox](https://hugoblox.com) modules to the latest version.
85+
86+
**Changes:**
87+
- Updated Hugo Modules (go.mod/go.sum)
88+
- Applied automatic migrations (if any)
89+
90+
**Verification:**
91+
- [ ] Check the Deploy Preview to ensure everything looks correct.
92+
- [ ] Merge this PR to apply the updates.
93+
branch: "chore/upgrade-hugoblox-${{ github.run_id }}"
94+
delete-branch: true
95+
base: main
96+
labels: |
97+
dependencies
98+
automated-pr

0 commit comments

Comments
 (0)