Skip to content

Commit 73c7f8f

Browse files
authored
Merge pull request #188 from ls1intum/feature/make-library-publishable
Feature/make library publishable
2 parents 756083c + cd5f47b commit 73c7f8f

File tree

8 files changed

+347
-6
lines changed

8 files changed

+347
-6
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Publish Library Minor Version
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
publish-patch:
8+
runs-on: ubuntu-latest
9+
defaults:
10+
run:
11+
working-directory: library
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
token: ${{ secrets.GITHUB_TOKEN }} # Needed for pushing changes and creating PR
17+
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 22
21+
registry-url: https://registry.npmjs.org/
22+
23+
- name: Install dependencies in root
24+
run: npm install
25+
working-directory: ..
26+
27+
- name: Bump Minor version and create branch
28+
run: |
29+
# Bump version in library/package.json
30+
npm version preminor --no-git-tag-version --preid=alpha > /dev/null
31+
new_version=$(node -p "require('./package.json').version")
32+
echo "New version: $new_version"
33+
34+
# Create and checkout new branch
35+
branch_name="chore/version-bump-minor-${new_version}"
36+
git checkout -b "$branch_name"
37+
38+
# Configure git
39+
git config user.name "github-actions"
40+
git config user.email "[email protected]"
41+
42+
# Add package.json from library and package-lock.json from root
43+
files_to_add="package.json"
44+
root_package_lock="../package-lock.json"
45+
if [ -f "$root_package_lock" ]; then
46+
files_to_add="$files_to_add $root_package_lock"
47+
else
48+
echo "Warning: $root_package_lock not found in root directory"
49+
fi
50+
git add $files_to_add
51+
git commit -m "chore(release): bump preminor version to $new_version"
52+
53+
# Push new branch
54+
git push origin "$branch_name"
55+
56+
# Store branch name and version for next steps
57+
echo "BRANCH_NAME=$branch_name" >> $GITHUB_ENV
58+
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
59+
60+
- name: Build
61+
run: npm run build
62+
63+
- name: Publish to npm
64+
run: npm publish --access public --tag latest
65+
env:
66+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
67+
68+
- name: Create Pull Request
69+
run: |
70+
gh pr create \
71+
--base main \
72+
--head "${{ env.BRANCH_NAME }}" \
73+
--title "chore: bump minor version to ${{ env.NEW_VERSION }}" \
74+
--body "Automated version bump to ${{ env.NEW_VERSION }} and npm publish with alpha tag"
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Publish Library Patch Version
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
publish-patch:
8+
runs-on: ubuntu-latest
9+
defaults:
10+
run:
11+
working-directory: library
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
token: ${{ secrets.GITHUB_TOKEN }} # Needed for pushing changes and creating PR
17+
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 22
21+
registry-url: https://registry.npmjs.org/
22+
23+
- name: Install dependencies in root
24+
run: npm install
25+
working-directory: ..
26+
27+
- name: Bump patch version and create branch
28+
run: |
29+
# Bump version in library/package.json
30+
npm version prepatch --no-git-tag-version --preid=alpha > /dev/null
31+
new_version=$(node -p "require('./package.json').version")
32+
echo "New version: $new_version"
33+
34+
# Create and checkout new branch
35+
branch_name="chore/version-bump-patch-${new_version}"
36+
git checkout -b "$branch_name"
37+
38+
# Configure git
39+
git config user.name "github-actions"
40+
git config user.email "[email protected]"
41+
42+
# Add package.json from library and package-lock.json from root
43+
files_to_add="package.json"
44+
root_package_lock="../package-lock.json"
45+
if [ -f "$root_package_lock" ]; then
46+
files_to_add="$files_to_add $root_package_lock"
47+
else
48+
echo "Warning: $root_package_lock not found in root directory"
49+
fi
50+
git add $files_to_add
51+
git commit -m "chore(release): bump prepatch version to $new_version"
52+
53+
# Push new branch
54+
git push origin "$branch_name"
55+
56+
# Store branch name and version for next steps
57+
echo "BRANCH_NAME=$branch_name" >> $GITHUB_ENV
58+
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
59+
60+
- name: Build
61+
run: npm run build
62+
63+
- name: Publish to npm
64+
run: npm publish --access public --tag latest
65+
env:
66+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
67+
68+
- name: Create Pull Request
69+
run: |
70+
gh pr create \
71+
--base main \
72+
--head "${{ env.BRANCH_NAME }}" \
73+
--title "chore: bump patch version to ${{ env.NEW_VERSION }}" \
74+
--body "Automated version bump to ${{ env.NEW_VERSION }} and npm publish with alpha tag"
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,29 @@ Run the container with docker compose:
216216
docker compose -f ./docker/compose.local.yml up -d
217217
```
218218

219+
## Publish Library in NPM
220+
Publish a new patch or minor version of the library package to npm using npm scripts or GitHub Actions.\
221+
Alpha prerelease versions (e.g., 4.0.3-alpha.0) are created with prepatch or preminor, later updated to stable (e.g., 4.0.3 or 4.1.0).
222+
### Version Increments
223+
Patch: 4.0.2 → 4.0.3-alpha.0 → 4.0.3 (bug fixes).\
224+
Minor: 4.0.2 → 4.1.0-alpha.0 → 4.1.0 (new features).
225+
### Local Publishing
226+
Run from the monorepo root:
227+
```bash
228+
npm run publish:library:patch # For patch (scripts/publish-library-patch.sh)
229+
npm run publish:library:minor # For minor (scripts/publish-library-minor.sh)
230+
```
231+
232+
### GitHub Actions
233+
Trigger the Publish Library Patch Version workflow (.github/workflows/publish-library-patch.yml) in GitHub Actions.\
234+
Same as local script but automated.\
235+
There is also workflow for minor version bump
236+
237+
Requires: NPM_TOKEN in repository secrets.\
238+
Currently temporarily classic token from npm is used
239+
### Notes
240+
Alpha versions are for testing; update to stable after PR approval.
241+
219242
## Troubleshooting
220243

221244
- If you encounter issues with Node.js versions, ensure you have the correct version installed by running:

library/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"name": "@tumaet/apollon",
3-
"version": "4.0.0-alpha.0",
3+
"version": "4.0.3-alpha.0",
44
"type": "module",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
7+
"publishConfig": {
8+
"access": "public"
9+
},
710
"files": [
811
"dist"
912
],
@@ -22,11 +25,11 @@
2225
"@mui/material": "6.3.1",
2326
"@types/node": "22.13.8",
2427
"@xyflow/react": "12.3.6",
28+
"react": "18.3.1",
29+
"react-dom": "18.3.1",
2530
"uuid": "11.0.3",
2631
"y-websocket": "2.1.0",
27-
"zustand": "5.0.3",
28-
"react": "18.3.1",
29-
"react-dom": "18.3.1"
32+
"zustand": "5.0.3"
3033
},
3134
"devDependencies": {
3235
"@eslint/js": "9.17.0",

package-lock.json

Lines changed: 66 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
"capacitor:open:android": "npx cap open android",
3535
"capacitor:open:ios": "npx cap open ios",
3636
"capacitor:assets:generate:ios": "npx capacitor-assets generate --ios",
37-
"capacitor:assets:generate:android": "npx capacitor-assets generate --android"
37+
"capacitor:assets:generate:android": "npx capacitor-assets generate --android",
38+
"publish:library:patch": "./scripts/publish-library-patch.sh",
39+
"publish:library:minor": "./scripts/publish-library-minor.sh"
3840
},
3941
"license": "MIT",
4042
"engines": {

scripts/publish-library-minor.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
set -e
3+
4+
LIB_DIR="library"
5+
cd "$LIB_DIR"
6+
7+
echo "📦 Bumping minor version and preparing PR"
8+
9+
# 1. Bump version (no tag/commit)
10+
npm version preminor --no-git-tag-version --preid=alpha > /dev/null
11+
new_version=$(node -p "require('./package.json').version")
12+
echo "New version: $new_version"
13+
14+
# 2. Build and publish
15+
npm run build > /dev/null
16+
npm publish --access public --tag latest
17+
18+
# 3. Create a branch
19+
branch_name="chore/version-bump-minor-${new_version}"
20+
git checkout -b "$branch_name"
21+
22+
# 4. Add and commit changes
23+
# Add package.json from the library directory
24+
# Add package-lock.json from the root directory
25+
files_to_add="package.json"
26+
root_package_lock="../package-lock.json"
27+
if [ -f "$root_package_lock" ]; then
28+
files_to_add="$files_to_add $root_package_lock"
29+
else
30+
echo "Warning: $root_package_lock not found in root directory"
31+
fi
32+
git add $files_to_add
33+
git commit -m "chore: bump minor version to $new_version"
34+
35+
echo "✅ Changes committed to branch: $branch_name"
36+
37+
# 5. Push branch
38+
git push -u origin "$branch_name"
39+
40+
# 6. Suggest PR URL
41+
repo_url=$(git config --get remote.origin.url | sed 's/.git$//' | sed 's/[email protected]:/https:\/\/github.com\//' | sed 's#^git://#https://#')
42+
pr_url="${repo_url}/compare/main...${branch_name}?expand=1"
43+
44+
echo ""
45+
echo "🔗 PR ready to be created:"
46+
echo "$pr_url"
47+
echo ""
48+
echo "👉 Click the link above or paste it in your browser to create a pull request."

0 commit comments

Comments
 (0)