Interact - Bump Version and Publish #33
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: Interact - Bump Version and Publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| source_branch: | |
| description: 'Source branch for deploy preview (leave empty for regular release from master)' | |
| required: false | |
| default: '' | |
| type: string | |
| version_strategy: | |
| type: choice | |
| description: Version strategy | |
| options: | |
| - prerelease | |
| - premajor | |
| - preminor | |
| - prepatch | |
| - major | |
| - minor | |
| - patch | |
| dry_run: | |
| description: 'Dry run (preview only)' | |
| required: false | |
| default: false | |
| type: boolean | |
| permissions: | |
| id-token: write # REQUIRED for npm Trusted Publishing | |
| contents: write | |
| pull-requests: write | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | |
| with: | |
| fetch-depth: 0 # full history for yarn version | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: ${{ github.event.inputs.source_branch || github.ref }} | |
| - name: Create and checkout release branch | |
| if: ${{ github.event.inputs.dry_run == 'false' }} | |
| id: release_branch | |
| run: | | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git config user.name "github-actions[bot]" | |
| if [ -n "${{ github.event.inputs.source_branch }}" ]; then | |
| BRANCH_NAME="release-dp" | |
| else | |
| BRANCH_NAME="release" | |
| fi | |
| echo "name=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
| git checkout -b "$BRANCH_NAME" | |
| git push -u origin "$BRANCH_NAME" | |
| - name: Setup Node with trusted publishing | |
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 | |
| with: | |
| node-version: 24 | |
| registry-url: https://registry.npmjs.org | |
| - name: Set up Yarn | |
| run: | | |
| corepack enable | |
| corepack prepare yarn@4.10.3 --activate | |
| yarn set version 4.10.3 | |
| - name: Install dependencies | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: NPQ_PKG_MGR=yarn npx npq install | |
| - name: Build motion package | |
| run: yarn workspace @wix/motion build | |
| - name: Build interact package | |
| run: yarn workspace @wix/interact build | |
| - name: Test interact package | |
| run: yarn workspace @wix/interact test | |
| # ---- UPDATE MOTION DEPENDENCY FOR DEPLOY PREVIEW ---- | |
| - name: Update @wix/motion dependency to deploy preview version | |
| if: ${{ github.event.inputs.source_branch != '' }} | |
| working-directory: packages/interact | |
| run: | | |
| MOTION_DP_VERSION=$(npm view @wix/motion@dp version) | |
| echo "Using @wix/motion deploy preview version: $MOTION_DP_VERSION" | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| pkg.dependencies['@wix/motion'] = '${MOTION_DP_VERSION}'; | |
| fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| # ---- BUMP VERSION ---- | |
| - name: Set deploy preview version | |
| if: ${{ github.event.inputs.dry_run == 'false' && github.event.inputs.source_branch != '' }} | |
| working-directory: packages/interact | |
| run: | | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| BASE_VERSION=$(echo "$CURRENT_VERSION" | sed 's/-.*//') | |
| TIMESTAMP=$(date +%Y%m%d%H%M%S) | |
| DP_VERSION="${BASE_VERSION}-dp.${TIMESTAMP}" | |
| yarn version "$DP_VERSION" | |
| - name: Bump version | |
| if: ${{ github.event.inputs.dry_run == 'false' && github.event.inputs.source_branch == '' }} | |
| working-directory: packages/interact | |
| run: yarn version ${{ github.event.inputs.version_strategy }} | |
| - name: Get new version | |
| if: ${{ github.event.inputs.dry_run == 'false' }} | |
| id: get_version | |
| working-directory: packages/interact | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Commit and push version bump | |
| if: ${{ github.event.inputs.dry_run == 'false' }} | |
| run: | | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git config user.name "github-actions[bot]" | |
| git add . | |
| git commit -m "chore: bump @wix/interact to ${{ steps.get_version.outputs.version }}" | |
| TAG="interact@${{ steps.get_version.outputs.version }}" | |
| git tag -a "$TAG" -m "chore: release @wix/interact ${{ steps.get_version.outputs.version }}" | |
| git push origin ${{ steps.release_branch.outputs.name }} | |
| git push origin "$TAG" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # ---- CREATE PULL REQUEST ---- | |
| - name: Create Pull Request | |
| if: ${{ github.event.inputs.dry_run == 'false' }} | |
| id: create_pr | |
| uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const { data: pr } = await github.rest.pulls.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: `chore: bump @wix/interact to ${{ steps.get_version.outputs.version }}`, | |
| head: '${{ steps.release_branch.outputs.name }}', | |
| base: '${{ github.event.inputs.source_branch || 'master' }}', | |
| body: 'Automated version bump and release PR', | |
| maintainer_can_modify: true | |
| }); | |
| return pr.number; | |
| # ---- PUBLISH WITH TRUSTED PUBLISHING ---- | |
| - name: npm publish @wix/interact deploy preview (trusted) | |
| if: ${{ github.event.inputs.dry_run == 'false' && github.event.inputs.source_branch != '' }} | |
| run: | | |
| cd packages/interact | |
| npm publish --tag dp --provenance --access=public | |
| - name: npm publish @wix/interact RC (trusted) | |
| if: ${{ github.event.inputs.dry_run == 'false' && github.event.inputs.source_branch == '' && (github.event.inputs.version_strategy == 'prerelease' || github.event.inputs.version_strategy == 'premajor' || github.event.inputs.version_strategy == 'preminor' || github.event.inputs.version_strategy == 'prepatch') }} | |
| run: | | |
| cd packages/interact | |
| npm publish --tag next --provenance --access=public | |
| - name: npm publish @wix/interact Stable (trusted) | |
| if: ${{ github.event.inputs.dry_run == 'false' && github.event.inputs.source_branch == '' && (github.event.inputs.version_strategy == 'major' || github.event.inputs.version_strategy == 'minor' || github.event.inputs.version_strategy == 'patch') }} | |
| run: | | |
| cd packages/interact | |
| npm publish --tag latest --provenance --access=public |