Release #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| release: | |
| types: [released] | |
| workflow_dispatch: | |
| inputs: | |
| channel: | |
| description: 'Publish channel' | |
| required: true | |
| default: 'dev' | |
| type: choice | |
| options: | |
| - latest | |
| - dev | |
| version: | |
| description: 'Version to publish (leave empty to use package.json version)' | |
| required: false | |
| type: string | |
| jobs: | |
| release: | |
| name: Publish to NPM | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: 'package.json' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Validate and set channel | |
| id: channel | |
| run: | | |
| CHANNEL="${{ github.event.inputs.channel || 'latest' }}" | |
| if [ "${{ github.event_name }}" = "release" ]; then | |
| BRANCH="${{ github.event.release.target_commitish }}" | |
| else | |
| BRANCH="${{ github.ref_name }}" | |
| fi | |
| if [ "$CHANNEL" = "latest" ] && [ "$BRANCH" != "master" ]; then | |
| echo "Error: 'latest' channel can only be published from 'master'." | |
| echo "Current branch: $BRANCH" | |
| exit 1 | |
| fi | |
| echo "channel=$CHANNEL" >> $GITHUB_OUTPUT | |
| echo "branch=$BRANCH" >> $GITHUB_OUTPUT | |
| echo "Publishing to channel: $CHANNEL from branch: $BRANCH" | |
| - name: Validate and set version | |
| id: version | |
| env: | |
| INPUT_VERSION: ${{ github.event.inputs.version }} | |
| CHANNEL: ${{ steps.channel.outputs.channel }} | |
| BRANCH: ${{ steps.channel.outputs.branch }} | |
| run: | | |
| if [ -n "$INPUT_VERSION" ]; then | |
| echo "Using provided version: $INPUT_VERSION" | |
| if [ "$BRANCH" = "master" ] && [ "$CHANNEL" = "latest" ]; then | |
| echo "Error: Cannot override version for 'latest' on master. Use package.json version." | |
| exit 1 | |
| fi | |
| if [ "$CHANNEL" = "dev" ]; then | |
| if ! echo "$INPUT_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+-dev\.[0-9]+$'; then | |
| echo "Error: Dev versions must match x.y.z-dev.N (e.g. 1.0.1-dev.0)" | |
| exit 1 | |
| fi | |
| fi | |
| echo "version=$INPUT_VERSION" >> $GITHUB_OUTPUT | |
| echo "has_version=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No version provided, using package.json" | |
| echo "has_version=false" >> $GITHUB_OUTPUT | |
| fi | |
| - run: yarn install | |
| - name: Install Playwright | |
| run: yarn workspace @nipple/tests playwright install --with-deps | |
| - name: Set version | |
| if: steps.version.outputs.has_version == 'true' | |
| env: | |
| RELEASE_VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| cd packages/nipplejs | |
| npm version "$RELEASE_VERSION" --no-git-tag-version | |
| - name: Commit version bump | |
| if: steps.version.outputs.has_version == 'true' | |
| env: | |
| RELEASE_VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add packages/nipplejs/package.json | |
| git commit -m "chore: bump version to $RELEASE_VERSION" | |
| git push | |
| - run: yarn build | |
| - run: yarn test:unit | |
| - run: yarn test:e2e | |
| - name: Copy README into package | |
| run: cp README.md packages/nipplejs/README.md | |
| - name: Publish | |
| env: | |
| CHANNEL: ${{ steps.channel.outputs.channel }} | |
| run: | | |
| if [ "$CHANNEL" = "dev" ]; then | |
| yarn workspace nipplejs npm publish --provenance --access public --tag dev | |
| else | |
| yarn workspace nipplejs npm publish --provenance --access public | |
| fi |