Skip to content

Commit c220777

Browse files
committed
ci(release): Add githubRelease option and handle executing in CI context
1 parent 3554961 commit c220777

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ on:
1919
type: boolean
2020
required: false
2121
default: true
22+
github-release:
23+
description: Whether or not to create Github release (doing so will require pushing changes)
24+
type: boolean
25+
required: false
26+
default: true
2227

2328
env:
2429
FORCE_COLOR: 2
@@ -71,7 +76,7 @@ jobs:
7176
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
7277
7378
- name: Release packages on '${{ inputs.channel }}' channel
74-
run: yarn release -c ${{ inputs.channel }} --verbose ${{ inputs.publish-only && '--publishOnly' }} ${{ inputs.skip-publish && '--skipPublish' }}
79+
run: yarn release -c ${{ inputs.channel }} --verbose ${{ inputs.publish-only && '--publishOnly' }} ${{ inputs.skip-publish && '--skipPublish' }} ${{ inputs.github-release && '--githubRelease'}}
7580
env:
7681
RELEASE_ENABLED: ${{ vars.RELEASE_ENABLED }}
7782
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

tools/scripts/release/changelog.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import { isPrereleaseVersion } from './version';
55
import chalk from 'chalk';
66
import { HandleChangelogOptions } from './changelog.types';
77

8-
export async function handleChangelog({
9-
projectName,
10-
isPrerelease,
11-
isCI,
12-
options,
13-
}: HandleChangelogOptions): Promise<void> {
8+
export async function handleChangelog({ projectName, isPrerelease, options }: HandleChangelogOptions): Promise<void> {
149
// Option to explicitly specify scope of the changelog
1510
let from: string | undefined;
1611
const currentVersion = options.versionData[projectName].currentVersion;
@@ -61,7 +56,5 @@ export async function handleChangelog({
6156
...options,
6257
projects: [projectName],
6358
from,
64-
// If in CI environment then commits need to be pushed
65-
gitPush: isCI,
6659
});
6760
}

tools/scripts/release/changelog.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ import { ChangelogOptions as NxChangelogOptions } from 'nx/src/command-line/rele
33
export interface HandleChangelogOptions {
44
projectName: string;
55
isPrerelease: boolean;
6-
isCI: boolean;
76
options: NxChangelogOptions;
87
}

tools/scripts/release/cli.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ export function parseReleaseCliOptions() {
5050
})
5151
.option('ci', {
5252
type: 'boolean',
53-
default: false,
5453
describe: 'Whether or not to run in CI context.',
54+
demandOption: false,
55+
})
56+
.option('githubRelease', {
57+
type: 'boolean',
58+
alias: 'ghr',
59+
default: false,
60+
describe: 'Whether or not to create Github release (doing so will require pushing changes)',
5561
})
5662
.parseAsync();
5763
}
@@ -60,6 +66,7 @@ export function parseReleaseOptions({
6066
channel,
6167
dryRun,
6268
ci,
69+
verbose,
6370
}: Awaited<ReturnType<typeof parseReleaseCliOptions>>): ParsedOptions {
6471
let isPrerelease: boolean;
6572
let preid: ReleasePreidValue;
@@ -103,12 +110,14 @@ export function parseReleaseOptions({
103110
);
104111

105112
const isCI = ci ?? isNxCI();
113+
console.log('CI', ci, isCI);
106114

107115
return {
108116
isPrerelease,
109117
preid,
110118
tag,
111119
dryRun: dryRun || !releaseEnabled,
120+
verbose: isCI || verbose,
112121
isCI,
113122
};
114123
}

tools/scripts/release/cli.types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { ReleaseChannel } from './release.consts';
33
export interface ParsedOptions {
44
isPrerelease: boolean;
55
isCI: boolean;
6-
preid?: string;
6+
preid: string | undefined;
77
tag: ReleaseChannel;
8-
dryRun?: boolean;
8+
dryRun: boolean;
9+
verbose: boolean;
910
}

tools/scripts/release/release.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { handleChangelog } from './changelog';
1313
(async () => {
1414
const options = await parseReleaseCliOptions();
1515
const graph = await createProjectGraphAsync({ exitOnError: true });
16-
const { publishOnly, projects, verbose, otp, skipPublish } = options;
17-
const { tag, preid, isPrerelease, dryRun, isCI } = parseReleaseOptions(options);
16+
const { publishOnly, projects, otp, skipPublish, githubRelease } = options;
17+
const { tag, preid, isPrerelease, dryRun, isCI, verbose } = parseReleaseOptions(options);
1818

1919
const projectsList = new Set(projects ?? []);
2020

@@ -79,12 +79,12 @@ import { handleChangelog } from './changelog';
7979
await handleChangelog({
8080
projectName,
8181
isPrerelease,
82-
isCI,
8382
options: {
8483
versionData,
8584
dryRun,
8685
verbose,
87-
createRelease: 'github',
86+
createRelease: githubRelease ? 'github' : undefined,
87+
gitPush: githubRelease || isCI ? true : undefined,
8888
},
8989
});
9090
// Add this project to projects list that will be published

0 commit comments

Comments
 (0)