|
| 1 | +name: Update Dash Dependency and Package Version |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 12 * * *' # Run daily at 1200 UTC |
| 6 | + workflow_dispatch: # Allow manual trigger |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + update-dash-package: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + # Step 1: Checkout the repository |
| 18 | + - name: Checkout Repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + # Step 2: Set up Node.js |
| 22 | + - name: Set up Node.js |
| 23 | + uses: actions/setup-node@v4 |
| 24 | + with: |
| 25 | + node-version: '20' |
| 26 | + |
| 27 | + # Step 3: Install dependencies |
| 28 | + - name: Install Dependencies |
| 29 | + run: npm install |
| 30 | + |
| 31 | + # Step 4: Check and Update Dash Dependency and Version |
| 32 | + - name: Check and Update Dash Dependency |
| 33 | + id: update_dash |
| 34 | + run: | |
| 35 | + # Get the current version of Dash in package.json |
| 36 | + CURRENT_DASH_VERSION=$(jq -r '.dependencies.dash // .devDependencies.dash' package.json) |
| 37 | + |
| 38 | + # Extract the version prefix (e.g., ^, ~, or empty) |
| 39 | + DASH_PREFIX=$(echo "$CURRENT_DASH_VERSION" | grep -o '^[^0-9]*') |
| 40 | + DASH_VERSION_NUMBER=$(echo "$CURRENT_DASH_VERSION" | grep -o '[0-9].*') |
| 41 | +
|
| 42 | + # Get the latest version of Dash |
| 43 | + LATEST_DASH_VERSION=$(npm show dash version) |
| 44 | + LATEST_MINOR_PATCH=$(echo "$LATEST_DASH_VERSION" | cut -d. -f2,3) |
| 45 | +
|
| 46 | + echo "Current Dash version: $CURRENT_DASH_VERSION" |
| 47 | + echo "Latest Dash version: $LATEST_DASH_VERSION" |
| 48 | +
|
| 49 | + # Update dash dependency if needed |
| 50 | + if [ "$DASH_VERSION_NUMBER" != "$LATEST_DASH_VERSION" ]; then |
| 51 | + jq '.dependencies.dash = "'"$DASH_PREFIX$LATEST_DASH_VERSION"'"' package.json > package.json.tmp && mv package.json.tmp package.json |
| 52 | +
|
| 53 | + # Update package version in package.json (keep major version, sync minor and patch) |
| 54 | + CURRENT_PACKAGE_VERSION=$(jq -r '.version' package.json) |
| 55 | + CURRENT_MAJOR_VERSION=$(echo "$CURRENT_PACKAGE_VERSION" | cut -d. -f1) |
| 56 | + NEW_PACKAGE_VERSION="$CURRENT_MAJOR_VERSION.$LATEST_MINOR_PATCH" |
| 57 | +
|
| 58 | + jq '.version = "'"$NEW_PACKAGE_VERSION"'"' package.json > package.json.tmp && mv package.json.tmp package.json |
| 59 | + echo "Updated package.json version to $NEW_PACKAGE_VERSION" |
| 60 | +
|
| 61 | + npm install dash |
| 62 | +
|
| 63 | + echo "needs_update=true" >> $GITHUB_ENV |
| 64 | + else |
| 65 | + echo "Dash dependency is up-to-date" |
| 66 | + echo "needs_update=false" >> $GITHUB_ENV |
| 67 | + fi |
| 68 | +
|
| 69 | + # Step 5: Commit and Push Changes if Needed |
| 70 | + - name: Commit and Push Changes |
| 71 | + if: env.needs_update == 'true' |
| 72 | + run: | |
| 73 | + git config user.name "github-actions[bot]" |
| 74 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 75 | + |
| 76 | + git checkout -b update-dash-and-version |
| 77 | + git add package.json package-lock.json |
| 78 | + git commit -m "chore: update dash dependency and sync version to $NEW_PACKAGE_VERSION" |
| 79 | + git push origin update-dash-and-version |
| 80 | +
|
| 81 | + # Step 6: Create Pull Request |
| 82 | + - name: Create Pull Request |
| 83 | + if: env.needs_update == 'true' |
| 84 | + uses: peter-evans/create-pull-request@v5 |
| 85 | + with: |
| 86 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + branch: update-dash-and-version |
| 88 | + title: "Update Dash Dependency and Sync Version" |
| 89 | + body: | |
| 90 | + 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`. |
0 commit comments