Skip to content

Commit f902046

Browse files
authored
Merge branch 'awslabs:develop' into develop
2 parents 1b33c9e + 09f98f8 commit f902046

File tree

123 files changed

+7945
-2684
lines changed

Some content is hidden

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

123 files changed

+7945
-2684
lines changed

.github/boring-cyborg.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
##### Labeler ##########################################################################################################
22
labelPRBasedOnFilePath:
3-
area/utilities:
4-
- aws_lambda_powertools/utilities/*
5-
- aws_lambda_powertools/utilities/**/*
6-
- aws_lambda_powertools/middleware_factory/*
7-
- aws_lambda_powertools/middleware_factory/**/*
83
area/logger:
94
- aws_lambda_powertools/logging/*
105
- aws_lambda_powertools/logging/**/*
@@ -42,6 +37,13 @@ labelPRBasedOnFilePath:
4237
area/feature_flags:
4338
- aws_lambda_powertools/feature_flags/*
4439
- aws_lambda_powertools/feature_flags/**/*
40+
area/jmespath_util:
41+
- aws_lambda_powertools/utilities/jmespath_utils/*
42+
area/utilities:
43+
- aws_lambda_powertools/utilities/*
44+
- aws_lambda_powertools/utilities/**/*
45+
- aws_lambda_powertools/middleware_factory/*
46+
- aws_lambda_powertools/middleware_factory/**/*
4547

