forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create repository_lockdown_check.yml
- Loading branch information
1 parent
35e5347
commit efa5537
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Repository lockdown check | ||
on: | ||
pull_request_target: | ||
types: [opened, synchronize, reopened] | ||
branches: | ||
- 'main' | ||
- 'release/*' | ||
permissions: | ||
issues: write | ||
pull-requests: write | ||
jobs: | ||
repository_lockdown: | ||
permissions: | ||
issues: write | ||
pull-requests: write | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check if lockdown is in place | ||
run: | | ||
set -e | ||
if [[ ${{ vars.LOCKDOWN }} == "true" ]]; then | ||
exit 1 | ||
fi | ||
# Did bot already comment the PR? | ||
- name: Find Comment | ||
if: (success() || failure()) | ||
uses: peter-evans/[email protected] | ||
id: fc | ||
with: | ||
issue-number: ${{github.event.pull_request.number}} | ||
comment-author: 'github-actions[bot]' | ||
body-includes: '<!-- DO_NOT_REMOVE: repository_lockdown -->' | ||
# If not, create a new comment | ||
- name: Create comment | ||
if: steps.fc.outputs.comment-id == '' && failure() | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ github.token }} | ||
script: | | ||
let body = "<!-- DO_NOT_REMOVE: repository_lockdown -->\n\n> [!CAUTION]\n>Repository is on lockdown for maintenance, all merges are on hold." | ||
const comment = await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: body | ||
}); | ||
return comment.data.id; | ||
# If yes, update the comment | ||
- name: Update comment | ||
if: steps.fc.outputs.comment-id != '' && failure() | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ github.token }} | ||
script: | | ||
let body = "<!-- DO_NOT_REMOVE: repository_lockdown -->\n\n> [!CAUTION]\n>Repository is on lockdown for maintenance, all merges are on hold." | ||
const comment = await github.rest.issues.updateComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
comment_id: ${{steps.fc.outputs.comment-id}}, | ||
body: body | ||
}); | ||
return comment.data.id; | ||
# If comment exists, but we are no longer in maintenance mode, delete the comment. | ||
- name: Delete comment | ||
if: steps.fc.outputs.comment-id != '' && success() | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ github.token }} | ||
script: | | ||
let body = "<!-- DO_NOT_REMOVE: repository_lockdown -->\n\n> [!CAUTION]\n>Repository is on lockdown for maintenance, all merges are on hold." | ||
const comment = await github.rest.issues.deleteComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
comment_id: ${{steps.fc.outputs.comment-id}} | ||
}); | ||
return 0; |