Skip to content

Commit f653c06

Browse files
authoredAug 12, 2022
fix(layers): release process + remove duplicate code (#1052)
* fix: release process * chore: remove duplicate code * Update .github/workflows/reusable-publish-docs.yml
·
v2.26.1v1.1.0
1 parent d48c1f8 commit f653c06

File tree

8 files changed

+299
-378
lines changed

8 files changed

+299
-378
lines changed
 

‎.github/PULL_REQUEST_TEMPLATE.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
### Related issues, RFCs
2323

24-
<!--- Add here the number to the Github Issue or RFC that is related to this PR. -->
25-
<!-- **Issue number:** #123 -->
24+
<!--- Add here the number (i.e. #42) to the Github Issue or RFC that is related to this PR. -->
25+
<!--- If no issue is present the PR might get blocked and not be reviewed. -->
2626
**Issue number:**
2727

2828
### PR status

‎.github/workflows/auto-merge.yml‎

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

‎.github/workflows/make-release.yml‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Make Release
2+
on:
3+
workflow_dispatch: {}
4+
concurrency:
5+
group: on-release-publish
6+
jobs:
7+
run-unit-tests:
8+
uses: ./.github/workflows/reusable-run-unit-tests.yml
9+
publish-npm:
10+
needs: run-unit-tests
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
with:
16+
# Here `token` is needed to avoid incurring in error GH006 Protected Branch Update Failed,
17+
token: ${{ secrets.GH_PUBLISH_TOKEN }}
18+
# While `fetch-depth` is used to allow the workflow to later commit & push the changes.
19+
fetch-depth: 0
20+
- name: Setup NodeJS
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: "16"
24+
cache: "npm"
25+
- name: Setup npm
26+
run: |
27+
npm i -g npm@next-8
28+
npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
29+
- name: Cache node modules
30+
id: cache-node-modules
31+
uses: actions/cache@v3
32+
with:
33+
path: "./node_modules"
34+
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
35+
# if one of them changes the cache is invalidated/discarded
36+
key: 16-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
37+
- name: Build packages
38+
run: |
39+
npm run build -w packages/commons
40+
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics
41+
- name: "Version and publish"
42+
env:
43+
GH_TOKEN: ${{ secrets.GH_PUBLISH_TOKEN }}
44+
run: |
45+
git config --global user.name 'github-actions[bot]'
46+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
47+
git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/$GITHUB_REPOSITORY
48+
npx lerna version --conventional-commits --force-publish --yes
49+
npx lerna publish from-git --no-verify-access --yes
50+
publish:
51+
needs: publish-npm
52+
uses: ./.github/workflows/reusable-publish-docs.yml
53+
with:
54+
workflow_origin: ${{ github.event.repository.full_name }}
55+
isRelease: "true"
56+
secrets:
57+
token: ${{ secrets.GITHUB_TOKEN }}

‎.github/workflows/on-merge-to-main.yml‎

Lines changed: 24 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
workflows: ["Record PR details"]
66
types:
77
- completed
8+
concurrency:
9+
group: on-merge-to-main
810

911
jobs:
1012
get_pr_details:
@@ -15,10 +17,30 @@ jobs:
1517
workflow_origin: ${{ github.event.repository.full_name }}
1618
secrets:
1719
token: ${{ secrets.GITHUB_TOKEN }}
20+
run-unit-tests:
21+
uses: ./.github/workflows/reusable-run-unit-tests.yml
22+
publish:
23+
needs:
24+
[get_pr_details, run-unit-tests, check-examples, check-layer-publisher]
25+
uses: ./.github/workflows/reusable-publish-docs.yml
26+
with:
27+
workflow_origin: ${{ github.event.repository.full_name }}
28+
prIsMerged: ${{ needs.get_pr_details.outputs.prIsMerged }}
29+
secrets:
30+
token: ${{ secrets.GITHUB_TOKEN }}
31+
update-release-draft:
32+
needs: publish
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v3
37+
- name: Update release draft
38+
uses: release-drafter/release-drafter@v5.20.0
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1841
release_label_on_merge:
19-
needs: get_pr_details
42+
needs: [get_pr_details, update-release-draft]
2043
runs-on: ubuntu-latest
21-
if: needs.get_pr_details.outputs.prIsMerged == 'true'
2244
steps:
2345
- uses: actions/checkout@v3
2446
- name: "Label PR related issue for release"
@@ -33,98 +55,3 @@ jobs:
3355
script: |
3456
const script = require('.github/scripts/label_related_issue.js')
3557
await script({github, context, core})
36-
publish:
37-
#########################
38-
# Force Github action to run only a single job at a time (based on the group name)
39-
# This is to prevent "race-condition" in publishing a new version of doc to `gh-pages` (#365)
40-
#########################
41-
concurrency:
42-
group: on-merge-to-main
43-
runs-on: ubuntu-latest
44-
steps:
45-
- name: "Checkout"
46-
uses: actions/checkout@v3
47-
with:
48-
fetch-depth: 0
49-
#########################
50-
# Release new version
51-
#########################
52-
- name: "Use NodeJS 16"
53-
uses: actions/setup-node@v3
54-
with:
55-
node-version: '16'
56-
- name: Install npm@8.x
57-
run: npm i -g npm@next-8
58-
- name: "Setup npm"
59-
run: |
60-
npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
61-
- name: Install monorepo packages
62-
# This installs all the dependencies of ./packages/*
63-
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
64-
run: npm ci --foreground-scripts
65-
- name: Install CDK example packages
66-
# Since we are not managing the CDK examples with npm workspaces we install
67-
# the dependencies in a separate step
68-
working-directory: ./examples/cdk
69-
run: npm ci
70-
- name: Install Layer publisher app
71-
working-directory: ./layer-publisher
72-
run: npm ci
73-
- name: "Setup SAM"
74-
# We use an ad-hoc action so we can specify the SAM CLI version
75-
uses: aws-actions/setup-sam@v2
76-
with:
77-
version: 1.49.0
78-
- name: Install SAM example packages
79-
# Since we are not managing the SAM examples with npm workspaces we install
80-
# the dependencies in a separate step
81-
working-directory: ./examples/sam
82-
run: npm ci
83-
- name: Run lint
84-
run: npm run lerna-lint
85-
- name: Run tests
86-
run: npm run lerna-test
87-
- name: Update release draft
88-
uses: release-drafter/release-drafter@v5.20.0
89-
env:
90-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91-
#########################
92-
# Generate documentation
93-
#########################
94-
- name: Set up Python
95-
uses: actions/setup-python@v4
96-
with:
97-
python-version: '3.8'
98-
- name: Install doc generation dependencies
99-
run: |
100-
pip install --upgrade pip
101-
pip install -r docs/requirements.txt
102-
- name: Setup doc deploy
103-
run: |
104-
git config --global user.name Docs deploy
105-
git config --global user.email docs@dummy.bot.com
106-
- name: Build mkdocs site in "gh-pages" branch and push
107-
run: |
108-
rm -rf site
109-
VERSION="dev"
110-
echo "Publishing doc for version: $VERSION"
111-
mkdocs build
112-
mike deploy --push "$VERSION"
113-
- name: Build API docs
114-
run: |
115-
rm -rf api
116-
npm run docs-generateApiDoc
117-
- name: Release API docs to the released version
118-
uses: peaceiris/actions-gh-pages@v3
119-
with:
120-
github_token: ${{ secrets.GITHUB_TOKEN }}
121-
publish_dir: ./api
122-
keep_files: true
123-
destination_dir: dev/api
124-
- name: Release API docs to the "latest" version
125-
uses: peaceiris/actions-gh-pages@v3
126-
with:
127-
github_token: ${{ secrets.GITHUB_TOKEN }}
128-
publish_dir: ./api
129-
keep_files: true
130-
destination_dir: latest/api

‎.github/workflows/on-release-prod.yml‎

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

‎.github/workflows/pr_lint_and_test.yml‎

Lines changed: 2 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4,103 +4,5 @@ on:
44
pull_request:
55
types: [opened, synchronize]
66
jobs:
7-
run-unit-tests-on-utils:
8-
runs-on: ubuntu-latest
9-
env:
10-
NODE_ENV: dev
11-
strategy:
12-
matrix:
13-
version: [12, 14, 16]
14-
fail-fast: false
15-
steps:
16-
- name: Checkout code
17-
uses: actions/checkout@v3
18-
- name: Setup NodeJS
19-
uses: actions/setup-node@v3
20-
with:
21-
node-version: ${{ matrix.version }}
22-
cache: "npm"
23-
- name: Setup npm
24-
run: npm i -g npm@next-8
25-
- name: Cache node modules
26-
id: cache-node-modules
27-
uses: actions/cache@v3
28-
with:
29-
path: "./node_modules"
30-
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
31-
# if one of them changes the cache is invalidated/discarded
32-
key: ${{ matrix.version }}-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
33-
- name: Install dependencies
34-
# We can skip the install if there was a cache hit
35-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
36-
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
37-
run: npm ci --foreground-scripts
38-
- name: Build packages
39-
# If there's a cache hit we still need to manually build the packages
40-
# this would otherwise have been done automatically as a part of the
41-
# postinstall npm hook
42-
if: steps.cache-node-modules.outputs.cache-hit == 'true'
43-
run: |
44-
npm run build -w packages/commons
45-
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics
46-
- name: Lint
47-
run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics
48-
- name: Run unit tests
49-
run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics
50-
check-examples:
51-
runs-on: ubuntu-latest
52-
env:
53-
NODE_ENV: dev
54-
strategy:
55-
matrix:
56-
example: ["sam", "cdk"]
57-
fail-fast: false
58-
defaults:
59-
run:
60-
working-directory: examples/${{ matrix.example }}
61-
steps:
62-
- name: Checkout code
63-
uses: actions/checkout@v3
64-
- name: Setup NodeJS
65-
uses: actions/setup-node@v3
66-
with:
67-
node-version: 16
68-
cache: "npm"
69-
- name: Cache node modules
70-
id: cache-node-modules
71-
uses: actions/cache@v3
72-
with:
73-
path: "./examples/${{ matrix.example }}/node_modules"
74-
# Use the combo between example, name, and SHA-256 hash of all example lock files as cache key.
75-
# It's not possible to use the ${{ matrix.example }} key in the hashFiles fn so
76-
# if any of the lock files (wich should be fairly similar anyway) changes the cache is
77-
# invalidated/discarded for all.
78-
key: ${{ matrix.example }}-cache-examples-node-modules-${{ hashFiles('./examples/*/package-lock.json') }}
79-
- name: Install dependencies
80-
run: npm ci
81-
- name: Run tests
82-
run: npm t
83-
check-layer-publisher:
84-
runs-on: ubuntu-latest
85-
env:
86-
NODE_ENV: dev
87-
defaults:
88-
run:
89-
working-directory: layer-publisher
90-
steps:
91-
- name: Checkout code
92-
uses: actions/checkout@v3
93-
- name: Setup NodeJS
94-
uses: actions/setup-node@v3
95-
with:
96-
node-version: 16
97-
cache: "npm"
98-
- name: Cache node modules
99-
id: cache-node-modules
100-
uses: actions/cache@v3
101-
with:
102-
path: "./layer-publisher/node_modules"
103-
# Use the combo between example, name, and SHA-256 hash of the layer-publisher lock files as cache key.
104-
key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/*/package-lock.json') }}
105-
- name: Install Layer publisher app
106-
run: npm ci
7+
run-unit-tests:
8+
uses: ./.github/workflows/reusable-run-unit-tests.yml
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Publish docs
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
workflow_origin: # see https://github.com/awslabs/aws-lambda-powertools-python/issues/1349
7+
required: true
8+
type: string
9+
prIsMerged:
10+
required: false
11+
default: "false"
12+
type: string
13+
isRelease:
14+
required: false
15+
default: "false"
16+
type: string
17+
secrets:
18+
token:
19+
required: true
20+
concurrency:
21+
group: on-release-publish
22+
23+
jobs:
24+
publish-docs:
25+
# see https://github.com/awslabs/aws-lambda-powertools-python/issues/1349
26+
if: inputs.workflow_origin == 'awslabs/aws-lambda-powertools-typescript'
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v3
31+
with:
32+
# Here `token` is needed to avoid incurring in error GH006 Protected Branch Update Failed,
33+
token: ${{ secrets.token }}
34+
# While `fetch-depth` is used to allow the workflow to later commit & push the changes.
35+
fetch-depth: 0
36+
- name: Setup NodeJS
37+
uses: actions/setup-node@v3
38+
with:
39+
node-version: "16"
40+
cache: "npm"
41+
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
42+
# if one of them changes the cache is invalidated/discarded
43+
- name: Cache node modules
44+
id: cache-node-modules
45+
uses: actions/cache@v3
46+
with:
47+
path: "./node_modules"
48+
key: 16-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
49+
# Here we assume that there will always be a cache hit because this workflow can be triggered
50+
# only after tests have already happened on this same code
51+
- name: Build packages
52+
run: |
53+
npm run build -w packages/commons
54+
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics
55+
- name: Set up Python
56+
uses: actions/setup-python@v4
57+
with:
58+
python-version: "3.8"
59+
# We run this step only when the workflow has been triggered by a release
60+
# in this case we publish the docs to `/latest`
61+
- name: Set RELEASE_VERSION env var to `latest`
62+
if: ${{ inputs.isRelease == 'true' }}
63+
run: |
64+
RELEASE_VERSION=$(cat packages/commons/package.json | jq '.version' -r)
65+
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
66+
# We run this step only when the workflow has been triggered by a PR merge
67+
# in this case we publish the docs to `/dev`
68+
- name: Set RELEASE_VERSION env var to `dev`
69+
if: ${{ inputs.prIsMerged == 'true' }}
70+
run: |
71+
echo "RELEASE_VERSION=dev" >> $GITHUB_ENV
72+
- name: Install doc generation dependencies
73+
run: |
74+
pip install --upgrade pip
75+
pip install -r docs/requirements.txt
76+
- name: Setup doc deploy
77+
run: |
78+
git config --global user.name Docs deploy
79+
git config --global user.email docs@dummy.bot.com
80+
- name: Publish docs to latest
81+
if: ${{ env.RELEASE_VERSION != 'dev' }}
82+
run: |
83+
rm -rf site
84+
mkdocs build
85+
mike deploy --push --update-aliases --no-redirect "${{ env.RELEASE_VERSION }}" "latest"
86+
# Set latest version as a default
87+
mike set-default --push latest
88+
- name: Publish docs to dev
89+
if: ${{ env.RELEASE_VERSION == 'dev' }}
90+
run: |
91+
rm -rf site
92+
mkdocs build
93+
mike deploy --push dev
94+
- name: Build API docs
95+
run: |
96+
rm -rf api
97+
npm run docs-generateApiDoc
98+
- name: Release API docs
99+
uses: peaceiris/actions-gh-pages@v3
100+
with:
101+
github_token: ${{ secrets.GITHUB_TOKEN }}
102+
publish_dir: ./api
103+
keep_files: true
104+
destination_dir: ${{ env.RELEASE_VERSION }}/api
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Run unit tests
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
run-unit-tests-on-utils:
8+
runs-on: ubuntu-latest
9+
env:
10+
NODE_ENV: dev
11+
strategy:
12+
matrix:
13+
version: [12, 14, 16]
14+
fail-fast: false
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
- name: Setup NodeJS
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: ${{ matrix.version }}
22+
cache: "npm"
23+
- name: Setup npm
24+
run: npm i -g npm@next-8
25+
- name: Cache node modules
26+
id: cache-node-modules
27+
uses: actions/cache@v3
28+
with:
29+
path: "./node_modules"
30+
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
31+
# if one of them changes the cache is invalidated/discarded
32+
key: ${{ matrix.version }}-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
33+
- name: Install dependencies
34+
# We can skip the install if there was a cache hit
35+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
36+
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
37+
run: npm ci --foreground-scripts
38+
- name: Build packages
39+
# If there's a cache hit we still need to manually build the packages
40+
# this would otherwise have been done automatically as a part of the
41+
# postinstall npm hook
42+
if: steps.cache-node-modules.outputs.cache-hit == 'true'
43+
run: |
44+
npm run build -w packages/commons
45+
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics
46+
- name: Lint
47+
run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics
48+
- name: Run unit tests
49+
run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics
50+
check-examples:
51+
runs-on: ubuntu-latest
52+
env:
53+
NODE_ENV: dev
54+
strategy:
55+
matrix:
56+
example: ["sam", "cdk"]
57+
fail-fast: false
58+
defaults:
59+
run:
60+
working-directory: examples/${{ matrix.example }}
61+
steps:
62+
- name: Checkout code
63+
uses: actions/checkout@v3
64+
- name: Setup NodeJS
65+
uses: actions/setup-node@v3
66+
with:
67+
node-version: 16
68+
cache: "npm"
69+
- name: Cache node modules
70+
id: cache-node-modules
71+
uses: actions/cache@v3
72+
with:
73+
path: "./examples/${{ matrix.example }}/node_modules"
74+
# Use the combo between example, name, and SHA-256 hash of all example lock files as cache key.
75+
# It's not possible to use the ${{ matrix.example }} key in the hashFiles fn so
76+
# if any of the lock files (wich should be fairly similar anyway) changes the cache is
77+
# invalidated/discarded for all.
78+
key: ${{ matrix.example }}-cache-examples-node-modules-${{ hashFiles('./examples/*/package-lock.json') }}
79+
- name: Install dependencies
80+
# We can skip the install if there was a cache hit
81+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
82+
run: npm ci
83+
- name: Run tests
84+
run: npm t
85+
check-layer-publisher:
86+
runs-on: ubuntu-latest
87+
env:
88+
NODE_ENV: dev
89+
defaults:
90+
run:
91+
working-directory: layer-publisher
92+
steps:
93+
- name: Checkout code
94+
uses: actions/checkout@v3
95+
- name: Setup NodeJS
96+
uses: actions/setup-node@v3
97+
with:
98+
node-version: 16
99+
cache: "npm"
100+
- name: Cache node modules
101+
id: cache-node-modules
102+
uses: actions/cache@v3
103+
with:
104+
path: "./layer-publisher/node_modules"
105+
# Use the combo between example, name, and SHA-256 hash of the layer-publisher lock files as cache key.
106+
key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/*/package-lock.json') }}
107+
- name: Install Layer publisher
108+
# We can skip the install if there was a cache hit
109+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
110+
run: npm ci

0 commit comments

Comments
 (0)
Please sign in to comment.