Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rust): provide needed information to build the project graph #29

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ on:
- main
pull_request:
env:
node_version: 18
node_version: 20

jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/workflows/setup
with:
node_version: ${{ env.node_version }}
- run: yarn nx affected --target=build --parallel --max-parallel=3
- run: yarn nx affected --target=test --parallel --max-parallel=3
- run: yarn nx affected --target=lint --parallel --max-parallel=3
- run: yarn nx affected --target=build,test,lint --parallel --max-parallel=3
- run: yarn nx affected --target=e2e --parallel
8 changes: 6 additions & 2 deletions .github/workflows/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ inputs:
node_version: # id of input
description: 'Version of node to use'
required: true
default: '18'
default: '20'

runs:
using: 'composite'
steps:
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v2
uses: nrwl/nx-set-shas@v3
- uses: actions/setup-node@v1
with:
node-version: ${{ inputs.node_version}}
- name: Install
uses: dtolnay/rust-toolchain@stable
- uses: actions/cache@v2
id: workspace-cache
with:
Expand All @@ -23,3 +25,5 @@ runs:
${{ runner.os }}-${{ inputs.node_version }}-workspace-
- run: yarn install --frozen-lockfile
shell: bash
- run: git branch --track main origin/main
shell: bash
47 changes: 47 additions & 0 deletions .verdaccio/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# path to a directory with all packages
storage: ../tmp/local-registry/storage

auth:
htpasswd:
file: ./htpasswd
algorithm: bcrypt

# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/
maxage: 60m
max_fails: 20
fail_timeout: 2m
yarn:
url: https://registry.yarnpkg.com
maxage: 60m
max_fails: 20
fail_timeout: 2

packages:
'@*/*':
# scoped packages
access: $all
publish: $all
unpublish: $all
proxy: npmjs

'**':
# give all users (including non-authenticated users) full access
# because it is a local registry
access: $all
publish: $all
unpublish: $all

# if package is not available locally, proxy requests to npm registry
proxy: npmjs

# log settings
logs:
type: stdout
format: pretty
level: warn

publish:
allow_offline: true # set offline to true to allow publish offline
1 change: 1 addition & 0 deletions .verdaccio/htpasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test:$2y$10$lVWrhBqHffH6dnroJWR.0ug.Zgehrsxdh0dRcrFSqdktWqf/sRk9S
18 changes: 18 additions & 0 deletions e2e/rust-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
15 changes: 0 additions & 15 deletions e2e/rust-e2e/jest.config.js

This file was deleted.

12 changes: 12 additions & 0 deletions e2e/rust-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable */
export default {
displayName: 'rust-e2e',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/e2e/rust-e2e',
globalSetup: '../../tools/scripts/start-local-registry.ts',
globalTeardown: '../../tools/scripts/stop-local-registry.ts',
};
16 changes: 11 additions & 5 deletions e2e/rust-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "e2e/rust-e2e/jest.config.js",
"runInBand": true,
"passWithNoTests": false
"jestConfig": "e2e/rust-e2e/jest.config.ts",
"runInBand": true
},
"dependsOn": ["rust:build"]
"dependsOn": ["^build"]
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["e2e/rust-e2e/**/*.ts"]
}
}
},
"tags": [],
"implicitDependencies": ["rust"]
}
108 changes: 108 additions & 0 deletions e2e/rust-e2e/src/rust.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { ProjectGraph } from '@nx/devkit';
import { execSync } from 'child_process';
import { mkdirSync, readFileSync, rmSync } from 'fs';
import { dirname, join } from 'path';

describe('rust', () => {
let projectDirectory: string;

beforeAll(() => {
projectDirectory = createTestProject();

// The plugin has been built and published to a local registry in the jest globalSetup
// Install the plugin built with the latest source code into the test repo
execSync(`npm install @monodon/rust@e2e`, {
cwd: projectDirectory,
stdio: 'inherit',
env: process.env,
});
});

afterAll(() => {
// Cleanup the test project
rmSync(projectDirectory, {
recursive: true,
force: true,
});
});

it('should be installed', () => {
// npm ls will fail if the package is not installed properly
execSync('npm ls @monodon/rust', {
cwd: projectDirectory,
stdio: 'inherit',
});
});

it('should generate a cargo project and update the project graph', () => {
runNxCommand(`generate @monodon/rust:bin hello-world`, projectDirectory);
runNxCommand(`generate @monodon/rust:lib lib1`, projectDirectory);

execSync('cargo add itertools -p lib1', { cwd: projectDirectory });
execSync(`cargo add lib1 --path ./lib1 -p hello_world`, {
cwd: projectDirectory,
});
expect(() =>
runNxCommand(`build hello_world`, projectDirectory)
).not.toThrow();

const projectGraph: ProjectGraph = JSON.parse(
readFileSync(
join(projectDirectory, '.nx/cache/project-graph.json')
).toString()
);

expect(projectGraph.dependencies['hello_world']).toMatchInlineSnapshot(`
Array [
Object {
"source": "hello_world",
"target": "lib1",
"type": "static",
},
]
`);
expect(projectGraph.dependencies['lib1']).toMatchInlineSnapshot(`
Array [
Object {
"source": "lib1",
"target": "cargo:itertools",
"type": "static",
},
]
`);
});
});

function runNxCommand(command: string, projectDir: string) {
execSync(`npx nx ${command}`, { cwd: projectDir, stdio: 'inherit' });
}

/**
* Creates a test project with create-nx-workspace and installs the plugin
* @returns The directory where the test project was created
*/
function createTestProject() {
const projectName = 'test-project';
const projectDirectory = join(process.cwd(), 'tmp', projectName);

// Ensure projectDirectory is empty
rmSync(projectDirectory, {
recursive: true,
force: true,
});
mkdirSync(dirname(projectDirectory), {
recursive: true,
});

execSync(
`npx --yes create-nx-workspace@latest ${projectName} --preset apps --no-nxCloud --no-interactive`,
{
cwd: dirname(projectDirectory),
stdio: 'inherit',
env: process.env,
}
);
console.log(`Created test project in "${projectDirectory}"`);

return projectDirectory;
}
42 changes: 0 additions & 42 deletions e2e/rust-e2e/tests/rust.spec.ts

This file was deleted.

3 changes: 0 additions & 3 deletions e2e/rust-e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.e2e.json"
},
{
"path": "./tsconfig.spec.json"
}
Expand Down
7 changes: 6 additions & 1 deletion e2e/rust-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.spec.ts", "**/*.d.ts"]
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getJestProjects } = require('@nx/jest');
import { getJestProjects } from '@nx/jest';

export default {
projects: getJestProjects(),
Expand Down
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@
"!{projectRoot}/src/test-setup.[jt]s"
]
},
"nxCloudAccessToken": "ZTY5ODM4MGMtNTcxNi00OGFiLWIwY2EtYTQxYzNmZTZjYWM2fHJlYWQtd3JpdGU="
"nxCloudAccessToken": "NzcyM2FlMTMtMjU2MS00NTE0LWFjNzQtNmU0OGU5YjExNzVlfHJlYWQ="
}
Loading
Loading