4648
documentation:
4749
- docs/*

.github/mergify.yml

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1+
queue_rules:
2+
- name: default
3+
conditions:
4+
# Conditions to get out of the queue (= merged)
5+
- check-success=Semantic Pull Request
6+
- "#approved-reviews-by>=1"
7+
- -title~=(WIP|wip)
8+
- -label~="do-not-merge"
9+
- "#changes-requested-reviews-by=0"
10+
111
pull_request_rules:
212
- name: automatic merge for Dependabot pull requests
313
conditions:
414
- author~=^dependabot(|-preview)\[bot\]$
5-
# - check-success=build # matrix jobs aren't working in mergify
6-
- -label~="do-not-merge"
7-
- "#approved-reviews-by>=1" # until we exclude major versions in dependabot
815
actions:
9-
merge:
10-
strict: false
16+
queue:
17+
name: default
1118
method: squash
1219
commit_message: title+body
1320

1421
- name: Automatic merge ⬇️ on approval ✔
1522
conditions:
1623
- base!=master
17-
- "#approved-reviews-by>=1"
18-
- "#changes-requested-reviews-by=0"
19-
- -title~=(WIP|wip)
20-
# - check-success=build # matrix jobs aren't working in mergify
21-
- check-success=Semantic Pull Request
22-
- body~=(?m)^\[X\] Meet tenets criteria
24+
- "#approved-reviews-by>=2"
2325
actions:
24-
merge:
25-
strict: smart
26+
queue:
27+
name: default
2628
method: squash
27-
strict_method: merge
2829
commit_message: title+body

.github/workflows/codeql-analysis.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ name: "CodeQL"
33
on:
44
push:
55
branches: [develop]
6-
pull_request:
7-
branches: [develop]
8-
schedule:
9-
- cron: '0 21 * * 0'
106

117
jobs:
128
analyze:
@@ -24,7 +20,7 @@ jobs:
2420

2521
steps:
2622
- name: Checkout repository
27-
uses: actions/checkout@v2
23+
uses: actions/checkout@v3
2824

2925
# Initializes the CodeQL tools for scanning.
3026
- name: Initialize CodeQL
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Label PR based on title
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Record PR number"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
upload:
11+
runs-on: ubuntu-latest
12+
# Guardrails to only ever run if PR recording workflow was indeed
13+
# run in a PR event and ran successfully
14+
if: >
15+
${{ github.event.workflow_run.event == 'pull_request' &&
16+
github.event.workflow_run.conclusion == 'success' }}
17+
steps:
18+
- name: 'Download artifact'
19+
uses: actions/github-script@v6
20+
# For security, we only download artifacts tied to the successful PR recording workflow
21+
with:
22+
script: |
23+
const fs = require('fs');
24+
25+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
run_id: ${{github.event.workflow_run.id }},
29+
});
30+
31+
const matchArtifact = artifacts.data.artifacts.filter(artifact => artifact.name == "pr")[0];
32+
33+
const artifact = await github.rest.actions.downloadArtifact({
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
artifact_id: matchArtifact.id,
37+
archive_format: 'zip',
38+
});
39+
40+
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(artifact.data));
41+
# NodeJS standard library doesn't provide ZIP capabilities; use system `unzip` command instead
42+
- run: unzip pr.zip
43+
44+
- name: 'Label PR based on title'
45+
uses: actions/github-script@v6
46+
with:
47+
github-token: ${{ secrets.GITHUB_TOKEN }}
48+
# This safely runs in our base repo, not on fork
49+
# thus allowing us to provide a write access token to label based on PR title
50+
# and label PR based on semantic title accordingly
51+
script: |
52+
const fs = require('fs');
53+
const pr_number = Number(fs.readFileSync('./number'));
54+
const pr_title = fs.readFileSync('./title', 'utf-8').trim();
55+
56+
const FEAT_REGEX = /feat(\((.+)\))?(\:.+)/
57+
const BUG_REGEX = /(fix|bug)(\((.+)\))?(\:.+)/
58+
const DOCS_REGEX = /(docs|doc)(\((.+)\))?(\:.+)/
59+
const CHORE_REGEX = /(chore)(\((.+)\))?(\:.+)/
60+
const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(\:.+)/
61+
const REFACTOR_REGEX = /(refactor)(\((.+)\))?(\:.+)/
62+
63+
const labels = {
64+
"feature": FEAT_REGEX,
65+
"bug": BUG_REGEX,
66+
"documentation": DOCS_REGEX,
67+
"internal": CHORE_REGEX,
68+
"enhancement": REFACTOR_REGEX,
69+
"deprecated": DEPRECATED_REGEX,
70+
}
71+
72+
for (const label in labels) {
73+
const matcher = new RegExp(labels[label])
74+
const isMatch = matcher.exec(pr_title)
75+
if (isMatch != null) {
76+
console.info(`Auto-labeling PR ${pr_number} with ${label}`)
77+
78+
await github.rest.issues.addLabels({
79+
issue_number: pr_number,
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
labels: [label]
83+
})
84+
85+
break
86+
}
87+
}

.github/workflows/post_release.js

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
const STAGED_LABEL = "status/staged-next-release";
2+
3+
/**
4+
* Fetch issues using GitHub REST API
5+
*
6+
* @param {object} gh_client - Pre-authenticated REST client (Octokit)
7+
* @param {string} org - GitHub Organization
8+
* @param {string} repository - GitHub repository
9+
* @param {string} state - GitHub issue state (open, closed)
10+
* @param {string} label - Comma-separated issue labels to fetch
11+
* @return {Object[]} issues - Array of issues matching params
12+
* @see {@link https://octokit.github.io/rest.js/v18#usage|Octokit client}
13+
*/
14+
const fetchIssues = async ({
15+
gh_client,
16+
org,
17+
repository,
18+
state = "open",
19+
label = STAGED_LABEL,
20+
}) => {
21+
22+
try {
23+
const { data: issues } = await gh_client.rest.issues.listForRepo({
24+
owner: org,
25+
repo: repository,
26+
state: state,
27+
labels: label,
28+
});
29+
30+
return issues;
31+
32+
} catch (error) {
33+
console.error(error);
34+
throw new Error("Failed to fetch issues")
35+
}
36+
37+
};
38+
39+
/**
40+
* Notify new release and close staged GitHub issue
41+
*
42+
* @param {object} gh_client - Pre-authenticated REST client (Octokit)
43+
* @param {string} owner - GitHub Organization
44+
* @param {string} repository - GitHub repository
45+
* @param {string} release_version - GitHub Release version
46+
* @see {@link https://octokit.github.io/rest.js/v18#usage|Octokit client}
47+
*/
48+
const notifyRelease = async ({
49+
gh_client,
50+
owner,
51+
repository,
52+
release_version,
53+
}) => {
54+
const release_url = `https://github.com/${owner}/${repository}/releases/tag/v${release_version}`;
55+
56+
const issues = await fetchIssues({
57+
gh_client: gh_client,
58+
org: owner,
59+
repository: repository,
60+
});
61+
62+
issues.forEach(async (issue) => {
63+
console.info(`Updating issue number ${issue.number}`);
64+
65+
const comment = `This is now released under [${release_version}](${release_url}) version!`;
66+
try {
67+
await gh_client.rest.issues.createComment({
68+
owner: owner,
69+
repo: repository,
70+
body: comment,
71+
issue_number: issue.number,
72+
});
73+
} catch (error) {
74+
console.error(error);
75+
throw new Error(`Failed to update issue ${issue.number} about ${release_version} release`)
76+
}
77+
78+
79+
// Close issue and remove staged label; keep existing ones
80+
const labels = issue.labels
81+
.filter((label) => label.name != STAGED_LABEL)
82+
.map((label) => label.name);
83+
84+
try {
85+
await gh_client.rest.issues.update({
86+
repo: repository,
87+
owner: owner,
88+
issue_number: issue.number,
89+
state: "closed",
90+
labels: labels,
91+
});
92+
} catch (error) {
93+
console.error(error);
94+
throw new Error("Failed to close issue")
95+
}
96+
97+
console.info(`Issue number ${issue.number} closed and updated`);
98+
});
99+
};
100+
101+
// context: https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts
102+
module.exports = async ({ github, context }) => {
103+
const { RELEASE_TAG_VERSION } = process.env;
104+
console.log(`Running post-release script for ${RELEASE_TAG_VERSION} version`);
105+
106+
await notifyRelease({
107+
gh_client: github,
108+
owner: context.repo.owner,
109+
repository: context.repo.repo,
110+
release_version: RELEASE_TAG_VERSION,
111+
});
112+
};

