Skip to content
This repository was archived by the owner on Jul 4, 2026. It is now read-only.

Publish Package

Publish Package #13

Workflow file for this run

name: Publish Package
on:
workflow_dispatch:
inputs:
release_type:
description: "Website Release type (patch, minor, major, prepatch, preminor, premajor, prerelease)"
required: true
default: "patch"
type: choice
options:
- patch
- minor
- major
- prepatch
- preminor
- premajor
- prerelease
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Bump versions
run: |
echo "Bumping NPM package version (always patch)"
cd package
npm version patch --no-git-tag-version --force
cd ..
echo "Bumping website versions (${{ github.event.inputs.release_type }})"
# Always bump root, frontend, and backend versions
npm version ${{ github.event.inputs.release_type }} --no-git-tag-version --force
cd frontend
npm version ${{ github.event.inputs.release_type }} --no-git-tag-version --force
cd ..
cd backend
npm version ${{ github.event.inputs.release_type }} --no-git-tag-version --force
cd ..
- name: Get versions
id: get_versions
run: |
WEBSITE_VERSION=$(node -p "require('./package.json').version")
FRONTEND_VERSION=$(node -p "require('./frontend/package.json').version")
BACKEND_VERSION=$(node -p "require('./backend/package.json').version")
PACKAGE_VERSION=$(node -p "require('./package/package.json').version")
# Fail if versions diverge
if [ "$WEBSITE_VERSION" != "$FRONTEND_VERSION" ] || [ "$WEBSITE_VERSION" != "$BACKEND_VERSION" ]; then
echo "Error: Version mismatch detected!"
echo "Website: $WEBSITE_VERSION, Frontend: $FRONTEND_VERSION, Backend: $BACKEND_VERSION"
exit 1
fi
echo "website_version=$WEBSITE_VERSION" >> "$GITHUB_OUTPUT"
echo "frontend_version=$FRONTEND_VERSION" >> "$GITHUB_OUTPUT"
echo "backend_version=$BACKEND_VERSION" >> "$GITHUB_OUTPUT"
echo "package_version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
- name: Update docs and READMEs
run: |
W_VERSION=${{ steps.get_versions.outputs.website_version }}
F_VERSION=${{ steps.get_versions.outputs.frontend_version }}
B_VERSION=${{ steps.get_versions.outputs.backend_version }}
P_VERSION=${{ steps.get_versions.outputs.package_version }}
export W_VERSION F_VERSION B_VERSION P_VERSION
node - <<'EOF'
const fs = require('fs');
const wVersion = process.env.W_VERSION;
const fVersion = process.env.F_VERSION;
const bVersion = process.env.B_VERSION;
const pVersion = process.env.P_VERSION;
// update backend api JSON docs with website version
const jsonPath = 'backend/docs/api-documentation.json';
if (fs.existsSync(jsonPath)) {
const doc = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
doc.info = doc.info || {};
doc.info.version = wVersion;
fs.writeFileSync(jsonPath, JSON.stringify(doc, null, 2));
}
const updateReadme = (p, v) => {
if (fs.existsSync(p)) {
let c = fs.readFileSync(p, 'utf8');
if (c.includes('**Version:**')) {
c = c.replace(/\*\*Version:\*\* .*/, `**Version:** ${v}`);
} else {
const h1Match = c.match(/^# .*/m);
if (h1Match) {
c = c.replace(/^# .*/m, `${h1Match[0]}\n\n**Version:** ${v}`);
} else {
c = `**Version:** ${v}\n\n${c}`;
}
}
fs.writeFileSync(p, c);
}
};
// Update READMEs with appropriate versions
updateReadme('package/README.md', pVersion);
updateReadme('README.md', wVersion);
updateReadme('frontend/README.md', fVersion);
updateReadme('backend/docs/README.md', bVersion);
EOF
- name: Commit version changes
id: commit_versions
run: |
git add -u
if git diff --cached --quiet; then
echo "did_commit=false" >> $GITHUB_OUTPUT
exit 0
fi
git commit -m "chore: bump versions (Website: v${{ steps.get_versions.outputs.website_version }}, Package: v${{ steps.get_versions.outputs.package_version }})"
TAG_NAME="v${{ steps.get_versions.outputs.website_version }}"
if git rev-parse -q --verify "refs/tags/$TAG_NAME"; then
echo "Tag $TAG_NAME already exists"
exit 1
else
echo "Creating new tag $TAG_NAME"
git tag -a "$TAG_NAME" -m "Release $TAG_NAME"
echo "did_commit=true" >> $GITHUB_OUTPUT
fi
- name: Push changes and tags
if: steps.commit_versions.outputs.did_commit == 'true'
run: git push --follow-tags
- name: Create GitHub Release
if: steps.commit_versions.outputs.did_commit == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.get_versions.outputs.website_version }}
name: Release v${{ steps.get_versions.outputs.website_version }}
generate_release_notes: true
draft: false
prerelease: ${{ contains(github.event.inputs.release_type, 'pre') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build package
run: |
cd package
pnpm install
pnpm build
- name: Publish dkutils-cli to npm
run: |
cd package
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}