Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backwards compat for GITHUB_TOKEN from env #133

Merged
merged 2 commits into from
Jul 30, 2021
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.8

- fix backwards compatibility with `GITHUB_TOKEN` resolution. `GITHUB_TOKEN` is no resolved first from an env varibale and then from and input [#133](https://github.com/softprops/action-gh-release/pull/133)

## 0.1.7

- allow creating draft releases without a tag [#95](https://github.com/softprops/action-gh-release/pull/95)
Expand Down
50 changes: 48 additions & 2 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ describe("util", () => {
input_target_commitish: undefined
});
});
});
describe("parseConfig", () => {

it("parses basic config with commitish", () => {
assert.deepStrictEqual(
parseConfig({
Expand All @@ -119,6 +118,53 @@ describe("util", () => {
}
);
});
it("prefers GITHUB_TOKEN over token input for backwards compatibility", () => {
assert.deepStrictEqual(
parseConfig({
INPUT_DRAFT: "false",
INPUT_PRERELEASE: "true",
GITHUB_TOKEN: "env-token",
INPUT_TOKEN: "input-token"
}),
{
github_ref: "",
github_repository: "",
github_token: "env-token",
input_body: undefined,
input_body_path: undefined,
input_draft: false,
input_prerelease: true,
input_files: [],
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined
}
);
});
it("uses input token as the source of GITHUB_TOKEN by default", () => {
assert.deepStrictEqual(
parseConfig({
INPUT_DRAFT: "false",
INPUT_PRERELEASE: "true",
INPUT_TOKEN: "input-token"
}),
{
github_ref: "",
github_repository: "",
github_token: "input-token",
input_body: undefined,
input_body_path: undefined,
input_draft: false,
input_prerelease: true,
input_files: [],
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined
}
);
});
it("parses basic config with draft and prerelease", () => {
assert.deepStrictEqual(
parseConfig({
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getInput } from "@actions/core";
import * as glob from "glob";
import { lstatSync, readFileSync } from "fs";

Expand Down Expand Up @@ -42,7 +41,7 @@ export const parseInputFiles = (files: string): string[] => {

export const parseConfig = (env: Env): Config => {
return {
github_token: getInput("token") || env.GITHUB_TOKEN || "",
github_token: env.GITHUB_TOKEN || env.INPUT_TOKEN || "",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note all inputs are just env variables prefixed with INPUT_. we gain easy unit testability from leveraging this fact

github_ref: env.GITHUB_REF || "",
github_repository: env.INPUT_REPOSITORY || env.GITHUB_REPOSITORY || "",
input_name: env.INPUT_NAME,
Expand Down