.github/workflows/publish.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ name: Publish to PyPi
2222
# 8. Builds a fresh version of docs including Changelog updates
2323
# 9. Push latest release source code to master using release title as the commit message
2424
# 10. Builds latest documentation for new release, and update latest alias pointing to the new release tag
25+
# 11. Close and notify all issues labeled "status/staged-next-release" about the release details
2526

2627
#
2728
# === Fallback mechanism due to external failures ===
@@ -44,11 +45,11 @@ jobs:
4445
release:
4546
runs-on: ubuntu-latest
4647
steps:
47-
- uses: actions/checkout@v2
48+
- uses: actions/checkout@v3
4849
with:
4950
fetch-depth: 0
5051
- name: Set up Python
51-
uses: actions/setup-python@v2.3.1
52+
uses: actions/setup-python@v3
5253
with:
5354
python-version: "3.8"
5455
- name: Set release notes tag
@@ -107,12 +108,18 @@ jobs:
107108
publish_dir: ./api
108109
keep_files: true
109110
destination_dir: latest/api
111+
- name: Close issues related to this release
112+
uses: actions/github-script@v6
113+
with:
114+
script: |
115+
const post_release = require('.github/workflows/post_release.js')
116+
await post_release({github, context, core})
110117
111118
sync_master:
112119
needs: release
113120
runs-on: ubuntu-latest
114121
steps:
115-
- uses: actions/checkout@v2
122+
- uses: actions/checkout@v3
116123
- name: Sync master from detached head
117124
# If version matches CHANGELOG and pyproject.toml
118125
# If it passes all checks, successfully releases to test and prod

.github/workflows/python_build.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ jobs:
2121
OS: ${{ matrix.os }}
2222
PYTHON: ${{ matrix.python-version }}
2323
steps:
24-
- uses: actions/checkout@v1
24+
- uses: actions/checkout@v3
2525
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v2.3.1
26+
uses: actions/setup-python@v3
2727
with:
2828
python-version: ${{ matrix.python-version }}
2929
- name: Install dependencies
3030
run: make dev
3131
- name: Formatting and Linting
3232
run: make lint
33+
- name: Static type checking
34+
run: make mypy
3335
- name: Test with pytest
3436
run: make test
3537
- name: Security baseline

.github/workflows/python_docs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
docs:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v3
1717
with:
1818
fetch-depth: 0
1919
- name: Set up Python
20-
uses: actions/setup-python@v2.3.1
20+
uses: actions/setup-python@v3
2121
with:
2222
python-version: "3.8"
2323
- name: Install dependencies

.github/workflows/rebuild_latest_docs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ jobs:
2121
release:
2222
runs-on: ubuntu-latest
2323
steps:
24-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v3
2525
with:
2626
fetch-depth: 0
2727
- name: Set up Python
28-
uses: actions/setup-python@v2.3.1
28+
uses: actions/setup-python@v3
2929
with:
3030
python-version: "3.8"
3131
- name: Set release notes tag

0 commit comments

Comments
 (0)