Bump Next.js Version #481
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: Bump Next.js Version | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 */6 * * *" | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| check-next-version: | |
| name: Check Next.js Version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| bump_needed: ${{ steps.compare-versions.outputs.bump_needed }} | |
| next_version: ${{ steps.compare-versions.outputs.next_version }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: ./.github/actions/node | |
| - name: Get current Next.js version | |
| id: get-current-version | |
| run: | | |
| package=$(pnpm list next --json) | |
| current_version=$(echo "$package" | jq -r '.[0].devDependencies.next.version') | |
| echo "Currently using Next.js version $current_version" | |
| echo "current_version=$current_version" >> $GITHUB_ENV | |
| - name: Get latest Next.js version | |
| id: get-latest-version | |
| run: | | |
| latest_version=$(pnpm show next version) | |
| echo "Latest version is $latest_version" | |
| echo "latest_version=$latest_version" >> $GITHUB_ENV | |
| - name: Compare versions | |
| id: compare-versions | |
| run: | | |
| echo "Comparing versions $current_version and $latest_version" | |
| if [ "$latest_version" != "$current_version" ]; then | |
| echo "Version bump needed" | |
| echo "bump_needed=true" >> $GITHUB_OUTPUT | |
| echo "next_version=$latest_version" >> $GITHUB_OUTPUT | |
| else | |
| echo "Version is up to date" | |
| echo "bump_needed=false" >> $GITHUB_OUTPUT | |
| fi | |
| update-next-version: | |
| name: Update Next.js Version | |
| needs: [check-next-version] | |
| if: ${{ needs.check-next-version.outputs.bump_needed == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: ./.github/actions/node | |
| - name: Update Next.js version | |
| run: | | |
| next_version="${{ needs.check-next-version.outputs.next_version }}" | |
| echo "Updating pnpm-workspace.yaml catalog to $next_version" | |
| sed -i "s/next: .*/next: \"$next_version\"/" "pnpm-workspace.yaml" | |
| pnpm install --lockfile-only | |
| - name: Bump supported range | |
| run: | | |
| next_version="${{ needs.check-next-version.outputs.next_version }}" | |
| patch_file=$(ls src/patches/patch-*.ts | sort -V | tail -n 1) | |
| echo "Updating $patch_file to $next_version" | |
| sed -i "s/\(versions: .*\) <=[0-9\.]\+/\1 <=$next_version/" "$patch_file" | |
| - name: Add new changeset | |
| run: | | |
| unique_id=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13; echo) | |
| echo "Adding new changeset with ID $unique_id" | |
| echo -e "---\n\"next-ws\": patch\n---\n" >> .changeset/$unique_id.md | |
| echo "Bump patch supported range to ${{ needs.check-next-version.outputs.next_version }}" >> .changeset/$unique_id.md | |
| - name: Make pull request | |
| uses: peter-evans/create-pull-request@v5 | |
| with: | |
| token: ${{ secrets.GH_PULL_REQUEST_TOKEN }} | |
| commit-message: "Bump patch supported range to ${{ needs.check-next-version.outputs.next_version }}" | |
| branch: "chore/bump-nextjs-${{ needs.check-next-version.outputs.next_version }}" | |
| title: "Bump patch supported range to ${{ needs.check-next-version.outputs.next_version }}" | |
| body: "Bump patch supported range to ${{ needs.check-next-version.outputs.next_version }}" | |
| delete-branch: true |