fix: prefer token input over GITHUB_TOKEN (#751)

Signed-off-by: Rui Chen <rui@chenrui.dev>
This commit is contained in:
Rui Chen
2026-03-14 22:29:40 -04:00
committed by GitHub
parent b25b93d384
commit b36466e122
3 changed files with 53 additions and 16 deletions

View File

@@ -292,7 +292,7 @@ describe('util', () => {
);
});
it('prefers GITHUB_TOKEN over token input for backwards compatibility', () => {
it('prefers token input over GITHUB_TOKEN', () => {
assert.deepStrictEqual(
parseConfig({
INPUT_DRAFT: 'false',
@@ -304,7 +304,7 @@ describe('util', () => {
{
github_ref: '',
github_repository: '',
github_token: 'env-token',
github_token: 'input-token',
input_working_directory: undefined,
input_append_body: false,
input_body: undefined,
@@ -324,6 +324,35 @@ describe('util', () => {
},
);
});
it('falls back to GITHUB_TOKEN when token input is empty', () => {
assert.deepStrictEqual(
parseConfig({
GITHUB_TOKEN: 'env-token',
INPUT_TOKEN: ' ',
}),
{
github_ref: '',
github_repository: '',
github_token: 'env-token',
input_working_directory: undefined,
input_append_body: false,
input_body: undefined,
input_body_path: undefined,
input_draft: undefined,
input_prerelease: undefined,
input_preserve_order: undefined,
input_files: [],
input_overwrite_files: undefined,
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: false,
input_make_latest: undefined,
},
);
});
it('uses input token as the source of GITHUB_TOKEN by default', () => {
assert.deepStrictEqual(
parseConfig({

26
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -84,9 +84,17 @@ export const parseInputFiles = (files: string): string[] => {
.filter((pat) => pat.trim() !== '');
};
const parseToken = (env: Env): string => {
const inputToken = env.INPUT_TOKEN?.trim();
if (inputToken) {
return inputToken;
}
return env.GITHUB_TOKEN?.trim() || '';
};
export const parseConfig = (env: Env): Config => {
return {
github_token: env.GITHUB_TOKEN || env.INPUT_TOKEN || '',
github_token: parseToken(env),
github_ref: env.GITHUB_REF || '',
github_repository: env.INPUT_REPOSITORY || env.GITHUB_REPOSITORY || '',
input_name: env.INPUT_NAME,