Skip to content

Commit ed763d6

Browse files
committed
chore: sync trunk ci with v2
Signed-off-by: heitorlessa <[email protected]>
1 parent 4f75045 commit ed763d6

15 files changed

+442
-73
lines changed
+73
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+
}

.github/workflows/build_changelog.yml

+9
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/codeql-analysis.yml

+15-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "CodeQL"
22

33
on:
44
push:
5-
branches: [develop]
5+
branches: [develop, v2]
66

77
jobs:
88
analyze:
@@ -14,23 +14,23 @@ jobs:
1414
matrix:
1515
# Override automatic language detection by changing the below list
1616
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
17-
language: ['python']
17+
language: ["python"]
1818
# Learn more...
1919
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
2020

2121
steps:
22-
- name: Checkout repository
23-
uses: actions/checkout@v3
22+
- name: Checkout repository
23+
uses: actions/checkout@v3
2424

25-
# Initializes the CodeQL tools for scanning.
26-
- name: Initialize CodeQL
27-
uses: github/codeql-action/init@v2
28-
with:
29-
languages: ${{ matrix.language }}
30-
# If you wish to specify custom queries, you can do so here or in a config file.
31-
# By default, queries listed here will override any specified in a config file.
32-
# Prefix the list here with "+" to use these queries and those in the config file.
33-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
25+
# Initializes the CodeQL tools for scanning.
26+
- name: Initialize CodeQL
27+
uses: github/codeql-action/init@v2
28+
with:
29+
languages: ${{ matrix.language }}
30+
# If you wish to specify custom queries, you can do so here or in a config file.
31+
# By default, queries listed here will override any specified in a config file.
32+
# Prefix the list here with "+" to use these queries and those in the config file.
33+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
3434

35-
- name: Perform CodeQL Analysis
36-
uses: github/codeql-action/analyze@v2
35+
- name: Perform CodeQL Analysis
36+
uses: github/codeql-action/analyze@v2

.github/workflows/on_label_added.yml

+38
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

-2
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

