Skip to content

Commit 6ad08c6

Browse files
authored
Merge pull request #179 from sliedig/sliedig-ci
chore(ci): updated workflows
2 parents f225e96 + 8490258 commit 6ad08c6

15 files changed

+381
-36
lines changed

.github/ISSUE_TEMPLATE/config.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const {
2+
PR_NUMBER,
3+
PR_ACTION,
4+
PR_AUTHOR,
5+
IGNORE_AUTHORS,
6+
} = require("./constants")
7+
8+
9+
/**
10+
* Notify PR author to split XXL PR in smaller chunks
11+
*
12+
* @param {object} core - core functions instance from @actions/core
13+
* @param {object} gh_client - Pre-authenticated REST client (Octokit)
14+
* @param {string} owner - GitHub Organization
15+
* @param {string} repository - GitHub repository
16+
*/
17+
const notifyAuthor = async ({
18+
core,
19+
gh_client,
20+
owner,
21+
repository,
22+
}) => {
23+
core.info(`Commenting on PR ${PR_NUMBER}`)
24+
25+
let msg = `### ⚠️Large PR detected⚠️
26+
27+
Please consider breaking into smaller PRs to avoid significant review delays. Ignore if this PR has naturally grown to this size after reviews.
28+
`;
29+
30+
try {
31+
await gh_client.rest.issues.createComment({
32+
owner: owner,
33+
repo: repository,
34+
body: msg,
35+
issue_number: PR_NUMBER,
36+
});
37+
} catch (error) {
38+
core.setFailed("Failed to notify PR author to split large PR");
39+
console.error(err);
40+
}
41+
}
42+
43+
module.exports = async ({github, context, core}) => {
44+
if (IGNORE_AUTHORS.includes(PR_AUTHOR)) {
45+
return core.notice("Author in IGNORE_AUTHORS list; skipping...")
46+
}
47+
48+
if (PR_ACTION != "labeled") {
49+
return core.notice("Only run on PRs labeling actions; skipping")
50+
}
51+
52+
53+
/** @type {string[]} */
54+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
issue_number: PR_NUMBER,
58+
})
59+
60+
// Schema: https://docs.github.com/en/rest/issues/labels#list-labels-for-an-issue
61+
for (const label of labels) {
62+
core.info(`Label: ${label}`)
63+
if (label.name == "size/XXL") {
64+
await notifyAuthor({
65+
core: core,
66+
gh_client: github,
67+
owner: context.repo.owner,
68+
repository: context.repo.repo,
69+
})
70+
break;
71+
}
72+
}
73+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const {
2+
PR_ACTION,
3+
PR_AUTHOR,
4+
PR_BODY,
5+
PR_NUMBER,
6+
IGNORE_AUTHORS,
7+
LABEL_BLOCK,
8+
LABEL_BLOCK_REASON
9+
} = require("./constants")
10+
11+
module.exports = async ({github, context, core}) => {
12+
if (IGNORE_AUTHORS.includes(PR_AUTHOR)) {
13+
return core.notice("Author in IGNORE_AUTHORS list; skipping...")
14+
}
15+
16+
if (PR_ACTION != "opened") {
17+
return core.notice("Only newly open PRs are labelled to avoid spam; skipping")
18+
}
19+
20+
const RELATED_ISSUE_REGEX = /Issue number:[^\d\r\n]+(?<issue>\d+)/;
21+
const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY);
22+
if (isMatch == null) {
23+
core.info(`No related issue found, maybe the author didn't use the template but there is one.`)
24+
25+
let msg = "No related issues found. Please ensure there is an open issue related to this change to avoid significant delays or closure.";
26+
await github.rest.issues.createComment({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
body: msg,
30+
issue_number: PR_NUMBER,
31+
});
32+
33+
return await github.rest.issues.addLabels({
34+
issue_number: PR_NUMBER,
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
labels: [LABEL_BLOCK, LABEL_BLOCK_REASON]
38+
})
39+
}
40+
}

.github/scripts/label_pr_based_on_title.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { PR_NUMBER, PR_TITLE, AREAS } = require("./constants")
1+
const { PR_NUMBER, PR_TITLE } = require("./constants")
22

33
module.exports = async ({github, context, core}) => {
44
const FEAT_REGEX = /feat(\((.+)\))?(:.+)/
@@ -33,19 +33,6 @@ module.exports = async ({github, context, core}) => {
3333
labels: [label]
3434
})
3535

