Skip to content

Commit f426fc3

Browse files
committed
Add github workflow to publish prerelease of litlytics lib
1 parent 3e1bb13 commit f426fc3

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed

.github/workflows/prerelease-lib.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Prerelease litlytics library
2+
3+
on:
4+
workflow_run:
5+
# Run after "Test and lint" workflow
6+
workflows: ['Test and lint']
7+
types:
8+
- completed # Only when it's completed
9+
branches:
10+
- main # Only run the publish workflow for pushes to main
11+
12+
jobs:
13+
publish-lib:
14+
environment: Github CI
15+
if: ${{ github.event.workflow_run.conclusion == 'success' }} # Only proceed if the tests passed
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
# Check for changes in ./packages/litlytics
23+
- name: Check if changed
24+
id: changes
25+
run: |
26+
# Check if any files changed in the specified directory
27+
if git diff --quiet HEAD^ HEAD ./packages/litlytics; then
28+
echo "No changes in ./packages/litlytics. Skipping publish."
29+
echo "should_publish=false" >> $GITHUB_ENV
30+
else
31+
echo "Changes detected in ./packages/litlytics."
32+
echo "should_publish=true" >> $GITHUB_ENV
33+
34+
# Stop if no changes detected
35+
- name: Stop if no changes
36+
if: ${{ env.should_publish == 'false' }}
37+
run: exit 0
38+
39+
# install node (for npm utils)
40+
- name: Install node for npm checks
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: 22
44+
45+
# install bun
46+
- name: Install bun for deployment
47+
uses: oven-sh/setup-bun@v2
48+
with:
49+
bun-version: latest
50+
51+
# Install dependencies
52+
- name: Install dependencies
53+
working-directory: ./packages/litlytics
54+
run: bun install --frozen-lockfile
55+
56+
# Build package
57+
- name: Build package
58+
working-directory: ./packages/litlytics
59+
run: bun run build
60+
61+
# Determine @next version and update package.json
62+
- name: Determine @next version
63+
id: get_version
64+
working-directory: ./packages/litlytics
65+
run: |
66+
# Extract the current version from package.json
67+
# Fetch the latest @next version from npm
68+
current_version=$(node -pe "require('./package.json').version")
69+
latest_next_version=$(npm show litlytics@next version || $current_version)
70+
echo "Latest @next version: $latest_next_version"
71+
72+
# Bump the version by minor update and append `-next`
73+
# We now use bash for splitting the version
74+
major=$(echo "$latest_next_version" | cut -d'.' -f1)
75+
minor=$(echo "$latest_next_version" | cut -d'.' -f2)
76+
patch=$(echo "$latest_next_version" | cut -d'.' -f3)
77+
78+
next_patch=$((patch + 1))
79+
next_version="$major.$minor.$next_patch-next"
80+
81+
echo "Next version: $next_version"
82+
83+
# Update package.json with the new version
84+
npm version "$next_version" --no-git-tag-version
85+
86+
echo "version=$next_version" >> $GITHUB_ENV
87+
88+
# install and publish if local version is not the same as published
89+
- name: publish
90+
if: ${{ steps.versions.outputs.current != steps.versions.outputs.new }}
91+
working-directory: ./packages/litlytics
92+
run: bun publish --access public --tag next
93+
env:
94+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test-lint.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
paths-ignore:
66
- '**/*.md' # Ignore changes to markdown files
77
pull_request:
8-
branches:
9-
- main
108
paths-ignore:
119
- '**/*.md' # Ignore changes to markdown files
1210

@@ -29,9 +27,9 @@ jobs:
2927
# install deps
3028
- name: Install lib deps
3129
working-directory: ./packages/litlytics
32-
run: bun install
30+
run: bun install --frozen-lockfile
3331
- name: Install app deps
34-
run: bun install
32+
run: bun install --frozen-lockfile
3533

3634
# lib lint/check/test
3735
- name: Run lib typecheck

packages/litlytics/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"module": "dist/litlytics.js",
44
"types": "litlytics.ts",
55
"type": "module",
6+
"version": "0.2.0",
67
"scripts": {
78
"build": "bun run build.ts",
89
"typecheck": "tsc",

0 commit comments

Comments
 (0)