Skip to content

Commit 91500de

Browse files
author
Michal Ploski
committed
Merge branch 'develop' into feature/e2e-tests
2 parents 9db0dcd + 83e6091 commit 91500de

File tree

221 files changed

+5876
-3688
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

221 files changed

+5876
-3688
lines changed

.github/mergify.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
# - name: Automatic merge ⬇️ on approval ✔
2424
# conditions:
25-
# - base!=master
2625
# - "#approved-reviews-by>=2"
2726
# actions:
2827
# queue:

.github/scripts/constants.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module.exports = Object.freeze({
2+
/** @type {string} */
3+
// Values: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
4+
"PR_ACTION": process.env.PR_ACTION || "",
5+
6+
/** @type {string} */
7+
"PR_AUTHOR": process.env.PR_AUTHOR || "",
8+
9+
/** @type {string} */
10+
"PR_BODY": process.env.PR_BODY || "",
11+
12+
/** @type {string} */
13+
"PR_TITLE": process.env.PR_TITLE || "",
14+
15+
/** @type {number} */
16+
"PR_NUMBER": process.env.PR_NUMBER || 0,
17+
18+
/** @type {boolean} */
19+
"PR_IS_MERGED": process.env.PR_IS_MERGED || false,
20+
21+
/** @type {string} */
22+
"LABEL_BLOCK": "do-not-merge",
23+
24+
/** @type {string} */
25+
"LABEL_BLOCK_REASON": "need-issue",
26+
27+
/** @type {string} */
28+
"LABEL_PENDING_RELEASE": "pending-release",
29+
30+
/** @type {string} */
31+
"HANDLE_MAINTAINERS_TEAM": "@awslabs/aws-lambda-powertools-python",
32+
33+
/** @type {string[]} */
34+
"IGNORE_AUTHORS": ["dependabot[bot]", "markdownify[bot]"],
35+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = async ({github, context, core}) => {
2+
const fs = require('fs');
3+
4+
const workflowRunId = process.env.WORKFLOW_ID;
5+
core.info(`Listing artifacts for workflow run ${workflowRunId}`);
6+
7+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
8+
owner: context.repo.owner,
9+
repo: context.repo.repo,
10+
run_id: workflowRunId,
11+
});
12+
13+
const matchArtifact = artifacts.data.artifacts.filter(artifact => artifact.name == "pr")[0];
14+
15+
core.info(`Downloading artifacts for workflow run ${workflowRunId}`);
16+
const artifact = await github.rest.actions.downloadArtifact({
17+
owner: context.repo.owner,
18+
repo: context.repo.repo,
19+
artifact_id: matchArtifact.id,
20+
archive_format: 'zip',
21+
});
22+
23+
core.info("Saving artifact found", artifact);
24+
25+
fs.writeFileSync('pr.zip', Buffer.from(artifact.data));
26+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
core.debug(`Number: ${PR_BODY}`);
13+
core.debug(`Action: ${PR_ACTION}`);
14+
core.debug(`Author: ${PR_AUTHOR}`);
15+
core.debug(`Body: ${PR_BODY}`);
16+
17+
if (IGNORE_AUTHORS.includes(PR_AUTHOR)) {
18+
return core.notice("Author in IGNORE_AUTHORS list; skipping...")
19+
}
20+
21+
if (PR_ACTION != "opened") {
22+
return core.notice("Only newly open PRs are labelled to avoid spam; skipping")
23+
}
24+
25+
const RELATED_ISSUE_REGEX = /Issue number:[^\d\r\n]+(?<issue>\d+)/;
26+
const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY);
27+
if (isMatch == null) {
28+
core.info(`No related issue found, maybe the author didn't use the template but there is one.`)
29+
30+
let msg = "No related issues found. Please ensure there is an open issue related to this change to avoid significant delays or closure.";
31+
await github.rest.issues.createComment({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
body: msg,
35+
issue_number: PR_NUMBER,
36+
});
37+
38+
return await github.rest.issues.addLabels({
39+
issue_number: PR_NUMBER,
40+
owner: context.repo.owner,
41+
repo: context.repo.repo,
42+
labels: [LABEL_BLOCK, LABEL_BLOCK_REASON]
43+
})
44+
}
45+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const { PR_NUMBER, PR_TITLE } = require("./constants")
2+
3+
module.exports = async ({github, context, core}) => {
4+
core.debug(PR_NUMBER);
5+
core.debug(PR_TITLE);
6+
7+
const FEAT_REGEX = /feat(\((.+)\))?(\:.+)/
8+
const BUG_REGEX = /(fix|bug)(\((.+)\))?(\:.+)/
9+
const DOCS_REGEX = /(docs|doc)(\((.+)\))?(\:.+)/
10+
const CHORE_REGEX = /(chore)(\((.+)\))?(\:.+)/
11+
const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(\:.+)/
12+
const REFACTOR_REGEX = /(refactor)(\((.+)\))?(\:.+)/
13+
14+
const labels = {
15+
"feature": FEAT_REGEX,
16+
"bug": BUG_REGEX,
17+
"documentation": DOCS_REGEX,
18+
"internal": CHORE_REGEX,
19+
"enhancement": REFACTOR_REGEX,
20+
"deprecated": DEPRECATED_REGEX,
21+
}
22+
23+
// Maintenance: We should keep track of modified PRs in case their titles change
24+
for (const label in labels) {
25+
const matcher = new RegExp(labels[label])
26+
const isMatch = matcher.exec(PR_TITLE)
27+
if (isMatch != null) {
28+
core.info(`Auto-labeling PR ${PR_NUMBER} with ${label}`)
29+
30+
await github.rest.issues.addLabels({
31+
issue_number: PR_NUMBER,
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
labels: [label]
35+
})
36+
37+
break
38+
}
39+
}
40+
41+
return core.notice(`PR ${PR_NUMBER} title '${PR_TITLE}' doesn't follow semantic titles; skipping...`)
42+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const {
2+
PR_AUTHOR,
3+
PR_BODY,
4+
PR_NUMBER,
5+
IGNORE_AUTHORS,
6+
LABEL_PENDING_RELEASE,
7+
HANDLE_MAINTAINERS_TEAM,
8+
PR_IS_MERGED,
9+
} = require("./constants")
10+
11+
module.exports = async ({github, context, core}) => {
12+
core.debug(PR_BODY);
13+
core.debug(PR_IS_MERGED);
14+
core.debug(PR_AUTHOR);
15+
16+
if (IGNORE_AUTHORS.includes(PR_AUTHOR)) {
17+
return core.notice("Author in IGNORE_AUTHORS list; skipping...")
18+
}
19+
20+
if (!PR_IS_MERGED) {
21+
return core.notice("Only merged PRs to avoid spam; skipping")
22+
}
23+
24+
25+
const RELATED_ISSUE_REGEX = /Issue number:[^\d\r\n]+(?<issue>\d+)/;
26+
const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY);
27+
if (!isMatch) {
28+
core.setFailed(`Unable to find related issue for PR number ${PR_NUMBER}.\n\n Body details: ${PR_BODY}`);
29+
return await github.rest.issues.createComment({
30+
owner: context.repo.owner,
31+
repo: context.repo.repo,
32+
body: `${HANDLE_MAINTAINERS_TEAM} No related issues found. Please ensure '${LABEL_PENDING_RELEASE}' label is applied before releasing.`,
33+
issue_number: PR_NUMBER,
34+
});
35+
}
36+
37+
const { groups: {issue} } = isMatch
38+
39+
core.info(`Auto-labeling related issue ${issue} for release`)
40+
return await github.rest.issues.addLabels({
41+
issue_number: issue,
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
labels: [LABEL_PENDING_RELEASE]
45+
})
46+
}
File renamed without changes.