36-
const area = matches[2]; // second capture group contains the area
37-
if (AREAS.indexOf(area) > -1) {
38-
core.info(`Auto-labeling PR ${PR_NUMBER} with area ${area}`);
39-
await github.rest.issues.addLabels({
40-
issue_number: PR_NUMBER,
41-
owner: context.repo.owner,
42-
repo: context.repo.repo,
43-
labels: [`area/${area}`],
44-
});
45-
} else {
46-
core.debug(`'${PR_TITLE}' didn't match any known area.`);
47-
}
48-
4936
return;
5037
} else {
5138
core.debug(`'${PR_TITLE}' didn't match '${label}' semantic.`)

.github/scripts/label_related_issue.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = async ({github, context, core}) => {
4040

4141
try {
4242
core.info(`Auto-labeling related issue ${issue} for release`)
43-
await github.rest.issues.addLabels({
43+
return await github.rest.issues.addLabels({
4444
issue_number: issue,
4545
owner: context.repo.owner,
4646
repo: context.repo.repo,
@@ -50,14 +50,4 @@ module.exports = async ({github, context, core}) => {
5050
core.setFailed(`Is this issue number (${issue}) valid? Perhaps a discussion?`);
5151
throw new Error(error);
5252
}
53-
54-
const { groups: {relatedIssueNumber} } = isMatch
55-
56-
core.info(`Auto-labeling related issue ${relatedIssueNumber} for release`)
57-
return await github.rest.issues.addLabels({
58-
issue_number: relatedIssueNumber,
59-
owner: context.repo.owner,
60-
repo: context.repo.repo,
61-
labels: [relatedIssueNumber]
62-
})
6353
}

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v3
1919
- name: Setup .NET 6.0
20-
uses: actions/setup-dotnet@v1
20+
uses: actions/setup-dotnet@v3
2121
with:
2222
dotnet-version: 6.0.302
2323
- name: Install solution dependencies

.github/workflows/build_changelog.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Standalone workflow to update changelog if necessary
2+
name: Build changelog
3+
4+
on:
5+
workflow_dispatch:
6+
7+
jobs:
8+
changelog:
9+
uses: ./.github/workflows/reusable_publish_changelog.yml

.github/workflows/on_label_added.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: On Label added
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Record PR details"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
get_pr_details:
11+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
12+
uses: ./.github/workflows/reusable_export_pr_details.yml
13+
with:
14+
record_pr_workflow_id: ${{ github.event.workflow_run.id }}
15+
workflow_origin: ${{ github.event.repository.full_name }}
16+
secrets:
17+
token: ${{ secrets.GITHUB_TOKEN }}
18+
19+
split-large-pr:
20+
needs: get_pr_details
21+
runs-on: ubuntu-latest
22+
permissions:
23+
issues: write
24+
pull-requests: write
25+
steps:
26+
- uses: actions/checkout@v3
27+
# Maintenance: Persist state per PR as an artifact to avoid spam on label add
28+
- name: "Suggest split large Pull Request"
29+
uses: actions/github-script@v6
30+
env:
31+
PR_NUMBER: ${{ needs.get_pr_details.outputs.prNumber }}
32+
PR_ACTION: ${{ needs.get_pr_details.outputs.prAction }}
33+
PR_AUTHOR: ${{ needs.get_pr_details.outputs.prAuthor }}
34+
with:
35+
github-token: ${{ secrets.GITHUB_TOKEN }}
36+
script: |
37+
const script = require('.github/scripts/comment_on_large_pr.js');
38+
await script({github, context, core});

.github/workflows/on_opened_pr.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@v3
23-
- name: "Debug workflow_run event"
24-
run: echo "${{ github }}"
2523
- name: "Ensure related issue is present"
2624
uses: actions/github-script@v6
2725
env:

.github/workflows/on_push_docs.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
paths:
8+
- "docs/**"
9+
- "mkdocs.yml"
10+
- "examples/**"
11+
12+
jobs:
13+
changelog:
14+
permissions:
15+
contents: write
16+
uses: ./.github/workflows/reusable_publish_changelog.yml
17+
18+
release-docs:
19+
needs: changelog
20+
permissions:
21+
contents: write
22+
pages: write
23+
uses: ./.github/workflows/reusable_publish_docs.yml
24+
with:
25+
version: develop
26+
alias: stage
27+
# Maintenance: Only necessary in repo migration
28+
# - name: Create redirect from old docs
29+
# run: |
30+
# git checkout gh-pages
31+
# test -f 404.html && echo "Redirect already set" && exit 0
32+
# git checkout develop -- 404.html
33+
# git add 404.html
34+
# git commit -m "chore: set docs redirect" --no-verify
35+
# git push origin gh-pages -f

0 commit comments

Comments
 (0)