generated from nginx/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 116
Add new workflow to block direct module reference changes #863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lamATnginx
wants to merge
9
commits into
main
Choose a base branch
from
blocking-action
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9b6a813
feat: Add new workflow to block direct module reference changes
lamATnginx 73b299b
Add code to comment on PR + fail if changes detected
lamATnginx 1011f43
Added exemption code
lamATnginx 00a0b4c
Merge branch 'main' into blocking-action
ADubhlaoich 0fdb9f4
Merge branch 'main' into blocking-action
ADubhlaoich 744b4da
Corrected exit code
lamATnginx 16051f3
Merge branch 'main' into blocking-action
ADubhlaoich b710ce5
Merge branch 'main' into blocking-action
ADubhlaoich 98b4757
Merge branch 'main' into blocking-action
ADubhlaoich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,70 @@ | ||
name: Block specific changes | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
block-direct-markdown-module-changes: | ||
name: Block modifying Markdown Module Reference files directly | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2 # v4.2.2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Check for changes in /nginx/module_reference | ||
id: check_module_changes | ||
run: | | ||
FOLDER_DIR="content/nginx/module_reference" | ||
git diff origin/main -- $FOLDER_DIR > changes.txt | ||
|
||
if [[ -s changes.txt ]]; then | ||
echo "Changes detected for $FOLDER_DIR" | ||
echo "CHANGES_DETECTED=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "CHANGES_DETECTED=false" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Check for exemption for PR created by dot-org-content workflow | ||
id: check_exemption | ||
run: | | ||
LABELS=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH" || echo "") | ||
AUTHOR=$(jq -r '.pull_request.user.login' "$GITHUB_EVENT_PATH") | ||
TITLE=$(jq -r '.pull_request.title' "$GITHUB_EVENT_PATH") | ||
ACCEPTED_LABEL="module_reference" | ||
ACCEPTED_AUTHOR="github-actions" | ||
ACCEPTED_TITLE="NGINX Plus - Module Ref" | ||
|
||
EXEMPTION=false | ||
|
||
if echo "$LABELS" | grep -q "$ACCEPTED_LABEL"; then | ||
echo "Label match..." | ||
EXEMPTION=true | ||
fi | ||
if [[ "$AUTHOR" == "$ACCEPTED_AUTHOR" ]]; then | ||
echo "Author match..." | ||
EXEMPTION=true | ||
fi | ||
if [[ "$TITLE" == *"${ACCEPTED_TITLE}"* ]]; then | ||
echo "Title match..." | ||
EXEMPTION=true | ||
fi | ||
|
||
echo "EXEMPTION=$EXEMPTION" >> $GITHUB_OUTPUT | ||
- name: Generate PR comment if changes detected | ||
if: steps.check_module_changes.outputs.CHANGES_DETECTED == 'true' && steps.check_exemption.outputs.EXEMPTION == 'false' | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
with: | ||
script: | | ||
const body = `This PR is blocked from being reviewed. Please make direct changes to module_references from the upstream XML in https://github.com/nginx/nginx.org`; | ||
await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: body, | ||
}); | ||
- name: Fail job if changes detected | ||
if: steps.check_module_changes.outputs.CHANGES_DETECTED == 'true' && steps.check_exemption.outputs.EXEMPTION == 'false' | ||
run: | | ||
exit 0 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.