Skip to content

Commit 886ee6b

Browse files
committed
chore: remove duplicate code
1 parent 23f1d20 commit 886ee6b

6 files changed

+250
-415
lines changed

Diff for: .github/workflows/auto-merge.yml

-68
This file was deleted.

Diff for: .github/workflows/make-release.yml

+10-150
Original file line numberDiff line numberDiff line change
@@ -4,108 +4,10 @@ on:
44
concurrency:
55
group: on-release-publish
66
jobs:
7-
check-examples:
8-
runs-on: ubuntu-latest
9-
env:
10-
NODE_ENV: dev
11-
strategy:
12-
matrix:
13-
example: ["sam", "cdk"]
14-
fail-fast: false
15-
defaults:
16-
run:
17-
working-directory: examples/${{ matrix.example }}
18-
steps:
19-
- name: Checkout code
20-
uses: actions/checkout@v3
21-
- name: Setup NodeJS
22-
uses: actions/setup-node@v3
23-
with:
24-
node-version: 16
25-
cache: "npm"
26-
- name: Cache node modules
27-
id: cache-node-modules
28-
uses: actions/cache@v3
29-
with:
30-
path: "./examples/${{ matrix.example }}/node_modules"
31-
# Use the combo between example, name, and SHA-256 hash of all example lock files as cache key.
32-
# It's not possible to use the ${{ matrix.example }} key in the hashFiles fn so
33-
# if any of the lock files (wich should be fairly similar anyway) changes the cache is
34-
# invalidated/discarded for all.
35-
key: ${{ matrix.example }}-cache-examples-node-modules-${{ hashFiles('./examples/*/package-lock.json') }}
36-
- name: Install dependencies
37-
run: npm ci
38-
- name: Run tests
39-
run: npm t
40-
check-layer-publisher:
41-
runs-on: ubuntu-latest
42-
env:
43-
NODE_ENV: dev
44-
defaults:
45-
run:
46-
working-directory: layer-publisher
47-
steps:
48-
- name: Checkout code
49-
uses: actions/checkout@v3
50-
- name: Setup NodeJS
51-
uses: actions/setup-node@v3
52-
with:
53-
node-version: 16
54-
cache: "npm"
55-
- name: Cache node modules
56-
id: cache-node-modules
57-
uses: actions/cache@v3
58-
with:
59-
path: "./layer-publisher/node_modules"
60-
# Use the combo between example, name, and SHA-256 hash of the layer-publisher lock files as cache key.
61-
key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/*/package-lock.json') }}
62-
- name: Install Layer publisher app
63-
run: npm ci
64-
run-unit-tests-on-utils:
65-
runs-on: ubuntu-latest
66-
env:
67-
NODE_ENV: dev
68-
strategy:
69-
matrix:
70-
version: [12, 14, 16]
71-
fail-fast: false
72-
steps:
73-
- name: Checkout code
74-
uses: actions/checkout@v3
75-
- name: Setup NodeJS
76-
uses: actions/setup-node@v3
77-
with:
78-
node-version: ${{ matrix.version }}
79-
cache: "npm"
80-
- name: Setup npm
81-
run: npm i -g npm@next-8
82-
- name: Cache node modules
83-
id: cache-node-modules
84-
uses: actions/cache@v3
85-
with:
86-
path: "./node_modules"
87-
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
88-
# if one of them changes the cache is invalidated/discarded
89-
key: ${{ matrix.version }}-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
90-
- name: Install dependencies
91-
# We can skip the install if there was a cache hit
92-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
93-
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
94-
run: npm ci --foreground-scripts
95-
- name: Build packages
96-
# If there's a cache hit we still need to manually build the packages
97-
# this would otherwise have been done automatically as a part of the
98-
# postinstall npm hook
99-
if: steps.cache-node-modules.outputs.cache-hit == 'true'
100-
run: |
101-
npm run build -w packages/commons
102-
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics
103-
- name: Lint
104-
run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics
105-
- name: Run unit tests
106-
run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics
7+
run-unit-tests:
8+
uses: ./.github/workflows/reusable-run-unit-tests.yml
1079
publish-npm:
108-
needs: [check-examples, check-layer-publisher, run-unit-tests-on-utils]
10+
needs: run-unit-tests
10911
runs-on: ubuntu-latest
11012
steps:
11113
- name: Checkout code
@@ -145,53 +47,11 @@ jobs:
14547
git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/$GITHUB_REPOSITORY
14648
npx lerna version --conventional-commits --force-publish --yes
14749
npx lerna publish from-git --no-verify-access --yes
148-
publish-docs:
50+
publish:
14951
needs: publish-npm
150-
runs-on: ubuntu-latest
151-
steps:
152-
- name: Checkout code
153-
uses: actions/checkout@v3
154-
- name: Set up Python
155-
uses: actions/setup-python@v4
156-
with:
157-
python-version: "3.8"
158-
- name: Set RELEASE_VERSION env var
159-
run: |
160-
RELEASE_VERSION=$(cat packages/commons/package.json | jq '.version' -r)
161-
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
162-
- name: Install doc generation dependencies
163-
run: |
164-
pip install --upgrade pip
165-
pip install -r docs/requirements.txt
166-
- name: Setup doc deploy
167-
run: |
168-
git config --global user.name Docs deploy
169-
git config --global user.email [email protected]
170-
- name: Build mkdocs site in "gh-pages" branch and push
171-
run: |
172-
rm -rf site
173-
VERSION="${{ env.RELEASE_VERSION }}"
174-
ALIAS="latest"
175-
echo "Publishing doc for version: $VERSION"
176-
mkdocs build
177-
mike deploy --push --update-aliases --no-redirect "$VERSION" "$ALIAS"
178-
# Set latest version as a default
179-
mike set-default --push latest
180-
- name: Build API docs
181-
run: |
182-
rm -rf api
183-
npm run docs-generateApiDoc
184-
- name: Release API docs to the released version
185-
uses: peaceiris/actions-gh-pages@v3
186-
with:
187-
github_token: ${{ secrets.GITHUB_TOKEN }}
188-
publish_dir: ./api
189-
keep_files: true
190-
destination_dir: ${{ env.RELEASE_VERSION }}/api
191-
- name: Release API docs to the "latest" version
192-
uses: peaceiris/actions-gh-pages@v3
193-
with:
194-
github_token: ${{ secrets.GITHUB_TOKEN }}
195-
publish_dir: ./api
196-
keep_files: true
197-
destination_dir: latest/api
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 }}

Diff for: .github/workflows/on-merge-to-main.yml

+24-97
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/[email protected]
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 [email protected]
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/[email protected]
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 [email protected]
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

0 commit comments

Comments
 (0)