This repository was archived by the owner on Feb 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (127 loc) · 6.09 KB
/
deploy.yml
File metadata and controls
149 lines (127 loc) · 6.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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 lint-staged 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: 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: 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: 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