Skip to content

Commit

Permalink
backwards compat for GITHUB_TOKEN from env (#133)
Browse files Browse the repository at this point in the history
* backwards compat for GITHUB_TOKEN from env

* update changelog
  • Loading branch information
softprops authored Jul 30, 2021
1 parent d2a05f5 commit 8779b82
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
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 || "",
github_ref: env.GITHUB_REF || "",
github_repository: env.INPUT_REPOSITORY || env.GITHUB_REPOSITORY || "",
input_name: env.INPUT_NAME,
Expand Down

0 comments on commit 8779b82

Please sign in to comment.