Skip to content

Commit fd3a791

Browse files
committed
add branch protections workflow
1 parent dc8c11f commit fd3a791

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"url": "https://api.github.com/repos/aws-powertools/powertools-lambda-java/branches/main/protection",
3+
"required_status_checks": {
4+
"url": "https://api.github.com/repos/aws-powertools/powertools-lambda-java/branches/main/protection/required_status_checks",
5+
"strict": true,
6+
"contexts": [
7+
"SonarCloud"
8+
],
9+
"contexts_url": "https://api.github.com/repos/aws-powertools/powertools-lambda-java/branches/main/protection/required_status_checks/contexts",
10+
"checks": [
11+
{
12+
"context": "SonarCloud",
13+
"app_id": 57789
14+
}
15+
]
16+
},
17+
"required_pull_request_reviews": {
18+
"url": "https://api.github.com/repos/aws-powertools/powertools-lambda-java/branches/main/protection/required_pull_request_reviews",
19+
"dismiss_stale_reviews": false,
20+
"require_code_owner_reviews": false,
21+
"require_last_push_approval": false,
22+
"required_approving_review_count": 0
23+
},
24+
"required_signatures": {
25+
"url": "https://api.github.com/repos/aws-powertools/powertools-lambda-java/branches/main/protection/required_signatures",
26+
"enabled": false
27+
},
28+
"enforce_admins": {
29+
"url": "https://api.github.com/repos/aws-powertools/powertools-lambda-java/branches/main/protection/enforce_admins",
30+
"enabled": true
31+
},
32+
"required_linear_history": {
33+
"enabled": false
34+
},
35+
"allow_force_pushes": {
36+
"enabled": false
37+
},
38+
"allow_deletions": {
39+
"enabled": false
40+
},
41+
"block_creations": {
42+
"enabled": false
43+
},
44+
"required_conversation_resolution": {
45+
"enabled": false
46+
},
47+
"lock_branch": {
48+
"enabled": false
49+
},
50+
"allow_fork_syncing": {
51+
"enabled": false
52+
}
53+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Modified copy of: https://github.com/github/docs/blob/main/.github/workflows/alert-changed-branch-protections.yml
2+
3+
on:
4+
branch_protection_rule:
5+
workflow_dispatch:
6+
schedule:
7+
- cron: '20 16 * * *' # Run daily at 16:20 UTC
8+
pull_request:
9+
paths:
10+
- .github/workflows/security-branch-protections.yml
11+
- .github/branch_protection_settings/*.json
12+
13+
name: Alert Changed Branch Protections
14+
run-name: Alert Changed Branch Protections
15+
16+
permissions:
17+
contents: write
18+
19+
jobs:
20+
check-branch-protections:
21+
runs-on: ubuntu-latest
22+
environment: Security
23+
if: github.repository == 'aws-powertools/powertools-lambda-java'
24+
strategy:
25+
matrix:
26+
# List of branches we want to monitor for protection changes
27+
branch:
28+
- main
29+
- v2
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
33+
- name: Fetch branch protections
34+
id: fetch
35+
env:
36+
GH_TOKEN: ${{ secrets.BRANCH_PROTECTION_TOKEN }}
37+
run: |
38+
# Fetch branch protections and store them in a file
39+
gh api /repos/${{ github.repository }}/branches/${{ matrix.branch }}/protection \
40+
> .github/branch_protection_settings/${{ matrix.branch }}.json
41+
- name: Compare branch protections
42+
id: compare
43+
run: |
44+
git diff --quiet .github/branch_protection_settings/${{ matrix.branch }}.json \
45+
|| echo "diff_failed=true" >> $GITHUB_ENV
46+
- name: Send webhook
47+
if: ${{ env.diff_failed == 'true' }}
48+
run: |
49+
curl -X POST -d '{"message": "Branch protections have changed for ${{ github.repository }} on ${{ matrix.branch }}. Please review the changes or revert the changes in GitHub. https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}' \
50+
${{ secrets.SLACK_WEBHOOK_URL }}
51+
- name: Fail workflow
52+
if: ${{ env.diff_failed == 'true' }}
53+
run: |
54+
echo "::error::Branch protections have been changed"

0 commit comments

Comments
 (0)