EVEREST-107 Simplify Feature Builds (#1019) #18
This file contains 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: Auto-Update PR Base | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
auto-update-base: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
script: | | |
try { | |
const { data: pulls } = await github.rest.pulls.list({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: "open", | |
}); | |
for (const pull of pulls) { | |
const hasAutoUpdateLabel = pull.labels.some(label => label.name === "auto-update-base"); | |
if (hasAutoUpdateLabel) { | |
try { | |
const pr = await github.rest.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pull.number, | |
}); | |
if (pr.data.mergeable_state === 'dirty') { | |
console.log(`[INFO] PR #${pull.number}: "${pull.title}" - Skipping update due to merge conflict.`); | |
continue; | |
} | |
if (pr.data.mergeable_state !== 'behind') { | |
console.log(`[INFO] PR #${pull.number}: "${pull.title}" - Base branch is up-to-date.`); | |
continue; | |
} | |
console.log(`[UPDATE] PR #${pull.number}: "${pull.title}" - Updating base branch...`); | |
try { | |
await github.rest.pulls.updateBranch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pull.number, | |
}); | |
console.log(`[SUCCESS] PR #${pull.number}: "${pull.title}" - Base branch updated.`); | |
} catch (updateError) { | |
console.error(`[ERROR] PR #${pull.number}: Failed to update base branch - ${updateError.message}`); | |
} | |
} catch (diffError) { | |
console.error(`[ERROR] PR #${pull.number}: Failed to compare commits - ${diffError.message}`); | |
} | |
} | |
} | |
} catch (error) { | |
console.error(`[ERROR] Failed to list pull requests - ${error.message}`); | |
} |