Skip to content

Commit

Permalink
feat: set default baseUrl to allow GHES usage (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
erodewald committed Oct 11, 2021
1 parent 178c0ff commit 4f1d148
Show file tree
Hide file tree
Showing 7 changed files with 9,289 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ A Github Action that can sync secrets from one repository to many others. This a

**Required** Newline delimited regex expressions to select repositories. Repositories are limited to those in which the token user is an owner or collaborator. Set `repositories_list_regex` to `False` to use a hardcoded list of repositories. Archived repositories will be ignored.

### `github_api_url`

Override default GitHub API URL. When not provided, the action will attempt to use an environment variable provided by the GitHub Action runner environment defaults.

### `repositories_list_regex`

If this value is `true` (default), the action will find all repositories available to the token user and filter based upon the regex provided. If it is `false`, it is expected that `repositories` will be an a newline delimited list in the form of org/name.
Expand Down Expand Up @@ -54,6 +58,7 @@ uses: google/secrets-sync-action
${{github.repository}}
DRY_RUN: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN_SECRETS }}
GITHUB_API_URL: ${{ secrets.CUSTOM_GITHUB_API_URL }}
CONCURRENCY: 10
env:
FOO: ${{github.run_id}}
Expand Down
19 changes: 19 additions & 0 deletions __tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ describe("getConfig", () => {
const SECRETS = ["FOO.*", "^BAR$"];
const REPOSITORIES = ["google/baz.*", "^google/foo$"];
const REPOSITORIES_LIST_REGEX = true;
const GITHUB_API_URL = "https://api.github.com";
const GITHUB_API_URL_OVERRIDE = "overridden_api_url";
const GITHUB_TOKEN = "token";
const DRY_RUN = false;
const RETRIES = 3;
const CONCURRENCY = 50;
const RUN_DELETE = false;

const inputs = {
INPUT_GITHUB_API_URL: String(GITHUB_API_URL),
INPUT_GITHUB_TOKEN: GITHUB_TOKEN,
INPUT_SECRETS: SECRETS.join("\n"),
INPUT_REPOSITORIES: REPOSITORIES.join("\n"),
Expand All @@ -61,6 +64,7 @@ describe("getConfig", () => {
process.env = { ...process.env, ...inputs };

expect(getConfig()).toEqual({
GITHUB_API_URL,
GITHUB_TOKEN,
SECRETS,
REPOSITORIES,
Expand All @@ -72,6 +76,21 @@ describe("getConfig", () => {
});
});

test("getConfig GITHUB_API_URL has fallback value", async () => {
const inputsWithoutApiUrl = inputs;
delete inputsWithoutApiUrl.INPUT_GITHUB_API_URL;
delete process.env.GITHUB_API_URL;

process.env = { ...process.env, ...inputsWithoutApiUrl };
expect(getConfig().GITHUB_API_URL).toEqual(GITHUB_API_URL);
});

test("getConfig GITHUB_API_URL uses process.env.GITHUB_API_URL when present", async () => {
process.env = { ...process.env, ...inputs };
process.env.GITHUB_API_URL = GITHUB_API_URL_OVERRIDE;
expect(getConfig().GITHUB_API_URL).toEqual(GITHUB_API_URL_OVERRIDE);
});

test("getConfig dry run should work with multiple values of true", async () => {
process.env = { ...process.env, ...inputs };

Expand Down
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ inputs:
github_token:
description: "Token to use to get repos and write secrets"
required: true
github_api_url:
description: |
Override default GitHub API URL. When not provided, the action will attempt
to use an environment variable provided by the GitHub Action runner environment
defaults.
required: false
repositories:
description: |
New line deliminated regex expressions to select repositories. Repositires
New line deliminated regex expressions to select repositories. Repositories
are limited to those in which the token user is an owner or collaborator.
Set `REPOSITORIES_LIST_REGEX` to `False` to use a hardcoded list of
repositories. Archived repositories will be ignored.
Expand Down
3 changes: 2 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,8 @@ function run() {
return;
}
const octokit = github_1.DefaultOctokit({
auth: config.GITHUB_TOKEN
auth: config.GITHUB_TOKEN,
baseUrl: process.env.GITHUB_API_URL || "https://api.github.com"
});
let repos;
if (config.REPOSITORIES_LIST_REGEX) {
Expand Down
Loading

0 comments on commit 4f1d148

Please sign in to comment.