update readme #57
Workflow file for this run
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: Block PR until Sub-PR is Merged | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened, closed] | |
issue_comment: | |
types: [created] | |
workflow_dispatch: {} | |
jobs: | |
block-pr: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check for Sub-PR Status | |
id: check_sub_pr | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 | |
with: | |
script: | | |
const isPullRequest = context.payload.pull_request !== undefined; | |
const mainPrNumber = isPullRequest | |
? context.payload.pull_request.number | |
: context.payload.issue.number; | |
const commentPattern = /Pull request https:\/\/github\.com\/.*\/pull\/(\d+) was created to preview the result of this PR\./; | |
const noChangeCommentPattern = /Your current PR doesn\'t make any change in the rendered project\. No PR was created\./; | |
const comments = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: mainPrNumber, | |
}); | |
const noChangeComment = comments.data.find(comment => noChangeCommentPattern.test(comment.body)); | |
if (noChangeComment) { | |
console.log("No sub-PR is created for this PR, skipping the check"); | |
return; | |
} | |
const subPrComment = comments.data.find(comment => commentPattern.test(comment.body)); | |
if (!subPrComment) { | |
console.log('No sub-PR comment found yet.'); | |
throw new Error(`Sub-PR comment not found in the current PR.`); | |
} | |
const subPrNumber = subPrComment.body.match(commentPattern)[1]; | |
console.log(`Sub-PR Number: ${subPrNumber}`); | |
const subPr = await github.rest.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: subPrNumber, | |
}); | |
if (subPr.data.merged) { | |
console.log(`Sub-PR #${subPrNumber} is merged.`); | |
} else { | |
throw new Error(`Sub-PR #${subPrNumber} is not merged.`); | |
} | |
- name: Fail if Sub-PR is not merged | |
if: ${{ failure() }} | |
run: | | |
echo "The sub-PR is not merged. Blocking the main PR." | |
exit 1 |