generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 28
fix: Modified auto merge condition #1136
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b12e5a5
Created github action for pnpm update
BrigittaK307 e47e8b3
Updated pnpm command
BrigittaK307 fc834fd
Updated pnpm command
BrigittaK307 012739a
Merge branch 'main' into githAction-pnpmUpdate-394
KavithaSiva 4be7e21
Added pnpm audit command to the file
BrigittaK307 cf83770
Modified the auto-merge logic
BrigittaK307 36949fc
Merge branch 'main' of https://github.com/SAP/ai-sdk-js into githActi…
BrigittaK307 2482f94
Solved pr comments
BrigittaK307 ff928ad
Merge branch 'main' of https://github.com/SAP/ai-sdk-js into githActi…
BrigittaK307 19a43b3
Modified branch name to have the same date format as in PR
BrigittaK307 af6bda7
Merge branch 'main' into githAction-pnpmUpdate-394
BrigittaK307 5444c03
Modified throw to console.log
BrigittaK307 8dde73f
Merge branch 'githAction-pnpmUpdate-394' of https://github.com/SAP/ai…
BrigittaK307 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ name: Monthly pnpm Dependency Update | |
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 2 1 * *' | ||
| - cron: '0 2 1 * *' # Runs at 02:00 UTC on the 1st of every month | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
|
|
@@ -19,16 +19,17 @@ jobs: | |
| run: | | ||
| pnpm --no-save update | ||
| pnpm audit --audit-level moderate | ||
|
|
||
| if [[ -n "$(git status --porcelain)" ]]; then | ||
| git config --global user.email "[email protected]" | ||
| git config --global user.name "cloud-sdk-js" | ||
| git checkout -b "bot/monthly-transitive-dependency-update-$(date +%Y-%m-%d)" | ||
| BRANCH_NAME="bot/monthly-transitive-dependency-update-$(date -u +%Y%m%d-%H%M%S)" | ||
| git checkout -b "$BRANCH_NAME" | ||
| git add . | ||
| git commit -m "chore: update pnpm transitive dependencies" | ||
| git push --set-upstream origin "bot/monthly-transitive-dependency-update-$(date +%Y-%m-%d)" | ||
| git push --set-upstream origin "$BRANCH_NAME" | ||
| else | ||
| echo "No changes to commit" | ||
| exit 0 | ||
| fi | ||
|
|
||
| - name: Create Pull Request | ||
|
|
@@ -38,11 +39,19 @@ jobs: | |
| github-token: ${{ secrets.GH_CLOUD_SDK_JS_ADMIN_WRITE_TOKEN }} | ||
| script: | | ||
| const { repo, owner } = context.repo; | ||
| const now = new Date(); | ||
| const pad = num => num.toString().padStart(2, '0'); | ||
| const formattedDate = `${now.getUTCFullYear()}${pad( | ||
| now.getUTCMonth() + 1 | ||
| )}${pad(now.getUTCDate())}-${pad(now.getUTCHours())}${pad( | ||
| now.getUTCMinutes() | ||
| )}${pad(now.getUTCSeconds())}`; | ||
| const branch = `bot/monthly-transitive-dependency-update-${formattedDate}`; | ||
| const result = await github.rest.pulls.create({ | ||
| title: 'chore: Monthly Transitive Dependency Update', | ||
| owner, | ||
| repo, | ||
| head: `bot/monthly-transitive-dependency-update-${new Date().toISOString().split('T')[0]}`, | ||
| head: branch, | ||
| base: 'main', | ||
| body: 'This is an automated PR to update pnpm transitive dependencies.' | ||
| }); | ||
|
|
@@ -54,41 +63,75 @@ jobs: | |
| with: | ||
| github-token: ${{ secrets.GH_CLOUD_SDK_JS_ADMIN_WRITE_TOKEN }} | ||
| script: | | ||
| const retry = require('async-retry'); | ||
ZhongpinWang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const { repo, owner } = context.repo; | ||
| const now = new Date(); | ||
| const pad = num => num.toString().padStart(2, '0'); | ||
| const formattedDate = `${now.getUTCFullYear()}${pad( | ||
| now.getUTCMonth() + 1 | ||
| )}${pad(now.getUTCDate())}-${pad(now.getUTCHours())}${pad( | ||
| now.getUTCMinutes() | ||
| )}${pad(now.getUTCSeconds())}`; | ||
| const branch = `bot/monthly-transitive-dependency-update-${formattedDate}`; | ||
|
|
||
| const pulls = await github.rest.pulls.list({ | ||
| owner, | ||
| repo, | ||
| head: `bot/monthly-transitive-dependency-update-${new Date().toISOString().split('T')[0]}`, | ||
| head: branch, | ||
| base: 'main', | ||
| state: 'open' | ||
| }); | ||
|
|
||
| if (pulls.data.length === 0) { | ||
| console.log('No matching pull request found'); | ||
| return; | ||
| } | ||
|
|
||
| const pr = pulls.data[0]; | ||
|
|
||
| // Wait for checks to complete | ||
| await new Promise(resolve => setTimeout(resolve, 300000)); // Wait 5 minutes | ||
|
|
||
| const { data: checks } = await github.rest.checks.listForRef({ | ||
| owner, | ||
| repo, | ||
| ref: pr.head.sha | ||
| }); | ||
|
|
||
| const allChecksPassed = checks.check_runs.every(run => run.conclusion === 'success'); | ||
|
|
||
| if (allChecksPassed) { | ||
|
|
||
| const result = await retry( | ||
| async () => { | ||
| const { data: checks } = await github.rest.checks.listForRef({ | ||
| owner, | ||
| repo, | ||
| ref: pr.head.sha | ||
| }); | ||
|
|
||
| const allCompleted = checks.check_runs.every(run => run.status === 'completed'); | ||
| const allAcceptable = checks.check_runs.every(run => | ||
| ['success', 'skipped', 'neutral'].includes(run.conclusion) | ||
| ); | ||
|
|
||
| if (!allCompleted) { | ||
| throw new Error(`PR #${pr.number} still has pending checks. Retrying...`); | ||
| } | ||
|
|
||
| if (!allAcceptable) { | ||
| console.log(`PR #${pr.number} has failed checks that prevent merging.`); | ||
| } | ||
|
|
||
| return 'success'; | ||
| }, | ||
| { | ||
| retries: 5, | ||
| minTimeout: 2 * 60 * 1000, | ||
| maxTimeout: 2 * 60 * 1000, | ||
| onRetry: (error, attempt) => { | ||
| const timestamp = new Date().toISOString(); | ||
| console.log(`[${timestamp}] Attempt ${attempt} failed: ${error.message}. Retrying...`); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| if (result === 'success') { | ||
| await github.rest.pulls.merge({ | ||
| owner, | ||
| repo, | ||
| pull_number: pr.number, | ||
| merge_method: 'squash' | ||
| }); | ||
| console.log(`Pull Request #${pr.number} merged successfully`); | ||
| } else { | ||
| console.log(`Not all checks passed for PR #${pr.number}`); | ||
| console.log(`PR #${pr.number} merged successfully.`); | ||
| } | ||
BrigittaK307 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| else { | ||
| console.log(`PR #${pr.number} could not be merged due to failed checks.`); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.