This repository was archived by the owner on Jul 4, 2026. It is now read-only.
Publish Package #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Package | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_type: | |
| description: "Release type" | |
| required: true | |
| default: "patch" | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| - prepatch | |
| - preminor | |
| - premajor | |
| - prerelease | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: 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: Detect changes and bump versions | |
| run: | | |
| # Fetch tags and get the last release tag | |
| git fetch --tags | |
| LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -n "$LAST_TAG" ]; then | |
| BASE=$(git rev-list -n1 "$LAST_TAG") | |
| echo "Using base commit $BASE from last tag $LAST_TAG" | |
| else | |
| BASE=$(git rev-parse --verify 4b825dc642cb6eb9a060e54bf8d69288fbee4904) | |
| echo "No tags found, using empty-tree SHA $BASE" | |
| fi | |
| CHANGED_FILES=$(git diff --name-only "$BASE" HEAD) | |
| # Determine which workspaces need version bumps | |
| if echo "$CHANGED_FILES" | grep -q "^frontend/"; then | |
| echo "Frontend changes detected, bumping frontend version" | |
| cd frontend | |
| npm version ${{ github.event.inputs.release_type }} --no-git-tag-version | |
| cd .. | |
| fi | |
| if echo "$CHANGED_FILES" | grep -q "^backend/"; then | |
| echo "Backend changes detected, bumping backend version" | |
| cd backend | |
| npm version ${{ github.event.inputs.release_type }} --no-git-tag-version | |
| cd .. | |
| fi | |
| # Always bump root version | |
| npm version ${{ github.event.inputs.release_type }} --no-git-tag-version | |
| - name: Get version | |
| id: get_version | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Update docs version | |
| run: | | |
| VERSION=${{ steps.get_version.outputs.version }} | |
| export VERSION | |
| node - <<'EOF' | |
| const fs = require('fs'); | |
| const version = process.env.VERSION; | |
| // update backend api JSON docs | |
| 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 = version; | |
| fs.writeFileSync(jsonPath, JSON.stringify(doc, null, 2)); | |
| } | |
| // update any README files with Version: lines | |
| const updateReadme = (p) => { | |
| if (fs.existsSync(p)) { | |
| let c = fs.readFileSync(p, 'utf8'); | |
| c = c.replace(/\*\*Version:\*\* .*/, `**Version:** ${version}`); | |
| fs.writeFileSync(p, c); | |
| } | |
| }; | |
| updateReadme('backend/docs/README.md'); | |
| updateReadme('README.md'); | |
| updateReadme('frontend/README.md'); | |
| EOF | |
| - name: Commit version changes | |
| id: commit_versions | |
| run: | | |
| FILES="" | |
| if [ -f package.json ]; then FILES="$FILES package.json"; fi | |
| if [ -f frontend/package.json ]; then FILES="$FILES frontend/package.json"; fi | |
| if [ -f backend/package.json ]; then FILES="$FILES backend/package.json"; fi | |
| if [ -f backend/docs/api-documentation.json ]; then FILES="$FILES backend/docs/api-documentation.json"; fi | |
| if [ -f backend/docs/README.md ]; then FILES="$FILES backend/docs/README.md"; fi | |
| if [ -f README.md ]; then FILES="$FILES README.md"; fi | |
| if [ -f frontend/README.md ]; then FILES="$FILES frontend/README.md"; fi | |
| if [ -n "$FILES" ]; then git add $FILES; fi | |
| if git diff --cached --quiet; then | |
| echo "did_commit=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| git commit -m "chore: bump versions for ${{ github.event.inputs.release_type }} v${{ steps.get_version.outputs.version }} release" | |
| # Check if tag already exists | |
| TAG_NAME="v${{ steps.get_version.outputs.version }}" | |
| did_commit=false | |
| if git rev-parse -q --verify "refs/tags/$TAG_NAME"; then | |
| echo "Tag $TAG_NAME already exists, skipping tag creation" | |
| # Only set did_commit=true if we actually made a new commit | |
| if [ "$(git rev-parse HEAD)" != "$(git rev-parse HEAD~1)" ]; then | |
| echo "did_commit=true" >> $GITHUB_OUTPUT | |
| fi | |
| 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_version.outputs.version }} | |
| name: Release v${{ steps.get_version.outputs.version }} | |
| generate_release_notes: true | |
| draft: false | |
| prerelease: ${{ contains(github.event.inputs.release_type, 'pre') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |