Skip to content

Commit 5f6bc01

Browse files
committed
ci: New CI/CD process
1 parent e9f11d3 commit 5f6bc01

File tree

27 files changed

+1125
-229
lines changed

27 files changed

+1125
-229
lines changed

.github/actions/action.yml

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
name: 'My composite action'
2-
description: 'Checks out the repository and install'
1+
name: Main action for Node.js
2+
description: Setup Node.js
3+
4+
inputs:
5+
node-version:
6+
description: Node.js version
7+
required: false
8+
default: 20.x
9+
310
runs:
4-
using: 'composite'
11+
using: composite
512
steps:
6-
- name: Setup Node.js
7-
uses: actions/setup-node@v4
13+
- name: Use Node.js ${{ inputs.node-version }}
14+
uses: actions/setup-node@v3
815
with:
9-
node-version: 20
16+
node-version: ${{ inputs.node-version }}
1017
registry-url: 'https://registry.npmjs.org'
11-
- name: Restore cached npm dependencies
12-
id: cache-dependencies-restore
13-
uses: actions/cache/restore@v4
18+
cache: npm
19+
20+
- name: Get npm cache directory
21+
id: npm-cache-dir
22+
shell: pwsh
23+
run: echo "dir=$(npm config get cache)" >> ${env:GITHUB_OUTPUT}
24+
25+
- name: Cache NPM dependencies
26+
uses: actions/cache@v4
27+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
1428
with:
15-
path: |
16-
node_modules
17-
~/.cache/Cypress # needed for the Cypress binary
18-
key: ${{ runner.os }}-npm-dependencies-${{ hashFiles('package-lock.json') }}
19-
- name: Npm install
20-
if: steps.cache-dependencies-restore.outputs.cache-hit != 'true'
21-
run: npm ci
29+
path: ${{ steps.npm-cache-dir.outputs.dir }}
30+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
31+
restore-keys: |
32+
${{ runner.os }}-node-
33+
34+
- name: Install Dependencies
2235
shell: bash
23-
- name: Cache npm dependencies
24-
id: cache-dependencies-save
25-
uses: actions/cache/save@v4
26-
with:
27-
path: |
28-
node_modules
29-
~/.cache/Cypress # needed for the Cypress binary
30-
key: ${{ steps.cache-dependencies-restore.outputs.cache-primary-key }}
31-
- name: Derive appropriate SHAs for base and head for `nx affected` commands
32-
uses: nrwl/nx-set-shas@v4
33-
with:
34-
main-branch-name: "master"
36+
run: npm ci

.github/workflows/build.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: ⚙️ Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
mainBranch:
7+
description: Type for main nx affect
8+
required: false
9+
default: "master"
10+
secrets:
11+
NX_CLOUD_ACCESS_TOKEN:
12+
required: true
13+
env:
14+
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
- name: Derive appropriate SHAs for base and head for `nx affected` commands
25+
uses: nrwl/nx-set-shas@v4
26+
with:
27+
main-branch-name: "master"
28+
29+
- name: Setup Node.js
30+
uses: ./.github/actions
31+
32+
- name: Determine base branch for NX affected
33+
id: set-base
34+
shell: bash
35+
run: |
36+
if [ "${{ github.event.inputs.mainBranch }}" = "master" ]; then
37+
echo "base=master" >> $GITHUB_OUTPUT
38+
echo "Using base branch 'master'"
39+
else
40+
LAST_TAG=$(git describe --tags --abbrev=0)
41+
LAST_TAG_HASH=$(git rev-parse "$LAST_TAG")
42+
echo "base=$LAST_TAG_HASH" >> $GITHUB_OUTPUT
43+
echo "Using last tag hash: $LAST_TAG_HASH"
44+
fi
45+
46+
- name: Derive appropriate SHAs for base and head for `nx affected` commands
47+
uses: nrwl/nx-set-shas@v4
48+
with:
49+
main-branch-name: ${{ steps.set-base.outputs.base }}
50+
51+
- name: Build Libraries
52+
run: npx nx affected --target=build --parallel=3 --exclude='*,!tag:type:publish'

