Skip to content

Commit ac5efbe

Browse files
authored
test: refactor backwards compatibility test (#600)
1 parent b8b14c3 commit ac5efbe

File tree

8 files changed

+105
-51
lines changed

8 files changed

+105
-51
lines changed
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
name: Backwards Compatibility Test
2-
on:
3-
workflow_dispatch:
4-
schedule:
5-
- cron: '0 0 * * *' # daily at 00:00
2+
3+
on: workflow_call
64

75
jobs:
86
backwards-compatibility-test:
97
strategy:
108
matrix:
11-
nx-version: [latest, '16.10.0']
12-
uses: ./.github/workflows/integration-test.yml
9+
nx-version: ['', '16.10.0'] # '' means current workspace version
10+
uses: ./.github/workflows/integration-test-nx-workspace.yml
1311
with:
1412
nx-version: ${{matrix.nx-version}}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Incoming Versions Compatibility Test
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: '0 0 * * *' # daily at 00:00
6+
7+
jobs:
8+
backwards-compatibility-test:
9+
strategy:
10+
matrix:
11+
nx-version: [latest]
12+
uses: ./.github/workflows/integration-test-nx-workspace.yml
13+
with:
14+
nx-version: ${{matrix.nx-version}}

.github/workflows/integration-test.yml renamed to .github/workflows/integration-test-nx-workspace.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
name: Integration Test
1+
# This can be seen as a automated simple manual test
2+
# It test the plugin with a real Nx workspace using a specific workspace version
3+
#
4+
# This integration test does:
5+
# 1. Creates a Nx workspace with the provided version
6+
# 2. Creates a node lib
7+
# 3. Adds ngx-deploy-npm plugin, test `install` generator
8+
# 4. Publish the lib suing --dry-run, test `deploy` executor
9+
name: Integration Test (Nx Workspace)
210

311
on:
412
workflow_call:
@@ -18,13 +26,14 @@ jobs:
1826
- name: Read package.json Nx and set default parameter
1927
id: set-default-param
2028
run: |
21-
version=$(jq -r '.devDependencies.nx'package.json)
22-
if [ -z "${{ github.event.inputs.nx-version }}" ]; then
29+
30+
if [ -z "${{ inputs.nx-version }}" ]; then
31+
version=$(jq -r '.devDependencies.nx' package.json)
2332
echo "Setting default value for nx-version parameter: $version"
2433
echo "NX_VERSION=$version" >> $GITHUB_ENV
2534
else
26-
echo "Using provided value for nx-version parameter: ${{ github.event.inputs.nx-version }}"
27-
echo "NX_VERSION=${{ github.event.inputs.nx-version }}" >> $GITHUB_ENV
35+
echo "Using provided value for nx-version parameter: ${{ inputs.nx-version }}"
36+
echo "NX_VERSION=${{ inputs.nx-version }}" >> $GITHUB_ENV
2837
fi
2938
3039
- name: Integration Test

.github/workflows/pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ jobs:
3636
- name: Check if Prettier was run
3737
run: npx pretty-quick --check
3838

39-
automated-manual-test:
40-
uses: ./.github/workflows/integration-test.yml
39+
backwards-compatibility-test:
40+
uses: ./.github/workflows/backwards-compatibility-test.yml
4141

4242
pr-analysis:
4343
name: SonarCloud Pr Analysis

.github/workflows/publishment.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
if: ${{ !contains(github.event.head_commit.message, 'chore(release)') }}
1818
uses: ./.github/workflows/integration-test-plugins.yml
1919

20-
automated-manual-test:
21-
uses: ./.github/workflows/integration-test.yml
20+
backwards-compatibility-test:
21+
uses: ./.github/workflows/backwards-compatibility-test.yml
2222

2323
analysis:
2424
name: SonarCloud Main Analysis
@@ -51,7 +51,7 @@ jobs:
5151
release:
5252
environment: production
5353
runs-on: ubuntu-latest
54-
needs: [release-preliminar, e2e-test, test, automated-manual-test]
54+
needs: [release-preliminar, e2e-test, test, backwards-compatibility-test]
5555
steps:
5656
- uses: actions/checkout@v4
5757
- uses: ./.github/actions/setup

packages/ngx-deploy-npm/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"executor": "nx:run-commands",
114114
"outputs": ["{workspaceRoot}/tmp/nx-workspace"],
115115
"options": {
116-
"command": "./tools/create-nx-workspace.sh"
116+
"command": "node ./tools/create-nx-workspace.js"
117117
},
118118
"dependsOn": ["yalc-it"]
119119
}

tools/create-nx-workspace.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const { spawnSync } = require('child_process');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const version = process.argv[2] || 'latest';
6+
7+
const tmpDir = path.join(__dirname, '..', 'tmp');
8+
fs.mkdirSync(tmpDir, { recursive: true });
9+
process.chdir(tmpDir);
10+
11+
// Delete the previous workspace
12+
if (fs.existsSync('nx-workspace')) {
13+
fs.rmSync('nx-workspace', { recursive: true, force: true });
14+
}
15+
16+
console.log('Creating Nx Workspace with version:', version);
17+
executeCommand(`npx --yes create-nx-workspace@${version} --version`);
18+
console.log('☝️');
19+
20+
console.log('----- Create Nx Workspace -----');
21+
executeCommand(
22+
`npx create-nx-workspace@${version} --name nx-workspace --preset npm ${
23+
version === '16.10.0' ? '--nxCloud=false' : '--nxCloud=skip'
24+
}`
25+
);
26+
process.chdir('nx-workspace');
27+
28+
fs.writeFileSync('.env', `NX_WORKSPACE_ROOT_PATH=${process.cwd()}`);
29+
30+
console.log('----- Generate lib -----');
31+
executeCommand(`npm add -D @nx/node@${version}`);
32+
executeCommand('npx nx generate @nx/node:init');
33+
executeCommand(
34+
'npx nx generate @nx/node:library nx-lib --publishable --importPath nx-lib'
35+
);
36+
37+
console.log('----- Link ngx-deploy-npm -----');
38+
executeCommand('npx --yes yalc add ngx-deploy-npm');
39+
40+
console.log('----- Add ngx-deploy-npm to the workspace -----');
41+
executeCommand(
42+
'npx nx generate ngx-deploy-npm:install --project nx-lib --distFolderPath dist/nx-lib'
43+
);
44+
45+
console.log('----- Test the build -----');
46+
executeCommand('npx nx deploy nx-lib --dry-run');
47+
48+
function executeCommand(command) {
49+
if (process.env.CI !== 'true') {
50+
console.log(`\x1b[32mExecuting command:\x1b[0m '${command}'`);
51+
}
52+
const commandArr = command.split(' ');
53+
54+
spawnSync(
55+
commandArr[0],
56+
commandArr
57+
.slice(1)
58+
.map(arg => arg.split(' '))
59+
.flat(),
60+
{
61+
stdio: 'inherit',
62+
},
63+
{
64+
stdio: 'inherit',
65+
}
66+
);
67+
}

tools/create-nx-workspace.sh

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

0 commit comments

Comments
 (0)