Skip to content

Commit 5a55099

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

File tree

23 files changed

+714
-201
lines changed

23 files changed

+714
-201
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: ⚙️ Build
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
NX_CLOUD_ACCESS_TOKEN:
7+
required: true
8+
env:
9+
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
- name: Derive appropriate SHAs for base and head for `nx affected` commands
20+
uses: nrwl/nx-set-shas@v4
21+
with:
22+
main-branch-name: "master"
23+
24+
- name: Setup Node.js
25+
uses: ./.github/actions
26+
27+
- name: Build Libraries
28+
run: npx nx affected --target=build --parallel=3 --exclude='*,!tag:type:publish'

.github/workflows/ci.yml

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

.github/workflows/e2e-test.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: ⚙️ E2E Test
2+
on:
3+
workflow_call:
4+
secrets:
5+
NX_CLOUD_ACCESS_TOKEN:
6+
required: true
7+
env:
8+
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
9+
10+
11+
jobs:
12+
e2e-test:
13+
runs-on: ubuntu-latest
14+
services:
15+
postgres:
16+
image: postgres
17+
env:
18+
POSTGRES_PASSWORD: postgres
19+
POSTGRES_DB: json-api-db
20+
options: >-
21+
--health-cmd pg_isready
22+
--health-interval 10s
23+
--health-timeout 5s
24+
--health-retries 5
25+
ports:
26+
- 5432:5432
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
- name: Setup Node.js
31+
uses: ./.github/actions
32+
- run: npm run typeorm migration:run
33+
- run: npm run seed:run
34+
- run: npx nx run json-api-server-e2e:e2e --parallel=1
35+
- run: npx nx run json-api-server-e2e:e2e-micro --parallel=1

.github/workflows/pr.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 📝 PR Checks
2+
3+
on:
4+
[pull_request]
5+
6+
jobs:
7+
test:
8+
uses: ./.github/workflows/test.yml
9+
secrets:
10+
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
11+
12+
e2e-test:
13+
needs: [test]
14+
uses: ./.github/workflows/e2e-test.yaml
15+
secrets:
16+
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
17+
18+
build:
19+
needs: [test, e2e-test]
20+
uses: ./.github/workflows/build.yml
21+
secrets:
22+
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

.github/workflows/test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: ⚙️ Test
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
NX_CLOUD_ACCESS_TOKEN:
7+
required: true
8+
env:
9+
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setup Node.js
21+
uses: ./.github/actions
22+
23+
- name: Derive appropriate SHAs for base and head for `nx affected` commands
24+
uses: nrwl/nx-set-shas@v4
25+
with:
26+
main-branch-name: "master"
27+
28+
- name: Test
29+
run: npx nx affected --target=test --parallel=3 --passWithNoTests --exclude='*,!tag:type:publish'
30+
31+
- name: TS Test
32+
run: npx nx affected --target=ts-test --parallel=3 --passWithNoTests --exclude='*,!tag:type:publish'

libs/json-api/json-api-nestjs-microorm/project.json

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,51 @@
1212
}
1313
}
1414
},
15-
"tags": ["type:lib", "lib:json-api-nestjs", "lib:json-api-nestjs-microorm", "type:publish"],
15+
"tags": [
16+
"type:lib",
17+
"lib:json-api-nestjs",
18+
"lib:json-api-nestjs-microorm",
19+
"type:publish"
20+
],
1621
"targets": {
1722
"build": {
1823
"dependsOn": [
1924
{
20-
"projects": ["json-api-nestjs"],
25+
"projects": [
26+
"json-api-nestjs"
27+
],
2128
"target": "build",
2229
"params": "ignore"
2330
}
2431
],
2532
"executor": "@nx/js:tsc",
26-
"outputs": ["{options.outputPath}"],
33+
"outputs": [
34+
"{options.outputPath}"
35+
],
36+
"options": {
37+
"outputPath": "dist/{projectRoot}",
38+
"tsConfig": "{projectRoot}/tsconfig.lib.json",
39+
"packageJson": "{projectRoot}/package.json",
40+
"main": "{projectRoot}/src/index.ts",
41+
"assets": [
42+
"{projectRoot}/*.md"
43+
]
44+
}
45+
},
46+
"upload-badge": {
47+
"executor": "nx:run-commands",
48+
"dependsOn": [
49+
{
50+
"target": "test"
51+
}
52+
],
2753
"options": {
28-
"outputPath": "dist/libs/json-api/json-api-nestjs-microorm",
29-
"tsConfig": "libs/json-api/json-api-nestjs-microorm/tsconfig.lib.json",
30-
"packageJson": "libs/json-api/json-api-nestjs-microorm/package.json",
31-
"main": "libs/json-api/json-api-nestjs-microorm/src/index.ts",
32-
"assets": ["libs/json-api/json-api-nestjs-microorm/*.md"]
54+
"commands": [
55+
"node tools/scripts/upload-badge.mjs json-api-nestjs-microorm"
56+
],
57+
"cwd": "./",
58+
"parallel": false,
59+
"outputPath": "{workspaceRoot}/{projectRoot}"
3360
}
3461
},
3562
"nx-release-publish": {
@@ -38,5 +65,7 @@
3865
}
3966
}
4067
},
41-
"implicitDependencies": ["json-api-nestjs"]
68+
"implicitDependencies": [
69+
"json-api-nestjs"
70+
]
4271
}

libs/json-api/json-api-nestjs-microorm/src/lib/orm-methods/get-all/get-all.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ describe('get-all', () => {
860860
},
861861
})
862862
.getResult();
863-
const count = await quweryBuilder.clone().count();
863+
const count = await quweryBuilder.clone().count('id', true);
864864
const query = getDefaultQuery<Users>();
865865
query.page = {
866866
size: 5,

libs/json-api/json-api-nestjs-microorm/src/lib/orm-methods/post-relationship/post-relationship.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,11 @@ describe('post-relationshipa', () => {
8181
jest.restoreAllMocks();
8282
});
8383

84-
afterAll(() => {
85-
mikroORMUsers.close(true);
86-
});
84+
afterAll(() => mikroORMUsers.close(true));
8785

8886
it('should be ok', async () => {
89-
const roles1 = faker.helpers.arrayElement(roles);
90-
const roles2 = faker.helpers.arrayElement(roles);
91-
const roles3 = faker.helpers.arrayElement(roles);
87+
const [roles1, roles2, roles3] = faker.helpers.arrayElements(roles, 3);
88+
9289
const userGroup1 = faker.helpers.arrayElement(userGroup);
9390
const saveIdUserGroup = userGroup1.id;
9491

@@ -139,12 +136,15 @@ describe('post-relationshipa', () => {
139136
})
140137
.getSingleResult();
141138

139+
const newRolesId = [roles1.id, roles2.id, roles3.id].filter(
140+
(i) => !saveRolesIds.includes(i)
141+
);
142142
expect(checkData?.roles.map((i) => i.id)).toEqual(
143143
expect.arrayContaining([roles1.id, roles2.id, roles3.id])
144144
);
145145

146146
expect(checkData?.roles.map((i) => i.id)).toHaveLength(
147-
[roles1.id, roles2.id, roles3.id].length + saveRolesIds.length
147+
newRolesId.length + saveRolesIds.length
148148
);
149149
expect(checkData?.userGroup?.id).toBe(saveIdUserGroup);
150150
});

0 commit comments

Comments
 (0)