Skip to content

Commit b70d73d

Browse files
author
Michal Ploski
committed
Merge branch 'develop' into fix/batch-sqs-handler-delete-message-batch-needs-batched
2 parents 7bcce12 + 6869155 commit b70d73d

File tree

127 files changed

+8374
-2981
lines changed

Some content is hidden

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

127 files changed

+8374
-2981
lines changed

.github/boring-cyborg.yml

Lines changed: 7 additions & 5 deletions
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

Lines changed: 15 additions & 14 deletions
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

Lines changed: 0 additions & 4 deletions
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:
Lines changed: 87 additions & 0 deletions
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@v5
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@v5
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

Lines changed: 112 additions & 0 deletions
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

Lines changed: 10 additions & 22 deletions
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 ===
@@ -33,23 +34,12 @@ name: Publish to PyPi
3334
#
3435
# === Documentation hotfix ===
3536
#
36-
# 1. Trigger "Publish to PyPi" workflow manually: https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
37-
# 2. Use the latest version released under Releases e.g. v1.21.1
38-
# 3. Set `Build and publish docs only` field to `true`
37+
# Look for rebuild latest docs workflow
3938

4039

4140
on:
4241
release:
4342
types: [published]
44-
workflow_dispatch:
45-
inputs:
46-
publish_version:
47-
description: 'Version to publish, e.g. v1.13.0'
48-
required: true
49-
publish_docs_only:
50-
description: 'Build and publish docs only'
51-
required: false
52-
default: 'false'
5343

5444
jobs:
5545
release:
@@ -59,46 +49,39 @@ jobs:
5949
with:
6050
fetch-depth: 0
6151
- name: Set up Python
62-
uses: actions/setup-python@v2.2.2
52+
uses: actions/setup-python@v2.3.1
6353
with:
6454
python-version: "3.8"
6555
- name: Set release notes tag
6656
run: |
6757
RELEASE_TAG_VERSION=${{ github.event.release.tag_name }}
68-
# Replace publishing version if the workflow was triggered manually
69-
test -n ${RELEASE_TAG_VERSION} && RELEASE_TAG_VERSION=${{ github.event.inputs.publish_version }}
7058
echo "RELEASE_TAG_VERSION=${RELEASE_TAG_VERSION:1}" >> $GITHUB_ENV
7159
- name: Ensure new version is also set in pyproject and CHANGELOG
72-
if: ${{ github.event.inputs.publish_docs_only == false }}
7360
run: |
7461
grep --regexp "${RELEASE_TAG_VERSION}" CHANGELOG.md
7562
grep --regexp "version \= \"${RELEASE_TAG_VERSION}\"" pyproject.toml
7663
- name: Install dependencies
7764
run: make dev
7865
- name: Run all tests, linting and baselines
79-
if: ${{ github.event.inputs.publish_docs_only == false }}
8066
run: make pr
8167
- name: Build python package and wheel
82-
if: ${{ github.event.inputs.publish_docs_only == false }}
8368
run: poetry build
8469
- name: Upload to PyPi test
85-
if: ${{ github.event.inputs.publish_docs_only == false }}
8670
run: make release-test
8771
env:
8872
PYPI_USERNAME: __token__
8973
PYPI_TEST_TOKEN: ${{ secrets.PYPI_TEST_TOKEN }}
9074
- name: Upload to PyPi prod
91-
if: ${{ github.event.inputs.publish_docs_only == false }}
9275
run: make release-prod
9376
env:
9477
PYPI_USERNAME: __token__
9578
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
9679
- name: publish lambda layer in SAR by triggering the internal codepipeline
97-
if: ${{ github.event.inputs.publish_docs_only == false }}
9880
run: |
9981
aws ssm put-parameter --name "powertools-python-release-version" --value $RELEASE_TAG_VERSION --overwrite
10082
aws codepipeline start-pipeline-execution --name ${{ secrets.CODEPIPELINE_NAME }}
10183
env:
84+
# Maintenance: Migrate to new OAuth mechanism
10285
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
10386
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
10487
AWS_DEFAULT_REGION: eu-west-1
@@ -125,11 +108,16 @@ jobs:
125108
publish_dir: ./api
126109
keep_files: true
127110
destination_dir: latest/api
111+
- name: Close issues related to this release
112+
uses: actions/github-script@v5
113+
with:
114+
script: |
115+
const post_release = require('.github/workflows/post_release.js')
116+
await post_release({github, context, core})
128117
129118
sync_master:
130119
needs: release
131120
runs-on: ubuntu-latest
132-
if: ${{ github.event.inputs.publish_docs_only == false }}
133121
steps:
134122
- uses: actions/checkout@v2
135123
- name: Sync master from detached head

.github/workflows/python_build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ jobs:
2323
steps:
2424
- uses: actions/checkout@v1
2525
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v2.2.2
26+
uses: actions/setup-python@v2.3.1
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

0 commit comments

Comments
 (0)