Feature branch test for PR vulnerability #5
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: "Disable Merge on Vulnerability" | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
jobs: | |
analyze: | |
name: Analyze | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Initialize CodeQL | |
uses: github/codeql-action/init@v2 | |
- name: Autobuild | |
uses: github/codeql-action/autobuild@v2 | |
- name: Perform CodeQL Analysis | |
uses: github/codeql-action/analyze@v2 | |
- name: Check for Vulnerabilities | |
id: check-for-vulnerabilities | |
run: | | |
if [ -e codeql-results/codeql-results.sarif ]; then | |
echo "Checking for vulnerabilities..." | |
if grep -q 'critical-vulnerability' codeql-results/codeql-results.sarif; then | |
echo "Critical vulnerabilities found!" | |
echo "Vulnerabilities found. Disabling merging..." | |
GITHUB_TOKEN=$GITHUB_TOKEN | |
branch_name=$(jq -r .ref <<< $GITHUB_EVENT_PATH) | |
protection_url="https://api.github.com/repos/${{ github.repository }}/branches/${branch_name}/protection" | |
protection_data='{"required_status_checks": null, "enforce_admins": {"enabled": true}, "restrictions": null}' | |
response=$(curl -X PUT -H "Authorization: token $GITHUB_TOKEN" -d "$protection_data" $protection_url) | |
if [ "$response" = "" ]; then | |
echo "Merge button disabled for branch $branch_name" | |
else | |
echo "Failed to disable merge button for branch $branch_name" | |
fi | |
fi | |
fi | |
- name: Post Vulnerability Check | |
if: steps.check-for-vulnerabilities.outputs.status == 'failure' | |
run: | | |
echo "Vulnerabilities found. Merging is disabled." | |
continue-on-error: true |