Skip to content

Commit

Permalink
Improve and rename script for seeding GHES instances (#335)
Browse files Browse the repository at this point in the history
* Grab tokens for environment variables in seed-github-enterprise-server-instance script

* Rename seed-github-enterprise-server-instance to configure-github-enterprise-server-instance

* Seed secrets with correct GHES token
  • Loading branch information
timrogers authored Nov 13, 2024
1 parent 25b4290 commit f103490
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ From time to time, we need to add or remove supported GitHub Enterprise Server v

1. Deploy a GitHub Enterprise Server (GHES) instance of the required version
1. Create a personal access token (PAT) with the `repo`, `admin:org`, `site_admin` and `project` scopes
1. Seed the GHES instance with data and configure the Actions and Dependabot secrets. You can do this by running `npm run seed-github-enterprise-server-instance -- --ghes-access-token TOKEN --ghes-base-url https://ghes.acme.com/api/v3 --dotcom-access-token FOO`.
1. Seed the GHES instance with data and configure the Actions and Dependabot secrets. You can do this by running `npm run configure-github-enterprise-server-instance -- --ghes-access-token TOKEN --ghes-base-url https://ghes.acme.com/api/v3 --dotcom-access-token FOO`.
1. Open `.github/workflows/ci.yml` and make a copy of an existing job used to test a GHES version (e.g. `end_to_end_tests_linux_ghes_311`)
1. Rename the job to an appropriate name for the new version, e.g. `end_to_end_tests_linux_ghes_312`
1. Update the GHES version in the job's `name`
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint-and-fix": "eslint . --fix",
"dev": "npx tsx src/index.ts",
"clean-up-organization-projects": "npx tsx script/clean-up-organization-projects.ts",
"seed-github-enterprise-server-instance": "npx tsx script/seed-github-enterprise-server-instance.ts"
"configure-github-enterprise-server-instance": "npx tsx script/configure-github-enterprise-server-instance.ts"
},
"author": "Tim Rogers <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -49,4 +49,4 @@
"type": "git",
"url": "https://github.com/timrogers/gh-migrate-project.git"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,25 @@ const opts = program.opts() as {

const logger = createLogger(opts.verbose);

const octokit = createOctokit(
opts.ghesAccessToken,
opts.ghesBaseUrl,
undefined,
logger,
);
const ghesAccessToken = opts.ghesAccessToken || process.env.GHES_TOKEN;

if (!ghesAccessToken) {
logger.error(
'No GitHub Enterprise Server token provided - set --ghes-access-token or $GHES_TOKEN',
);
process.exit(1);
}

const dotcomAccessToken = opts.dotcomAccessToken || process.env.GITHUB_TOKEN;

if (!dotcomAccessToken) {
logger.error(
'No GitHub.com token provided - set --dotcom-access-token or $GITHUB_TOKEN',
);
process.exit(1);
}

const octokit = createOctokit(ghesAccessToken, opts.ghesBaseUrl, undefined, logger);

const githubProductInformation = await getGitHubProductInformation(octokit);

Expand Down Expand Up @@ -396,7 +409,7 @@ const opts = program.opts() as {
const ghesVersionForSecretName = `${parsedGhesVersion.major}${parsedGhesVersion.minor}`;

const dotcomOctokit = createOctokit(
opts.dotcomAccessToken,
dotcomAccessToken,
'https://api.github.com',
undefined,
logger,
Expand All @@ -408,7 +421,7 @@ const opts = program.opts() as {
repo: PROJECT_REPO,
sodium,
secretName: `GHES_${ghesVersionForSecretName}_ACCESS_TOKEN`,
secretValue: opts.ghesAccessToken,
secretValue: ghesAccessToken,
});

await encryptAndSetDependabotSecret({
Expand All @@ -417,7 +430,7 @@ const opts = program.opts() as {
repo: PROJECT_REPO,
sodium,
secretName: `GHES_${ghesVersionForSecretName}_ACCESS_TOKEN`,
secretValue: opts.ghesAccessToken,
secretValue: ghesAccessToken,
});

await encryptAndSetActionsSecret({
Expand Down

0 comments on commit f103490

Please sign in to comment.