|
| 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 }} |
0 commit comments