Skip to content

chore: pin Jess 2.0.0-alpha.27 #129

chore: pin Jess 2.0.0-alpha.27

chore: pin Jess 2.0.0-alpha.27 #129

Workflow file for this run

name: Publish to NPM
on:
# Publish when a release PR is merged:
# master branch: "chore: release vX.Y.Z" PR → publishes latest
# alpha branch: "chore: release vX.Y.Z-alpha.N" PR → publishes alpha
# Both release PRs are created automatically by create-release-pr.yml.
pull_request:
types: [closed]
branches:
- master
- alpha
permissions:
id-token: write # Required for OIDC trusted publishing
contents: write # Required for creating releases and pushing tags
jobs:
publish:
name: Publish to NPM
runs-on: ubuntu-latest
# Only run when a release PR with the expected title is merged into master
# or alpha. Any other PR close (or merge without the right title) is
# silently skipped.
if: |
github.repository == 'less/less.js' &&
github.event.pull_request.merged == true &&
(
(github.event.pull_request.base.ref == 'master' &&
startsWith(github.event.pull_request.title, 'chore: release v')) ||
(github.event.pull_request.base.ref == 'alpha' &&
(
startsWith(github.event.pull_request.title, 'chore: release v') ||
startsWith(github.event.pull_request.title, 'chore: alpha release v')
))
)
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
# Check out the base branch (master or alpha) post-merge so the
# version bump from the release PR is already present.
ref: ${{ github.event.pull_request.base.ref }}
- name: Install pnpm
uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Validate release title version
env:
RELEASE_BASE: ${{ github.event.pull_request.base.ref }}
RELEASE_TITLE: ${{ github.event.pull_request.title }}
run: |
set -euo pipefail
TITLE_VERSION=$(node scripts/release-metadata.js parse-title "$RELEASE_BASE" "$RELEASE_TITLE")
PACKAGE_VERSION=$(node -p "require('./packages/less/package.json').version")
if [ "$TITLE_VERSION" != "$PACKAGE_VERSION" ]; then
echo "❌ ERROR: Release PR title requests v${TITLE_VERSION}, but package.json contains v${PACKAGE_VERSION}"
echo " Edit the release PR title and wait for the release-file sync check to update the branch before merging."
exit 1
fi
if [ "$RELEASE_BASE" = "alpha" ]; then
NPM_VERSION=$(npm view less dist-tags.alpha)
else
NPM_VERSION=$(npm view less version)
fi
node scripts/release-metadata.js validate "$RELEASE_BASE" "$TITLE_VERSION" "$NPM_VERSION"
echo "✅ Release title, package.json, and npm version checks agree on v${TITLE_VERSION}"
- name: Run Less v5 alpha support contract
run: pnpm run test:alpha
- name: Build
run: |
cd packages/less
pnpm run build
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Determine branch and tag type
id: branch-info
run: |
# Always a pull_request event; base.ref is master or alpha.
BRANCH="${{ github.event.pull_request.base.ref }}"
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
if [ "$BRANCH" = "alpha" ]; then
echo "is_alpha=true" >> $GITHUB_OUTPUT
echo "npm_tag=alpha" >> $GITHUB_OUTPUT
echo "release_type=prerelease" >> $GITHUB_OUTPUT
else
echo "is_alpha=false" >> $GITHUB_OUTPUT
echo "npm_tag=latest" >> $GITHUB_OUTPUT
echo "release_type=release" >> $GITHUB_OUTPUT
fi
- name: Validate alpha branch requirements
if: steps.branch-info.outputs.is_alpha == 'true'
run: |
# Fetch master branch (used by the alpha-base >= master version check)
git fetch origin master:master || true
# NOTE: The Less 5 alpha lives on a deliberately divergent branch (a
# Jess-powered rewrite). It does NOT carry every v4.x master hotfix, so
# a "alpha must contain all master commits" gate is the wrong invariant
# and blocked alpha publishes. The alpha-base >= master version check
# below is what actually prevents an alpha undercutting the 4.x latest.
# Check 2: Get current version and validate it contains 'alpha'
CURRENT_VERSION=$(node -p "require('./packages/less/package.json').version")
echo "📦 Current version: $CURRENT_VERSION"
if [[ ! "$CURRENT_VERSION" =~ -alpha\. ]]; then
echo "❌ ERROR: Alpha branch version must contain '-alpha.'"
echo " Current version: $CURRENT_VERSION"
echo " Expected format: X.Y.Z-alpha.N"
exit 1
fi
echo "✅ Version contains 'alpha' suffix"
# Check 3: Alpha base version must be >= master version
echo "🔍 Comparing alpha base version with master version..."
MASTER_VERSION=$(git show master:packages/less/package.json 2>/dev/null | node -p "try { JSON.parse(require('fs').readFileSync(0, 'utf-8')).version } catch(e) { '0.0.0' }" || echo "0.0.0")
if [ "$MASTER_VERSION" = "0.0.0" ]; then
echo "⚠️ Could not determine master version, skipping comparison"
else
echo "📦 Master version: $MASTER_VERSION"
# Extract base version (remove -alpha.X suffix)
ALPHA_BASE=$(echo "$CURRENT_VERSION" | sed 's/-alpha\.[0-9]*$//')
echo "📦 Alpha base version: $ALPHA_BASE"
# Compare versions using semver from root workspace
COMPARE_RESULT=$(node -e "
const semver = require('semver');
const alphaBase = process.argv[1];
const master = process.argv[2];
if (semver.lt(alphaBase, master)) {
console.log('ERROR');
} else {
console.log('OK');
}
" "$ALPHA_BASE" "$MASTER_VERSION" 2>/dev/null || echo "ERROR")
if [ "$COMPARE_RESULT" = "ERROR" ]; then
echo "❌ ERROR: Alpha base version ($ALPHA_BASE) is lower than master version ($MASTER_VERSION)"
echo " According to semver, alpha base version must be >= master version"
exit 1
fi
echo "✅ Alpha base version is >= master version"
fi
- name: Ensure npm 11.5.1 or later for trusted publishing
run: npm install -g npm@latest
- name: Bump version and publish
id: publish
env:
# Pass the resolved base branch name (master or alpha) so that
# bump-and-publish.js knows which branch it is publishing for.
GITHUB_REF_NAME: ${{ steps.branch-info.outputs.branch }}
run: |
pnpm run publish
# Extract version from package.json
VERSION=$(node -p "require('./packages/less/package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ steps.publish.outputs.tag }}"
VERSION="${{ steps.publish.outputs.version }}"
IS_ALPHA="${{ steps.branch-info.outputs.is_alpha }}"
if [ "$IS_ALPHA" = "true" ]; then
TITLE="Alpha Release $TAG"
PRERELEASE="--prerelease"
BODY="## Alpha Release
This Less 5 alpha is a Jess-powered compiler rewrite for early testing, not a drop-in Less 4.x replacement yet.
Highlights:
- CSS nesting is preserved by default.
- Less-style ampersand joining for BEM-style modifiers and similar selector patterns is still supported.
- Nested and extended selector output may use modern selectors such as :is(); selector compatibility remains part of the alpha feedback surface.
- Browser compilation is not included in this alpha; a new browser build mechanism will be introduced in a future alpha.
See CHANGELOG.md for the current supported surface and work-in-progress areas.
## Installation
\`\`\`bash
npm install less@${VERSION} --tag alpha
\`\`\`
Or:
\`\`\`bash
npm install less@alpha
\`\`\`"
else
TITLE="Release $TAG"
PRERELEASE=""
BODY="## Changes
See [CHANGELOG.md](https://github.com/less/less.js/blob/master/CHANGELOG.md) for details.
## Installation
\`\`\`bash
npm install less@${VERSION}
\`\`\`"
fi
ASSETS=()
if [ "$IS_ALPHA" != "true" ]; then
for asset in packages/less/dist/less.js packages/less/dist/less.min.js; do
if [ -f "$asset" ]; then
ASSETS+=("$asset")
fi
done
else
echo "Alpha release has no browser build assets; browser compilation will return through a future build mechanism."
fi
if gh release view "$TAG" &>/dev/null; then
echo "Release $TAG already exists"
if [ "${#ASSETS[@]}" -gt 0 ]; then
gh release upload "$TAG" "${ASSETS[@]}" --clobber
fi
else
gh release create "$TAG" \
--title "$TITLE" \
$PRERELEASE \
--notes "$BODY" \
"${ASSETS[@]}"
fi