Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add workflow to check for new version of sdk #47

Merged
merged 8 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/dependency-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Update Dash Dependency and Package Version

on:
schedule:
- cron: '0 12 * * *' # Run daily at 1200 UTC
workflow_dispatch: # Allow manual trigger

permissions:
contents: write
pull-requests: write

jobs:
update-dash-package:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v4

# Step 2: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

# Step 3: Install dependencies
- name: Install Dependencies
run: npm install

# Step 4: Check and Update Dash Dependency and Version
- name: Check and Update Dash Dependency
id: update_dash
run: |
# Get the current version of Dash in package.json
CURRENT_DASH_VERSION=$(jq -r '.dependencies.dash // .devDependencies.dash' package.json)

# Extract the version prefix (e.g., ^, ~, or empty)
DASH_PREFIX=$(echo "$CURRENT_DASH_VERSION" | grep -o '^[^0-9]*')
DASH_VERSION_NUMBER=$(echo "$CURRENT_DASH_VERSION" | grep -o '[0-9].*')

# Get the latest version of Dash
LATEST_DASH_VERSION=$(npm show dash version)
LATEST_MINOR_PATCH=$(echo "$LATEST_DASH_VERSION" | cut -d. -f2,3)

echo "Current Dash version: $CURRENT_DASH_VERSION"
echo "Latest Dash version: $LATEST_DASH_VERSION"

# Update dash dependency if needed
if [ "$DASH_VERSION_NUMBER" != "$LATEST_DASH_VERSION" ]; then
jq '.dependencies.dash = "'"$DASH_PREFIX$LATEST_DASH_VERSION"'"' package.json > package.json.tmp && mv package.json.tmp package.json

# Update package version in package.json (keep major version, sync minor and patch)
CURRENT_PACKAGE_VERSION=$(jq -r '.version' package.json)
CURRENT_MAJOR_VERSION=$(echo "$CURRENT_PACKAGE_VERSION" | cut -d. -f1)
NEW_PACKAGE_VERSION="$CURRENT_MAJOR_VERSION.$LATEST_MINOR_PATCH"

jq '.version = "'"$NEW_PACKAGE_VERSION"'"' package.json > package.json.tmp && mv package.json.tmp package.json
echo "Updated package.json version to $NEW_PACKAGE_VERSION"

npm install dash

echo "needs_update=true" >> $GITHUB_ENV
else
echo "Dash dependency is up-to-date"
echo "needs_update=false" >> $GITHUB_ENV
fi

# Step 5: Commit and Push Changes if Needed
- name: Commit and Push Changes
if: env.needs_update == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

git checkout -b update-dash-and-version
git add package.json package-lock.json
git commit -m "chore: update dash dependency and sync version to $NEW_PACKAGE_VERSION"
git push origin update-dash-and-version

# Step 6: Create Pull Request
- name: Create Pull Request
if: env.needs_update == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update-dash-and-version
title: "Update Dash Dependency and Sync Version"
body: |
This pull request updates the `dash` dependency to the latest version and syncs the package version to `$NEW_PACKAGE_VERSION`, aligning the minor and patch versions with `dash`.