.github/workflows/ci.yml renamed to .github/workflows/bump-version-save.yml

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,49 @@
1-
name: CI
1+
name: Create Releases
22
on:
3-
pull_request:
4-
branches:
5-
- master
6-
types:
7-
- opened
8-
- synchronize
3+
workflow_dispatch:
4+
inputs:
5+
projects:
6+
description: 'Package Bump'
7+
required: true
8+
default: 'json-api-nestjs,json-api-nestjs-sdk,nestjs-json-rpc,nestjs-json-rpc-sdk'
9+
first-release:
10+
description: 'Is first release?'
11+
required: false
12+
type: boolean
13+
default: false
14+
dry-run:
15+
description: 'Is dry run?'
16+
required: false
17+
type: boolean
18+
default: false
919
jobs:
10-
run-test:
11-
name: Try build and run unit test
20+
build-and-test:
21+
name: "Build and test"
1222
runs-on: ubuntu-latest
23+
permissions:
24+
contents: "read"
25+
actions: "read"
1326
steps:
1427
- uses: actions/checkout@v4
1528
with:
1629
fetch-depth: 0
1730
- name: Npm install
1831
uses: ./.github/actions
19-
- name: Get branch names.
20-
id: branch-names
21-
uses: tj-actions/branch-names@v8
32+
- name: Get git hash
33+
run: |
34+
COMMIT=$(git show-ref --tags --hash | tail -n 1)
35+
echo "NX_BASE=$(echo ${COMMIT})" >> $GITHUB_ENV
36+
- name: Set GIST_SECRET to env
37+
run: |
38+
echo "GIST_SECRET=${{ secrets.GIST_SECRET }}" >> $GITHUB_ENV
39+
echo "GIST_ID=${{ secrets.GIST_ID }}" >> $GITHUB_ENV
2240
- name: Restore cached .nx
2341
id: cache-nx-restore
2442
uses: actions/cache/restore@v4
2543
with:
2644
path: |
2745
.nx
28-
key: ${{ runner.os }}-nx-${{ steps.branch-names.outputs.current_branch }}
29-
- run: git branch --track main origin/master
46+
key: ${{ runner.os }}-nx-master
3047
- name: Test
3148
env:
3249
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
@@ -35,6 +52,8 @@ jobs:
3552
env:
3653
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
3754
run: npx nx affected -t build --exclude='json-api-front,json-api-server,json-api-server-e2e,json-shared-type,microorm-database,typeorm-database,@nestjs-json-api/source,type-for-rpc'
55+
- name: Upload test coverage badge
56+
run: npx nx affected -t upload-badge --exclude='json-api-front,json-api-server,shared-utils,json-api-server-e2e,json-shared-type,microorm-database,typeorm-database,@nestjs-json-api/source,type-for-rpc'
3857
- name: Save cached .nx
3958
id: cache-dependencies-save
4059
uses: actions/cache/save@v4
@@ -46,7 +65,7 @@ jobs:
4665
runs-on: ubuntu-latest
4766
name: Try run e2e test
4867
needs:
49-
- run-test
68+
- build-and-test
5069
services:
5170
# Label used to access the service container
5271
postgres:
@@ -71,25 +90,49 @@ jobs:
7190
fetch-depth: 0
7291
- name: Npm install
7392
uses: ./.github/actions
74-
- name: Get branch names.
75-
id: branch-names
76-
uses: tj-actions/branch-names@v8
7793
- name: Restore cached .nx
7894
id: cache-nx-restore
7995
uses: actions/cache/restore@v4
8096
with:
8197
path: |
8298
.nx
83-
key: ${{ runner.os }}-nx-${{ steps.branch-names.outputs.current_branch }}
99+
key: ${{ runner.os }}-nx-master
84100
- run: git branch --track main origin/master
85101
- run: npm run typeorm migration:run
86102
- run: npm run seed:run
87103
- run: npx nx affected -t e2e --parallel=1
88-
- run: npx nx affected -t e2e-micro --parallel=1
89104
- name: Save cached .nx
90105
id: cache-dependencies-save
91106
uses: actions/cache/save@v4
92107
with:
93108
path: |
94109
.nx
95110
key: ${{ steps.cache-nx-restore.outputs.cache-primary-key }}
111+
bump-version:
112+
name: "Bump version"
113+
needs:
114+
- run-e2e-test
115+
runs-on: ubuntu-latest
116+
permissions:
117+
contents: "write"
118+
actions: "read"
119+
id-token: "write"
120+
timeout-minutes: 10
121+
steps:
122+
- name: Checkout repository
123+
uses: actions/checkout@v4
124+
with:
125+
fetch-depth: 0
126+
token: ${{ secrets.PAT }}
127+
- name: Npm install
128+
uses: ./.github/actions
129+
- name: Bump version
130+
run: |
131+
git config --global user.email "[email protected]"
132+
git config --global user.name "GitHub Actions"
133+
npx nx release --skip-publish --first-release=${{ github.event.inputs.first-release }} --projects=${{ github.event.inputs.projects }} --dry-run=${{ github.event.inputs.dry-run }}
134+
shell: bash
135+
env:
136+
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
137+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
138+
NPM_CONFIG_PROVENANCE: true

.github/workflows/bump-version.yml

