Skip to content

Bump Hono versions

Bump Hono versions #13

name: Sync Templates
on:
push:
branches: [main]
paths:
- "packages/fraq/package.json"
- ".github/workflows/sync-templates.yml"
workflow_dispatch:
inputs:
version:
description: "Fraq version to sync. Defaults to packages/fraq/package.json."
required: false
type: string
permissions:
contents: read
concurrency:
group: sync-templates-${{ github.event_name == 'workflow_dispatch' && inputs.version || github.sha }}
cancel-in-progress: false
jobs:
detect:
name: Detect Fraq version
runs-on: ubuntu-latest
outputs:
npm_available: ${{ steps.npm.outputs.available }}
should_sync: ${{ steps.result.outputs.should_sync }}
version: ${{ steps.version.outputs.version }}
version_changed: ${{ steps.version.outputs.changed }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 22
- name: Resolve Fraq version
id: version
env:
BEFORE_SHA: ${{ github.event.before }}
EVENT_NAME: ${{ github.event_name }}
INPUT_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.version || '' }}
run: |
node <<'NODE'
const { execFileSync } = require("node:child_process");
const { appendFileSync, readFileSync } = require("node:fs");
const packagePath = "packages/fraq/package.json";
const currentPackage = JSON.parse(readFileSync(packagePath, "utf8"));
const inputVersion = process.env.INPUT_VERSION.trim();
const version = inputVersion || currentPackage.version;
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(version)) {
console.error(`Invalid Fraq version: ${version}`);
process.exit(1);
}
let changed = process.env.EVENT_NAME === "workflow_dispatch";
if (process.env.EVENT_NAME === "push") {
const beforeSha = process.env.BEFORE_SHA;
if (!beforeSha || /^0+$/.test(beforeSha)) {
changed = true;
} else {
try {
const previousPackage = JSON.parse(
execFileSync("git", ["show", `${beforeSha}:${packagePath}`], {
encoding: "utf8",
}),
);
changed = previousPackage.version !== currentPackage.version;
} catch (error) {
console.warn(`Could not read previous ${packagePath}: ${error.message}`);
changed = true;
}
}
}
appendFileSync(process.env.GITHUB_OUTPUT, `version=${version}\n`);
appendFileSync(process.env.GITHUB_OUTPUT, `changed=${changed}\n`);
console.log(`Fraq version: ${version}`);
console.log(`Version changed or manually requested: ${changed}`);
NODE
- name: Wait for npm registry
id: npm
if: steps.version.outputs.changed == 'true'
env:
EVENT_NAME: ${{ github.event_name }}
FRAQ_VERSION: ${{ steps.version.outputs.version }}
run: |
for attempt in {1..30}; do
resolved="$(npm view "@fraqjs/fraq@${FRAQ_VERSION}" version 2>/dev/null || true)"
if [ "${resolved}" = "${FRAQ_VERSION}" ]; then
echo "available=true" >> "${GITHUB_OUTPUT}"
echo "npm can resolve @fraqjs/fraq@${FRAQ_VERSION}"
exit 0
fi
echo "Attempt ${attempt}/30: @fraqjs/fraq@${FRAQ_VERSION} is not visible on npm yet."
sleep 20
done
echo "available=false" >> "${GITHUB_OUTPUT}"
if [ "${EVENT_NAME}" = "workflow_dispatch" ]; then
echo "::error::npm cannot resolve @fraqjs/fraq@${FRAQ_VERSION}."
exit 1
fi
echo "::notice::Skipping template sync because npm cannot resolve @fraqjs/fraq@${FRAQ_VERSION}."
- name: Decide whether to sync
id: result
env:
NPM_AVAILABLE: ${{ steps.npm.outputs.available }}
VERSION_CHANGED: ${{ steps.version.outputs.changed }}
run: |
if [ "${VERSION_CHANGED}" = "true" ] && [ "${NPM_AVAILABLE}" = "true" ]; then
echo "should_sync=true" >> "${GITHUB_OUTPUT}"
else
echo "should_sync=false" >> "${GITHUB_OUTPUT}"
fi
update-template:
name: Update ${{ matrix.repository }}
needs: detect
if: needs.detect.outputs.should_sync == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
repository:
- starter-template
- plugin-template
env:
FRAQ_VERSION: ${{ needs.detect.outputs.version }}
steps:
- name: Check token
env:
TEMPLATE_SYNC_TOKEN: ${{ secrets.FRAQ_TEMPLATE_SYNC_TOKEN }}
run: |
if [ -z "${TEMPLATE_SYNC_TOKEN}" ]; then
echo "::error::Missing FRAQ_TEMPLATE_SYNC_TOKEN. Add a token with contents:write access to fraqjs/${{ matrix.repository }}."
exit 1
fi
- name: Checkout template
uses: actions/checkout@v6
with:
repository: fraqjs/${{ matrix.repository }}
ref: main
token: ${{ secrets.FRAQ_TEMPLATE_SYNC_TOKEN }}
path: template
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 22
- name: Install pnpm
uses: pnpm/action-setup@v5
with:
version: 11.9.0
run_install: false
- name: Update Fraq dependency
working-directory: template
run: |
node <<'NODE'
const { readFileSync, writeFileSync } = require("node:fs");
const fraqRange = `^${process.env.FRAQ_VERSION}`;
const packagePath = "package.json";
const packageJson = JSON.parse(readFileSync(packagePath, "utf8"));
const dependencyFields = [
"dependencies",
"devDependencies",
"peerDependencies",
"optionalDependencies",
];
let updated = false;
for (const field of dependencyFields) {
if (packageJson[field]?.["@fraqjs/fraq"]) {
packageJson[field]["@fraqjs/fraq"] = fraqRange;
updated = true;
}
}
if (!updated) {
console.error("No @fraqjs/fraq dependency was found in package.json.");
process.exit(1);
}
writeFileSync(packagePath, `${JSON.stringify(packageJson, null, 2)}\n`);
NODE
- name: Update lockfile
working-directory: template
run: pnpm install --lockfile-only --ignore-scripts
- name: Commit and push
working-directory: template
run: |
if git diff --quiet -- package.json pnpm-lock.yaml; then
echo "fraqjs/${{ matrix.repository }} is already on @fraqjs/fraq@${FRAQ_VERSION}."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json pnpm-lock.yaml
git commit -m "chore: update Fraq to ${FRAQ_VERSION}"
git push origin HEAD:main