Files
hugo-extended/.github/workflows/bump-hugo.yml
T
2026-06-21 16:51:33 -04:00

169 lines
6.3 KiB
YAML

name: Bump Hugo Version
on:
schedule:
- cron: "0 */3 * * *"
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
bump:
name: Bump to latest Hugo version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: 24
- name: Get current package version
id: current
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current package version: $CURRENT_VERSION"
- name: Get latest Hugo release
id: hugo
env:
GH_TOKEN: ${{ github.token }}
run: |
# Fetch latest release from Hugo repo (excludes prereleases by default)
LATEST_RELEASE=$(gh api repos/gohugoio/hugo/releases/latest --jq '.tag_name')
# Remove 'v' prefix if present
LATEST_VERSION="${LATEST_RELEASE#v}"
echo "version=$LATEST_VERSION" >> $GITHUB_OUTPUT
echo "Latest Hugo version: $LATEST_VERSION"
- name: Check if update is needed
id: check
run: |
CURRENT="${{ steps.current.outputs.version }}"
LATEST="${{ steps.hugo.outputs.version }}"
if [ "$CURRENT" = "$LATEST" ]; then
echo "Already up to date with Hugo v$LATEST"
echo "needs_update=false" >> $GITHUB_OUTPUT
else
echo "New Hugo version available: v$LATEST (current: v$CURRENT)"
echo "needs_update=true" >> $GITHUB_OUTPUT
fi
- name: Check if PR already exists
id: pr_check
if: steps.check.outputs.needs_update == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
LATEST="${{ steps.hugo.outputs.version }}"
BRANCH_NAME="chore/hugo-v${LATEST}"
# Check if a PR for this version already exists
EXISTING_PR=$(gh pr list --head "$BRANCH_NAME" --json number --jq '.[0].number // empty')
if [ -n "$EXISTING_PR" ]; then
echo "PR #$EXISTING_PR already exists for Hugo v$LATEST"
echo "pr_exists=true" >> $GITHUB_OUTPUT
else
echo "No existing PR found for Hugo v$LATEST"
echo "pr_exists=false" >> $GITHUB_OUTPUT
fi
- name: Configure Git
if: steps.check.outputs.needs_update == 'true' && steps.pr_check.outputs.pr_exists == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Install dependencies
if: steps.check.outputs.needs_update == 'true' && steps.pr_check.outputs.pr_exists == 'false'
run: npm ci --ignore-scripts --omit=optional
- name: Create branch and bump version
if: steps.check.outputs.needs_update == 'true' && steps.pr_check.outputs.pr_exists == 'false'
run: |
LATEST="${{ steps.hugo.outputs.version }}"
BRANCH_NAME="chore/hugo-v${LATEST}"
# Create new branch
git checkout -b "$BRANCH_NAME"
# Use npm version to properly bump (updates package.json and package-lock.json)
# --no-git-tag-version prevents creating a tag, we'll let the publish workflow handle that
npm version "$LATEST" --no-git-tag-version
node --input-type=module <<'NODE'
import fs from "node:fs";
const packageJsonPath = "package.json";
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
if (!packageJson.optionalDependencies || Object.keys(packageJson.optionalDependencies).length === 0) {
throw new Error("package.json has no optionalDependencies to sync");
}
packageJson.optionalDependencies = Object.fromEntries(
Object.keys(packageJson.optionalDependencies).map((packageName) => [
packageName,
packageJson.version,
]),
);
fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`);
NODE
npm install --package-lock-only --ignore-scripts
- name: Generate current platform binary package
if: steps.check.outputs.needs_update == 'true' && steps.pr_check.outputs.pr_exists == 'false'
run: npm run generate-packages -- --set-github-env
- name: Regenerate Hugo spec and types
if: steps.check.outputs.needs_update == 'true' && steps.pr_check.outputs.pr_exists == 'false'
run: npm run generate-types
- name: Stage updated files
if: steps.check.outputs.needs_update == 'true' && steps.pr_check.outputs.pr_exists == 'false'
run: git add package.json package-lock.json src/generated/types.ts src/generated/flags.json
- name: Commit and push
if: steps.check.outputs.needs_update == 'true' && steps.pr_check.outputs.pr_exists == 'false'
run: |
LATEST="${{ steps.hugo.outputs.version }}"
BRANCH_NAME="chore/hugo-v${LATEST}"
git commit -m "chore: bump to Hugo v${LATEST}"
git push origin "$BRANCH_NAME"
- name: Create Pull Request
if: steps.check.outputs.needs_update == 'true' && steps.pr_check.outputs.pr_exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
run: |
LATEST="${{ steps.hugo.outputs.version }}"
BRANCH_NAME="chore/hugo-v${LATEST}"
gh pr create \
--title "chore: bump to Hugo v${LATEST}" \
--body "## 🚀 New Hugo Release
This PR updates the package to match **Hugo v${LATEST}**.
### Changes
- Bumped package version to \`${LATEST}\`
- Regenerated committed type definitions and flag specs
### Hugo Release
📦 [Hugo v${LATEST} Release Notes](https://github.com/gohugoio/hugo/releases/tag/v${LATEST})
---
*This PR was automatically created by the [Bump Hugo Version](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow.*" \
--head "$BRANCH_NAME" \
--base main