Skip to content

chore(ci): confirm workflow_run event #284

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

Merged
merged 5 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/scripts/enforce_acknowledgment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const {
PR_ACTION,
PR_AUTHOR,
PR_BODY,
PR_NUMBER,
IGNORE_AUTHORS,
LABEL_BLOCK,
LABEL_BLOCK_REASON
} = require("./constants")

module.exports = async ({github, context, core}) => {
if (IGNORE_AUTHORS.includes(PR_AUTHOR)) {
return core.notice("Author in IGNORE_AUTHORS list; skipping...")
}

if (PR_ACTION != "opened") {
return core.notice("Only newly open PRs are labelled to avoid spam; skipping")
}

const RELATED_ISSUE_REGEX = /Issue number:[^\d\r\n]+(?<issue>\d+)/;
const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY);
if (isMatch == null) {
core.info(`No related issue found, maybe the author didn't use the template but there is one.`)

let msg = "No related issues found. Please ensure there is an open issue related to this change to avoid significant delays or closure.";
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
body: msg,
issue_number: PR_NUMBER,
});

return await github.rest.issues.addLabels({
issue_number: PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [LABEL_BLOCK, LABEL_BLOCK_REASON]
})
}
}
1 change: 1 addition & 0 deletions .github/workflows/label_pr_on_title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
uses: ./.github/workflows/reusable_export_pr_details.yml
with:
record_pr_workflow_id: ${{ github.event.workflow_run.id }}
workflow_origin: ${{ github.event.repository.full_name }}
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
label_pr:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/on_merged_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
uses: ./.github/workflows/reusable_export_pr_details.yml
with:
record_pr_workflow_id: ${{ github.event.workflow_run.id }}
workflow_origin: ${{ github.event.repository.full_name }}
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
release_label_on_merge:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/on_opened_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ jobs:
get_pr_details:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: ./.github/workflows/reusable_export_pr_details.yml
env:
with:
record_pr_workflow_id: ${{ github.event.workflow_run.id }}
workflow_origin: ${{ github.event.repository.full_name }}
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
check_related_issue:
Expand All @@ -20,7 +22,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: "Debug workflow_run event"
run: echo ${{ toJSON(github.event) }}
run: echo "${{ github }}"
- name: "Ensure related issue is present"
uses: actions/github-script@v6
env:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/reusable_export_pr_details.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ on:
record_pr_workflow_id:
required: true
type: number
# this protects from anyone mimicking "Record PR details" dependency
# regardless of our untrusted input validation
workflow_origin:
required: true
type: string
secrets:
token:
required: true
Expand All @@ -32,6 +37,7 @@ on:

jobs:
export_pr_details:
if: inputs.workflow_origin == "bla/bla"
runs-on: ubuntu-latest
env:
FILENAME: pr.txt
Expand Down