Lines changed: 10 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,30 @@
1-
name: Create Releases
1+
name: ⚙️ Bump version
2+
23
on:
3-
workflow_dispatch:
4+
workflow_call:
45
inputs:
56
projects:
6-
description: 'Package Bump'
7+
description: "Project list"
78
required: true
8-
default: 'json-api-nestjs,json-api-nestjs-sdk,nestjs-json-rpc,nestjs-json-rpc-sdk'
9+
type: string
910
first-release:
1011
description: 'Is first release?'
1112
required: false
1213
type: boolean
1314
default: false
15+
beta-release:
16+
description: 'Is beta release?'
17+
required: false
18+
type: boolean
19+
default: false
1420
dry-run:
1521
description: 'Is dry run?'
1622
required: false
1723
type: boolean
1824
default: false
1925
jobs:
20-
build-and-test:
21-
name: "Build and test"
22-
runs-on: ubuntu-latest
23-
permissions:
24-
contents: "read"
25-
actions: "read"
26-
steps:
27-
- uses: actions/checkout@v4
28-
with:
29-
fetch-depth: 0
30-
- name: Npm install
31-
uses: ./.github/actions
32-
- name: Get git hash
33-
run: |
34-
COMMIT=$(git show-ref --tags --hash | tail -n 1)
35-
echo "NX_BASE=$(echo ${COMMIT})" >> $GITHUB_ENV
36-
- name: Set GIST_SECRET to env
37-
run: |
38-
echo "GIST_SECRET=${{ secrets.GIST_SECRET }}" >> $GITHUB_ENV
39-
echo "GIST_ID=${{ secrets.GIST_ID }}" >> $GITHUB_ENV
40-
- name: Restore cached .nx
41-
id: cache-nx-restore
42-
uses: actions/cache/restore@v4
43-
with:
44-
path: |
45-
.nx
46-
key: ${{ runner.os }}-nx-master
47-
- name: Test
48-
env:
49-
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
50-
run: npx nx affected -t test --parallel=3 --exclude='json-api-front,json-api-server,json-api-server-e2e,json-shared-type,microorm-database,typeorm-database,@nestjs-json-api/source,type-for-rpc'
51-
- name: Build
52-
env:
53-
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
54-
run: npx nx affected -t build --exclude='json-api-front,json-api-server,json-api-server-e2e,json-shared-type,microorm-database,typeorm-database,@nestjs-json-api/source,type-for-rpc'
55-
- name: Upload test coverage badge
56-
run: npx nx affected -t upload-badge --exclude='json-api-front,json-api-server,shared-utils,json-api-server-e2e,json-shared-type,microorm-database,typeorm-database,@nestjs-json-api/source,type-for-rpc'
57-
- name: Save cached .nx
58-
id: cache-dependencies-save
59-
uses: actions/cache/save@v4
60-
with:
61-
path: |
62-
.nx
63-
key: ${{ steps.cache-nx-restore.outputs.cache-primary-key }}
64-
run-e2e-test:
65-
runs-on: ubuntu-latest
66-
name: Try run e2e test
67-
needs:
68-
- build-and-test
69-
services:
70-
# Label used to access the service container
71-
postgres:
72-
# Docker Hub image
73-
image: postgres
74-
# Provide the password for postgres
75-
env:
76-
POSTGRES_PASSWORD: postgres
77-
POSTGRES_DB: json-api-db
78-
# Set health checks to wait until postgres has started
79-
options: >-
80-
--health-cmd pg_isready
81-
--health-interval 10s
82-
--health-timeout 5s
83-
--health-retries 5
84-
ports:
85-
# Maps tcp port 5432 on service container to the host
86-
- 5432:5432
87-
steps:
88-
- uses: actions/checkout@v4
89-
with:
90-
fetch-depth: 0
91-
- name: Npm install
92-
uses: ./.github/actions
93-
- name: Restore cached .nx
94-
id: cache-nx-restore
95-
uses: actions/cache/restore@v4
96-
with:
97-
path: |
98-
.nx
99-
key: ${{ runner.os }}-nx-master
100-
- run: git branch --track main origin/master
101-
- run: npm run typeorm migration:run
102-
- run: npm run seed:run
103-
- run: npx nx affected -t e2e --parallel=1
104-
- name: Save cached .nx
105-
id: cache-dependencies-save
106-
uses: actions/cache/save@v4
107-
with:
108-
path: |
109-
.nx
110-
key: ${{ steps.cache-nx-restore.outputs.cache-primary-key }}
11126
bump-version:
112-
name: "Bump version"
113-
needs:
114-
- run-e2e-test
11527
runs-on: ubuntu-latest
116-
permissions:
117-
contents: "write"
118-
actions: "read"
119-
id-token: "write"
120-
timeout-minutes: 10
12128
steps:
12229
- name: Checkout repository
12330
uses: actions/checkout@v4

0 commit comments

Comments
 (0)