2022-09-23 10:13:03 -05:00
name : Check mergeability
2023-05-31 17:15:14 -05:00
on : pull_request
2022-09-23 10:13:03 -05:00
permissions :
pull-requests : write
2023-05-31 17:15:14 -05:00
checks : write
statuses : write
2022-09-23 10:13:03 -05:00
jobs :
check :
runs-on : ubuntu-latest
steps :
- name : Check if there is already a block on this PR
2023-06-01 13:21:55 -05:00
id : blocked
2022-10-28 10:39:01 -05:00
uses : actions/github-script@v6
2023-05-31 17:15:14 -05:00
env :
issue_number : ${{ github.event.number }}
2022-10-28 10:39:01 -05:00
with :
script : |
2023-05-31 17:15:14 -05:00
const { data: reviews } = await github.rest.pulls.listReviews({
owner : context.repo.owner,
repo : context.repo.repo,
pull_number : process.env.issue_number,
});
2023-06-01 13:21:55 -05:00
2023-05-31 17:15:14 -05:00
for (const review of reviews) {
2023-06-01 13:21:55 -05:00
if (review.user.login === 'github-actions[bot]' && review.state === 'CHANGES_REQUESTED') {
return 'true'
2022-10-28 10:39:01 -05:00
}
}
2023-06-01 13:21:55 -05:00
return 'false'
2022-10-28 10:39:01 -05:00
result-encoding : string
2022-09-23 10:13:03 -05:00
- uses : actions/checkout@v3
2023-06-01 13:21:55 -05:00
if : steps.blocked.outputs.result != 'true'
2022-09-23 10:13:03 -05:00
with :
fetch-depth : 0
- name : Get changed files in the .changeset folder
id : changed-files
2024-01-25 06:35:34 -05:00
uses : tj-actions/changed-files@v41
2023-06-01 13:21:55 -05:00
if : steps.blocked.outputs.result != 'true'
2022-09-23 10:13:03 -05:00
with :
files : |
.changeset/**/*.md
2024-01-12 12:38:07 -05:00
- name : Check if any changesets contain minor or major changes
id : check
2023-06-01 13:21:55 -05:00
if : steps.blocked.outputs.result != 'true'
2022-09-23 10:13:03 -05:00
run : |
2024-01-12 12:38:07 -05:00
echo "Checking for changesets marked as minor or major"
2024-01-03 01:20:38 -05:00
echo "found=false" >> $GITHUB_OUTPUT
2024-01-12 12:38:07 -05:00
regex="[\"']astro[\"']: (minor|major)"
2022-09-23 10:13:03 -05:00
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
2024-01-12 12:38:07 -05:00
if [[ $(cat $file) =~ $regex ]]; then
version="${BASH_REMATCH[1]}"
echo "version=$version" >> $GITHUB_OUTPUT
echo "found=true" >> $GITHUB_OUTPUT
echo "$file has a $version release tag"
fi
2022-09-23 10:13:03 -05:00
done
- name : Add label
2023-05-31 17:15:14 -05:00
uses : actions/github-script@v6
2024-01-12 12:38:07 -05:00
if : steps.check.outputs.found == 'true'
2023-05-31 17:15:14 -05:00
env :
issue_number : ${{ github.event.number }}
2023-04-06 09:29:55 -05:00
with :
2023-05-31 17:15:14 -05:00
script : |
github.rest.issues.addLabels({
issue_number : process.env.issue_number,
owner : context.repo.owner,
repo : context.repo.repo,
2024-01-12 12:38:07 -05:00
labels: ['semver : ${{ steps.check.outputs.version }}']
2023-05-31 17:15:14 -05:00
});
2023-04-06 09:29:55 -05:00
2023-05-31 17:15:14 -05:00
- name : Change PR Status
uses : actions/github-script@v6
2024-01-12 12:38:07 -05:00
if : steps.check.outputs.found == 'true'
2023-05-31 17:15:14 -05:00
env :
issue_number : ${{ github.event.number }}
2023-03-01 11:23:24 -05:00
with :
2023-05-31 17:15:14 -05:00
script : |
github.rest.pulls.createReview({
owner : context.repo.owner,
repo : context.repo.repo,
pull_number : process.env.issue_number,
event : 'REQUEST_CHANGES' ,
2024-01-12 12:38:07 -05:00
body : 'This PR is blocked because it contains a `${{ steps.check.outputs.version }}` changeset. A reviewer will merge this at the next release if approved.'
2023-05-31 17:15:14 -05:00
});