Skip to content

Commit

Permalink
fix(misc): make generated ci workflow work without nx-cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed May 6, 2024
1 parent f13dcce commit 511599f
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- checkout
# Connect your workspace on my.nx.app and uncomment this to enable task distribution.
# Connect your workspace on nx.app and uncomment this to enable task distribution.
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested
# - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
with:
fetch-depth: 0
# Connect your workspace on my.nx.app and uncomment this to enable task distribution.
# Connect your workspace on nx.app and uncomment this to enable task distribution.
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested
# - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"
Expand Down
12 changes: 1 addition & 11 deletions packages/gradle/src/generators/ci-workflow/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, updateJson, NxJsonConfiguration } from '@nx/devkit';
import { Tree } from '@nx/devkit';

import { ciWorkflowGenerator } from './generator';

Expand All @@ -10,16 +10,6 @@ describe('ci-workflow generator', () => {
tree = createTreeWithEmptyWorkspace();
});

beforeEach(() => {
updateJson<NxJsonConfiguration>(tree, 'nx.json', (json) => {
return {
...json,
nxCloudAccessToken: 'xxxx-xxx-xxxx',
nxCloudUrl: 'https://my.nx.app',
};
});
});

describe.each([
['github', '.github/workflows/ci.yml'],
['circleci', '.circleci/config.yml'],
Expand Down
21 changes: 8 additions & 13 deletions packages/gradle/src/generators/ci-workflow/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
formatFiles,
detectPackageManager,
readNxJson,
readJson,
} from '@nx/devkit';
import { join } from 'path';
import { getNxCloudUrl, isNxCloudUsed } from 'nx/src/utils/nx-cloud-utils';
Expand All @@ -33,13 +34,7 @@ export interface Schema {
export async function ciWorkflowGenerator(tree: Tree, schema: Schema) {
const ci = schema.ci;

const nxJson: NxJsonConfiguration = readNxJson(tree);
const nxCloudUsed = isNxCloudUsed(nxJson);
if (!nxCloudUsed) {
throw new Error('This workspace is not connected to Nx Cloud.');
}

const options = getTemplateData(schema, nxJson);
const options = getTemplateData(tree, schema);
generateFiles(tree, join(__dirname, 'files', ci), '', options);
await formatFiles(tree);
}
Expand All @@ -54,19 +49,19 @@ interface Substitutes {
nxCloudHost: string;
}

function getTemplateData(
options: Schema,
nxJson: NxJsonConfiguration
): Substitutes {
function getTemplateData(tree: Tree, options: Schema): Substitutes {
const { name: workflowName, fileName: workflowFileName } = names(
options.name
);
const packageManager = detectPackageManager();
const { exec: packageManagerPrefix } =
getPackageManagerCommand(packageManager);

const nxCloudUrl = getNxCloudUrl(nxJson);
const nxCloudHost = new URL(nxCloudUrl).host;
let nxCloudHost: string = 'nx.app';
try {
const nxCloudUrl = getNxCloudUrl(readJson(tree, 'nx.json'));
nxCloudHost = new URL(nxCloudUrl).host;
} catch {}

const mainBranch = deduceDefaultBase();

Expand Down
Loading

0 comments on commit 511599f

Please sign in to comment.