mirror of
https://github.com/softprops/action-gh-release.git
synced 2026-03-15 09:20:54 -04:00
fix: prefer token input over GITHUB_TOKEN (#751)
Signed-off-by: Rui Chen <rui@chenrui.dev>
This commit is contained in:
@@ -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
26
dist/index.js
vendored
File diff suppressed because one or more lines are too long
10
src/util.ts
10
src/util.ts
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user