Skip to content

Bump litlytics lib to 0.4.2 #31

Bump litlytics lib to 0.4.2

Bump litlytics lib to 0.4.2 #31

name: Prerelease litlytics library
on:
push:
branches: ['main'] # Only run the publish workflow for pushes to main
jobs:
publish-lib-prerelease:
environment: Github CI
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
# run test-lint
- name: Test and lint
uses: ./.github/actions/test-lint
# Check for changes in ./packages/litlytics
- name: Check if changed
id: changes
run: |
# Check if any files changed in the specified directory
if git diff --quiet HEAD^ HEAD ./packages/litlytics; then
echo "No changes in ./packages/litlytics. Skipping publish."
echo "should_publish=false" >> $GITHUB_ENV
else
echo "Changes detected in ./packages/litlytics."
echo "should_publish=true" >> $GITHUB_ENV
fi
# install node (for npm utils)
- name: Install node for npm checks
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
# install bun
- name: Install bun for deployment
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
# Install dependencies
- name: Install dependencies
working-directory: ./packages/litlytics
run: bun install --frozen-lockfile
# Build package
- name: Build package
working-directory: ./packages/litlytics
run: bun run build
# Determine @next version and update package.json
- name: Determine @next version
id: get_version
working-directory: ./packages/litlytics
run: |
# Extract the current version from package.json
# Fetch the latest @next version from npm
current_version=$(node -pe "require('./package.json').version")
latest_next_version=$(npm show litlytics@next version || $current_version)
echo "Latest @next version: $latest_next_version"
# Bump the version by minor update and append `-next`
# We now use bash for splitting the version
major=$(echo "$latest_next_version" | cut -d'.' -f1)
minor=$(echo "$latest_next_version" | cut -d'.' -f2)
patch=$(echo "$latest_next_version" | cut -d'.' -f3)
next_patch=$((patch + 1))
next_version="$major.$minor.$next_patch-next"
echo "Next version: $next_version"
# Update package.json with the new version
npm version "$next_version" --no-git-tag-version
echo "version=$next_version" >> $GITHUB_ENV
# install and publish if local version is not the same as published
- name: publish
if: ${{ env.should_publish == 'true' }}
working-directory: ./packages/litlytics
run: npm publish --access public --tag next
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}