.github/scripts/save_pr_details.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = async ({github, context, core}) => {
2+
const fs = require('fs');
3+
const filename = "pr.txt";
4+
5+
try {
6+
core.debug("Payload as it comes..");
7+
core.debug(context.payload);
8+
fs.writeFileSync(`./${filename}`, JSON.stringify(context.payload));
9+
10+
return `PR successfully saved ${filename}`
11+
} catch (err) {
12+
core.setFailed("Failed to save PR details");
13+
console.error(err);
14+
}
15+
}

.github/workflows/auto-merge.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,25 @@ jobs:
1414
steps:
1515
- name: Dependabot metadata
1616
id: metadata
17-
uses: dependabot/fetch-metadata@v1.1.1
17+
uses: dependabot/fetch-metadata@v1.3.3
1818
with:
1919
github-token: "${{ secrets.GITHUB_TOKEN }}"
2020
- name: Enable auto-merge for mypy-boto3 stubs Dependabot PRs
21-
if: ${{contains(steps.metadata.outputs.dependency-names, 'mypy-boto3')}} # && steps.metadata.outputs.update-type == 'version-update:semver-patch'
21+
if: ${{ contains(steps.metadata.outputs.dependency-names, 'mypy-boto3') && steps.metadata.outputs.update-type != 'version-update:semver-major' }}
22+
run: gh pr merge --auto --squash "$PR_URL"
23+
env:
24+
PR_URL: ${{github.event.pull_request.html_url}}
25+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
26+
# Maintenance: Experiment with literal array (toJSON('["dep1", "dep2"]')) to ease extending it
27+
- name: Enable auto-merge for CDK Construct Lambda Layer Dependabot PRs
28+
if: ${{ contains(steps.metadata.outputs.dependency-names, 'cdk-lambda-powertools-python-layer') && steps.metadata.outputs.update-type != 'version-update:semver-major' }}
29+
run: gh pr merge --auto --squash "$PR_URL"
30+
env:
31+
PR_URL: ${{github.event.pull_request.html_url}}
32+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
33+
# Maintenance: Revisit if CDK Constructs make breaking changes like CDK v1
34+
- name: Enable auto-merge for CDK Lib Construct
35+
if: ${{ contains(steps.metadata.outputs.dependency-names, 'aws-cdk-lib') && steps.metadata.outputs.update-type != 'version-update:semver-major' }}
2236
run: gh pr merge --auto --squash "$PR_URL"
2337
env:
2438
PR_URL: ${{github.event.pull_request.html_url}}

.github/workflows/export_pr_details.yml

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)