This repository was archived by the owner on Feb 10, 2026. It is now read-only.
Deploy Package #19
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: Deploy Package | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_type: | |
| description: "Version bump type" | |
| required: true | |
| default: "patch" | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| - none | |
| deploy_target: | |
| description: "Deploy target" | |
| required: true | |
| default: "both" | |
| type: choice | |
| options: | |
| - both | |
| - npm | |
| - github | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| env: | |
| NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN }} | |
| BUN_AUTH_TOKEN: ${{ secrets.GH_TOKEN }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version-file: "package.json" | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Build package | |
| run: bun run build | |
| - name: Lint code | |
| run: bun run lint | |
| - name: Bump version | |
| if: github.event.inputs.version_type != 'none' | |
| run: bun bump ${{ github.event.inputs.version_type }} | |
| - name: Get package version | |
| id: package-version | |
| run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
| - name: Generate documentation | |
| run: bun run docs | |
| - name: Backup package.json | |
| run: cp package.json package.json.backup | |
| - name: Clean package.json for publish | |
| run: bun pm pkg delete scripts devDependencies packageManager | |
| - name: Publish to NPM Packages | |
| if: github.event.inputs.deploy_target == 'npm' || github.event.inputs.deploy_target == 'both' | |
| run: | | |
| echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
| bun publish --registry https://registry.npmjs.org | |
| - name: Publish to GitHub Packages | |
| if: github.event.inputs.deploy_target == 'github' || github.event.inputs.deploy_target == 'both' | |
| run: | | |
| bun pm pkg set name=@cmru-computer-science-66/cmru-api | |
| echo "//npm.pkg.github.com/:_authToken=${{ secrets.GH_TOKEN }}" > ~/.npmrc | |
| echo "@cmru-computer-science-66:registry=https://npm.pkg.github.com" >> ~/.npmrc | |
| npm publish --registry https://npm.pkg.github.com | |
| - name: Restore package.json | |
| run: mv package.json.backup package.json | |
| - name: Generate changelog | |
| id: changelog | |
| run: | | |
| PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -z "$PREVIOUS_TAG" ]; then | |
| CHANGELOG="Initial release" | |
| echo "previous_tag=" >> $GITHUB_OUTPUT | |
| else | |
| ALL_COMMITS=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"* %s by @%an (%h)" --no-merges | grep -v "^* Release v") | |
| ADD_COMMITS=$(echo "$ALL_COMMITS" | grep "^* Add " || true) | |
| UPDATE_COMMITS=$(echo "$ALL_COMMITS" | grep "^* Update " || true) | |
| FIX_COMMITS=$(echo "$ALL_COMMITS" | grep "^* Fix " || true) | |
| OTHER_COMMITS=$(echo "$ALL_COMMITS" | grep -v "^* Add " | grep -v "^* Update " | grep -v "^* Fix " || true) | |
| CHANGELOG="" | |
| [ -n "$ADD_COMMITS" ] && CHANGELOG="$ADD_COMMITS" | |
| [ -n "$UPDATE_COMMITS" ] && CHANGELOG="$CHANGELOG"$'\n'"$UPDATE_COMMITS" | |
| [ -n "$FIX_COMMITS" ] && CHANGELOG="$CHANGELOG"$'\n'"$FIX_COMMITS" | |
| [ -n "$OTHER_COMMITS" ] && CHANGELOG="$CHANGELOG"$'\n'"$OTHER_COMMITS" | |
| CHANGELOG=$(echo "$CHANGELOG" | sed '/^$/d') | |
| echo "previous_tag=${PREVIOUS_TAG}" >> $GITHUB_OUTPUT | |
| fi | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| echo "$CHANGELOG" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.package-version.outputs.version }} | |
| name: v${{ steps.package-version.outputs.version }} | |
| body: | | |
| ## ✨ What's Changed | |
| ${{ steps.changelog.outputs.changelog }} | |
| ${{ steps.changelog.outputs.previous_tag && format('**Full Changelog**: https://github.com/{0}/compare/{1}...v{2}', github.repository, steps.changelog.outputs.previous_tag, steps.package-version.outputs.version) || '' }} | |
| draft: false | |
| prerelease: false | |
| token: ${{ secrets.GH_TOKEN }} | |
| - name: Automatically Commit Changes | |
| uses: stefanzweifel/git-auto-commit-action@v7 | |
| with: | |
| push_options: "--force" | |
| commit_options: "--no-verify" | |
| commit_message: "Release v${{ steps.package-version.outputs.version }}" | |
| skip_checkout: true | |
| - name: Deploy documentation to docs branch | |
| uses: peaceiris/actions-gh-pages@v4.0.0 | |
| with: | |
| personal_token: ${{ secrets.GH_TOKEN }} | |
| publish_dir: ./public | |
| publish_branch: docs | |
| user_name: "github-actions[bot]" | |
| user_email: "github-actions[bot]@users.noreply.github.com" | |
| enable_jekyll: true |