mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-07-27 04:49:49 -07:00
fix(release): skip gh attribution without CI token
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
"name": "subminer",
|
"name": "subminer",
|
||||||
"productName": "SubMiner",
|
"productName": "SubMiner",
|
||||||
"desktopName": "SubMiner.desktop",
|
"desktopName": "SubMiner.desktop",
|
||||||
"version": "0.18.0-beta.3",
|
"version": "0.18.0-beta.4",
|
||||||
"description": "All-in-one sentence mining overlay with AnkiConnect and dictionary integration",
|
"description": "All-in-one sentence mining overlay with AnkiConnect and dictionary integration",
|
||||||
"packageManager": "bun@1.3.5",
|
"packageManager": "bun@1.3.5",
|
||||||
"main": "dist/main-entry.js",
|
"main": "dist/main-entry.js",
|
||||||
|
|||||||
@@ -1213,6 +1213,102 @@ test('writeChangelogArtifacts appends contributor attribution and a new-contribu
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('writeChangelogArtifacts skips contributor attribution in GitHub Actions without a token', async () => {
|
||||||
|
const { writeChangelogArtifacts } = await loadModule();
|
||||||
|
const workspace = createWorkspace('release-notes-actions-no-token');
|
||||||
|
const projectRoot = path.join(workspace, 'SubMiner');
|
||||||
|
const originalActions = process.env.GITHUB_ACTIONS;
|
||||||
|
const originalGhToken = process.env.GH_TOKEN;
|
||||||
|
const originalGithubToken = process.env.GITHUB_TOKEN;
|
||||||
|
const originalPath = process.env.PATH;
|
||||||
|
const originalWarn = console.warn;
|
||||||
|
const warnings: string[] = [];
|
||||||
|
|
||||||
|
fs.mkdirSync(path.join(projectRoot, 'changes'), { recursive: true });
|
||||||
|
fs.writeFileSync(path.join(projectRoot, 'CHANGELOG.md'), '# Changelog\n', 'utf8');
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(projectRoot, 'changes', '001.md'),
|
||||||
|
['type: added', 'area: release', '', '- Added a feature.'].join('\n'),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
process.env.GITHUB_ACTIONS = 'true';
|
||||||
|
delete process.env.GH_TOKEN;
|
||||||
|
delete process.env.GITHUB_TOKEN;
|
||||||
|
process.env.PATH = workspace;
|
||||||
|
console.warn = (message?: unknown) => {
|
||||||
|
warnings.push(String(message));
|
||||||
|
};
|
||||||
|
|
||||||
|
writeChangelogArtifacts({
|
||||||
|
cwd: projectRoot,
|
||||||
|
version: '0.6.0',
|
||||||
|
date: '2026-05-06',
|
||||||
|
deps: { runClaude: defaultStubClaude().runClaude },
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(warnings, []);
|
||||||
|
const releaseNotes = fs.readFileSync(
|
||||||
|
path.join(projectRoot, 'release', 'release-notes.md'),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
|
assert.doesNotMatch(releaseNotes, /## What's Changed/);
|
||||||
|
} finally {
|
||||||
|
console.warn = originalWarn;
|
||||||
|
if (originalActions === undefined) {
|
||||||
|
delete process.env.GITHUB_ACTIONS;
|
||||||
|
} else {
|
||||||
|
process.env.GITHUB_ACTIONS = originalActions;
|
||||||
|
}
|
||||||
|
if (originalGhToken === undefined) {
|
||||||
|
delete process.env.GH_TOKEN;
|
||||||
|
} else {
|
||||||
|
process.env.GH_TOKEN = originalGhToken;
|
||||||
|
}
|
||||||
|
if (originalGithubToken === undefined) {
|
||||||
|
delete process.env.GITHUB_TOKEN;
|
||||||
|
} else {
|
||||||
|
process.env.GITHUB_TOKEN = originalGithubToken;
|
||||||
|
}
|
||||||
|
if (originalPath === undefined) {
|
||||||
|
delete process.env.PATH;
|
||||||
|
} else {
|
||||||
|
process.env.PATH = originalPath;
|
||||||
|
}
|
||||||
|
fs.rmSync(workspace, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('shouldSkipDefaultContributionLookup skips GitHub Actions without a gh token', async () => {
|
||||||
|
const { shouldSkipDefaultContributionLookup } = await loadModule();
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
shouldSkipDefaultContributionLookup({
|
||||||
|
GITHUB_ACTIONS: 'true',
|
||||||
|
GH_TOKEN: undefined,
|
||||||
|
GITHUB_TOKEN: undefined,
|
||||||
|
}),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
shouldSkipDefaultContributionLookup({
|
||||||
|
GITHUB_ACTIONS: 'true',
|
||||||
|
GH_TOKEN: 'ghs_test',
|
||||||
|
GITHUB_TOKEN: undefined,
|
||||||
|
}),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
shouldSkipDefaultContributionLookup({
|
||||||
|
GITHUB_ACTIONS: undefined,
|
||||||
|
GH_TOKEN: undefined,
|
||||||
|
GITHUB_TOKEN: undefined,
|
||||||
|
}),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('writeReleaseNotesForVersion preserves committed contributor attribution before installation', async () => {
|
test('writeReleaseNotesForVersion preserves committed contributor attribution before installation', async () => {
|
||||||
const { writeReleaseNotesForVersion } = await loadModule();
|
const { writeReleaseNotesForVersion } = await loadModule();
|
||||||
const workspace = createWorkspace('release-notes-preserve-attribution');
|
const workspace = createWorkspace('release-notes-preserve-attribution');
|
||||||
|
|||||||
@@ -345,6 +345,12 @@ function resolveFragmentRelativePath(fragmentPath: string, cwd: string): string
|
|||||||
return path.relative(cwd, fragmentPath).split(path.sep).join('/');
|
return path.relative(cwd, fragmentPath).split(path.sep).join('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function shouldSkipDefaultContributionLookup(
|
||||||
|
env: Partial<Record<'GITHUB_ACTIONS' | 'GH_TOKEN' | 'GITHUB_TOKEN', string>> = process.env,
|
||||||
|
): boolean {
|
||||||
|
return env.GITHUB_ACTIONS === 'true' && !env.GH_TOKEN && !env.GITHUB_TOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
// Walks git history + the GitHub API to attribute each released fragment to the
|
// Walks git history + the GitHub API to attribute each released fragment to the
|
||||||
// PR (and author) that introduced it. One git call and one gh call per fragment,
|
// PR (and author) that introduced it. One git call and one gh call per fragment,
|
||||||
// plus one gh call per unique author for the first-contribution check. Best
|
// plus one gh call per unique author for the first-contribution check. Best
|
||||||
@@ -354,6 +360,9 @@ function defaultResolveContributions(fragmentPaths: string[], cwd: string): Cont
|
|||||||
if (fragmentPaths.length === 0) {
|
if (fragmentPaths.length === 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
if (shouldSkipDefaultContributionLookup()) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const slug = execFileSync(
|
const slug = execFileSync(
|
||||||
|
|||||||
Reference in New Issue
Block a user