+35
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
+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Publish to PyPi
2+
3+
# RELEASE PROCESS
4+
#
5+
# === Manual activities ===
6+
#
7+
# 1. Edit the current draft release notes
8+
# 2. If not already set, use `v<new version>` as a tag, e.g., v1.26.4, and select develop as target branch
9+
#
10+
# === Automated activities ===
11+
#
12+
# 1. Extract release notes tag that was published
13+
# 2. Run tests, linting, security and complexity base line
14+
# 3. Bump package version and generate latest Changelog
15+
# 4. Publish package to PyPi test and prod repository
16+
# 5. Kick off SAR App pipeline to publish latest version with minimal and extra dependencies
17+
# 6. Builds and publish latest changelog from tip of the branch
18+
# 7. Builds a new user guide and API docs with release version; update /latest pointing to newly released version
19+
# 8. Close all issues labeled "pending-release" and notify customers about the release
20+
21+
# See MAINTAINERS.md "Releasing a new version" for release mechanisms
22+
23+
env:
24+
BRANCH: develop
25+
26+
on:
27+
release:
28+
types: [published]
29+
workflow_dispatch:
30+
inputs:
31+
version_to_publish:
32+
description: "Version to be released in PyPi, Docs, and Lambda Layer, e.g. v1.26.4"
33+
default: v1.26.4
34+
required: true
35+
skip_pypi:
36+
description: "Skip publishing to PyPi as it can't publish more than once. Useful for semi-failed releases"
37+
default: false
38+
type: boolean
39+
required: false
40+
skip_code_quality:
41+
description: "Skip tests, linting, and baseline. Only use if release fail for reasons beyond our control and you need a quick release."
42+
default: false
43+
type: boolean
44+
required: false
45+
46+
jobs:
47+
release:
48+
environment: release
49+
runs-on: ubuntu-latest
50+
permissions:
51+
id-token: write
52+
contents: read
53+
outputs:
54+
RELEASE_VERSION: ${{ steps.release_version.outputs.RELEASE_VERSION }}
55+
env:
56+
RELEASE_TAG_VERSION: ${{ github.event.release.tag_name || inputs.version_to_publish }}
57+
steps:
58+
- uses: actions/checkout@v3
59+
with:
60+
fetch-depth: 0
61+
- name: Install poetry
62+
run: pipx install poetry
63+
- name: Set up Python
64+
uses: actions/setup-python@v4
65+
with:
66+
python-version: "3.8"
67+
cache: "poetry"
68+
- name: Set release notes tag
69+
id: release_version
70+
# transform tag format `v<version` to `<version`
71+
run: |
72+
RELEASE_VERSION="${RELEASE_TAG_VERSION:1}"
73+
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "$GITHUB_ENV"
74+
echo "::set-output name=RELEASE_VERSION::${RELEASE_VERSION}"
75+
- name: Install dependencies
76+
run: make dev
77+
- name: Run all tests, linting and baselines
78+
if: ${{ !inputs.skip_code_quality }}
79+
run: make pr
80+
- name: Bump package version
81+
run: poetry version "${RELEASE_VERSION}"
82+
- name: Build python package and wheel
83+
if: ${{ !inputs.skip_pypi }}
84+
run: poetry build
85+
- name: Upload to PyPi test
86+
if: ${{ !inputs.skip_pypi }}
87+
run: make release-test
88+
env:
89+
PYPI_USERNAME: __token__
90+
PYPI_TEST_TOKEN: ${{ secrets.PYPI_TEST_TOKEN }}
91+
- name: Upload to PyPi prod
92+
if: ${{ !inputs.skip_pypi }}
93+
run: make release-prod
94+
env:
95+
PYPI_USERNAME: __token__
96+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
97+
- name: aws credentials
98+
uses: aws-actions/configure-aws-credentials@v1
99+
with:
100+
aws-region: eu-west-1
101+
role-to-assume: ${{ secrets.AWS_SAR_ROLE_ARN }}
102+
- name: publish lambda layer in SAR by triggering the internal codepipeline
103+
run: |
104+
aws ssm put-parameter --name "powertools-python-release-version" --value "$RELEASE_VERSION" --overwrite
105+
aws codepipeline start-pipeline-execution --name ${{ secrets.AWS_SAR_PIPELINE_NAME }}
106+
107+
changelog:
108+
needs: release
109+
permissions:
110+
contents: write
111+
uses: ./.github/workflows/reusable_publish_changelog.yml
112+
113+
docs:
114+
needs: [release, changelog]
115+
permissions:
116+
contents: write
117+
pages: write
118+
uses: ./.github/workflows/reusable_publish_docs.yml
119+
with:
120+
version: ${{ needs.release.outputs.RELEASE_VERSION }}
121+
alias: latest
122+
detached_mode: true
123+
124+
post_release:
125+
needs: release
126+
permissions:
127+
contents: read
128+
issues: write
129+
discussions: write
130+
pull-requests: write
131+
runs-on: ubuntu-latest
132+
env:
133+
RELEASE_VERSION: ${{ needs.release.outputs.RELEASE_VERSION }}
134+
steps:
135+
- uses: actions/checkout@v3
136+
- name: Close issues related to this release
137+
uses: actions/github-script@v6
138+
with:
139+
github-token: ${{ secrets.GITHUB_TOKEN }}
140+
script: |
141+
const post_release = require('.github/scripts/post_release.js')
142+
await post_release({github, context, core})

.github/workflows/python_build.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- "mypy.ini"
1111
branches:
1212
- develop
13+
- v2
1314
push:
1415
paths:
1516
- "aws_lambda_powertools/**"
@@ -19,6 +20,7 @@ on:
1920
- "mypy.ini"
2021
branches:
2122
- develop
23+
- v2
2224

2325
jobs:
2426
build:
@@ -28,7 +30,6 @@ jobs:
2830
matrix:
2931
python-version: [3.7, 3.8, 3.9]
3032
env:
31-
OS: ${{ matrix.os }}
3233
PYTHON: ${{ matrix.python-version }}
3334
steps:
3435
- uses: actions/checkout@v3
@@ -55,7 +56,5 @@ jobs:
5556
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # 3.1.0
5657
with:
5758
file: ./coverage.xml
58-
# flags: unittests
59-
env_vars: OS,PYTHON
59+
env_vars: PYTHON
6060
name: aws-lambda-powertools-python-codecov
61-
# fail_ci_if_error: true # failing more consistently making CI unreliable despite all tests above passing

0 commit comments

Comments
 (0)