2022-09-23 10:13:03 -05:00
name : Check mergeability
2024-03-08 03:21:33 -05:00
on : pull_request_target
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
2024-02-09 01:35:00 -05:00
uses : actions/github-script@v7
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
2024-02-09 01:35:00 -05:00
- uses : actions/checkout@v4
2023-06-01 13:21:55 -05:00
if : steps.blocked.outputs.result != 'true'
2022-09-23 10:13:03 -05:00
with :
2024-03-08 03:21:33 -05:00
repository : ${{ github.event.pull_request.head.repo.full_name }}
2024-04-09 09:55:07 -05:00
ref : ${{ github.event.pull_request.head.sha }}
2022-09-23 10:13:03 -05:00
fetch-depth : 0
- name : Get changed files in the .changeset folder
id : changed-files
2024-09-25 06:48:16 -05:00
uses : tj-actions/changed-files@v45
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'
2024-04-05 05:54:12 -05:00
env :
ALL_CHANGED_FILES : ${{ steps.changed-files.outputs.all_changed_files }}
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)"
2024-04-05 05:54:12 -05:00
for file in ${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
2024-02-09 01:35:00 -05:00
uses : actions/github-script@v7
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
2024-02-09 01:35:00 -05:00
uses : actions/github-script@v7
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
});