Skip to content

Auto Version PR

Auto Version PR #899

name: Auto Version PR
on:
# Run daily at midnight
schedule:
- cron: '0 0 * * *'
# Allow manual triggering
workflow_dispatch:
# Run on pushes to main (except when version-stamp.txt is modified)
push:
branches:
- main
paths-ignore:
- '.github/version-stamp.txt'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-for-changes:
name: Check for Changes
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.check-changes.outputs.has_changes }}
sdk_changes: ${{ steps.check-changes.outputs.sdk_changes }}
pkg_changes: ${{ steps.check-changes.outputs.pkg_changes }}
sdk_changes_log: ${{ steps.check-changes.outputs.sdk_changes_log }}
pkg_changes_log: ${{ steps.check-changes.outputs.pkg_changes_log }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js 22.x
uses: actions/setup-node@v3
with:
node-version: 22.x
registry-url: 'https://registry.npmjs.org/'
- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: 10.x
- name: Install Dependencies
run: pnpm install --frozen-lockfile
# Add explicit NPM authentication step
- name: Configure NPM Authentication
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
npm whoami || echo "NPM Authentication Failed"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Check for Changes
id: check-changes
run: |
# Run version-pr scripts in dry run mode to check for changes
export GH_TOKEN=${{ github.token }}
SDK_OUTPUT=$(GH_TOKEN=${{ github.token }} pnpm version-pr-sdks)
PKG_OUTPUT=$(GH_TOKEN=${{ github.token }} pnpm version-pr-pkgs)
echo "$SDK_OUTPUT" > /tmp/sdk-version-pr-output.txt
echo "$PKG_OUTPUT" > /tmp/pkg-version-pr-output.txt
# Check if SDK packages have changes
if echo "$SDK_OUTPUT" | grep -q "The next release version is"; then
echo "sdk_changes=true" >> $GITHUB_OUTPUT
echo "sdk_changes_log<<EOF" >> $GITHUB_OUTPUT
echo "$SDK_OUTPUT" | grep -A 2 "The next release version is" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "Found SDK changes that need versioning"
else
echo "sdk_changes=false" >> $GITHUB_OUTPUT
echo "No SDK changes that need versioning"
fi
# Check if other packages have changes
if echo "$PKG_OUTPUT" | grep -q "The next release version is"; then
echo "pkg_changes=true" >> $GITHUB_OUTPUT
echo "pkg_changes_log<<EOF" >> $GITHUB_OUTPUT
echo "$PKG_OUTPUT" | grep -A 2 "The next release version is" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "Found package changes that need versioning"
else
echo "pkg_changes=false" >> $GITHUB_OUTPUT
echo "No package changes that need versioning"
fi
# Set overall has_changes flag
if [[ "$SDK_OUTPUT" == *"The next release version is"* ]] || [[ "$PKG_OUTPUT" == *"The next release version is"* ]]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
create-version-pr:
name: Create Version PR
needs: check-for-changes
if: needs.check-for-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js 22.x
uses: actions/setup-node@v3
with:
node-version: 22.x
registry-url: 'https://registry.npmjs.org/'
- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: 10.x
- name: Install Dependencies
run: pnpm install --frozen-lockfile
# Add explicit NPM authentication step
- name: Configure NPM Authentication
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
npm whoami || echo "NPM Authentication Failed"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Update Version Stamp
run: |
# Determine if we have SDK or package changes or both
if [[ "${{ needs.check-for-changes.outputs.sdk_changes }}" == "true" ]]; then
echo "# SDK Version Stamp - Updated on $(date)" > .github/version-stamp-sdks.txt
echo "# This file triggers the SDK release workflow when merged to main" >> .github/version-stamp-sdks.txt
git add .github/version-stamp-sdks.txt
echo "SDK changes detected, creating version stamp"
fi
if [[ "${{ needs.check-for-changes.outputs.pkg_changes }}" == "true" ]]; then
echo "# Package Version Stamp - Updated on $(date)" > .github/version-stamp-pkgs.txt
echo "# This file triggers the package release workflow when merged to main" >> .github/version-stamp-pkgs.txt
git add .github/version-stamp-pkgs.txt
echo "Package changes detected, creating version stamp"
fi
git config --global user.name "Drivly Bot"
git config --global user.email "[email protected]"
- name: Create Release PR
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: version packages"
branch: version-pr
delete-branch: true
title: "chore: version packages"
body: |
This PR was created automatically by the auto-version-pr workflow.
It contains version updates for all packages that have changes.
Changes detected:
```
SDK Changes:
${{ needs.check-for-changes.outputs.sdk_changes_log || 'No SDK changes' }}
Package Changes:
${{ needs.check-for-changes.outputs.pkg_changes_log || 'No package changes' }}
```
Ticket: ENG-821
labels: |
version
automated pr