Skip to content
Merged
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
6 changes: 4 additions & 2 deletions src/publish-beta/package.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ describe('package', () => {

it('generatePackageBetaTag', async () => {
process.env['GITHUB_REF'] = '/ref/2406/branch';
process.env['GITHUB_SHA'] = '1234';
const packageBetaTag = generatePackageBetaTag();
assert.ok(packageBetaTag.startsWith('2406-'));
assert.ok(packageBetaTag.startsWith('PR.2406-'));
});

it('test packageJSON Update and add /src/ to files', async () => {
const filePath = path.join(tmpdir(), 'packageUpdate/package.json');
process.env['GITHUB_REF'] = '/ref/87/branch';
process.env['GITHUB_SHA'] = '12345678ad90';
await writeFile(
path.join(tmpdir(), 'packageUpdate/package.json'),
JSON.stringify({ name: 'testpackage', version: '1.2.10', files: ['/dist/'] })
Expand All @@ -40,7 +42,7 @@ describe('package', () => {

await packageJSONUpdate(path.join(tmpdir(), 'packageUpdate'));
const rawUpdatedFile = await readFile(filePath, 'utf8');
assert.ok(JSON.parse(rawUpdatedFile).version.startsWith('1.2.10-beta.87-'));
assert.ok(JSON.parse(rawUpdatedFile).version === '1.2.10-PR.87-ad90');
assert.deepEqual(JSON.parse(rawUpdatedFile).files.sort(), ['/dist/', '/src/'].sort());
});

Expand Down
13 changes: 9 additions & 4 deletions src/publish-beta/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import path from 'node:path';
import { readFile, writeFile } from 'node:fs/promises';
import { debug } from 'debug';

import shortId from './short-id';
import { getPRNumber } from './github';
import { removeNonTSFiles } from './files';

Expand All @@ -16,10 +15,16 @@ interface PackageJSON {
files: string[];
}

const NUMBER_OF_CHARS_TO_USE_FROM_COMMIT_SHA = 4;

export function generatePackageBetaTag(): string {
const id = shortId();
const commentSha = process.env['GITHUB_SHA'];
if (!commentSha) {
throw new Error('Unable to get GITHUB_SHA');
}
const id = commentSha.slice(-NUMBER_OF_CHARS_TO_USE_FROM_COMMIT_SHA, commentSha.length);
const prNumber = getPRNumber();
return `${prNumber}-${id}`;
return `PR.${prNumber}-${id}`;
}

function checkFilesPropertyExists(packageJSON: string): void {
Expand All @@ -45,7 +50,7 @@ export async function packageJSONUpdate(rootProjectDirectory: string): Promise<s
await removeNonTSFiles(path.join(rootProjectDirectory, 'src'));

const files = addSourceToFilesProperty(packageJson);
const newVersion = `${packageJson.version}-beta.${generatePackageBetaTag()}`;
const newVersion = `${packageJson.version}-${generatePackageBetaTag()}`;
packageJson.version = newVersion;
packageJson.files = files;
await writeFile(packageJSONPath, JSON.stringify(packageJson));
Expand Down
13 changes: 0 additions & 13 deletions src/publish-beta/short-id.spec.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/publish-beta/short-id.ts

This file was deleted.