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

Implement deploy to another repository #112

Merged
merged 77 commits into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
5673c2f
Implement deploy to another repository
ebraminio Jun 9, 2020
f3346a9
Update src/git.ts
ktbarrett Feb 28, 2022
e50abdf
use path.join to concatenate paths safely
ktrz Mar 27, 2022
24cb424
add gh-repository param to action.yml
ktrz Mar 27, 2022
77fa274
add unit tests for write.ts with different ghRepository
ktrz Mar 27, 2022
af05022
add debug info fo ci_validate_modification.ts
ktrz Mar 27, 2022
89bad1b
add debug info fo ci_validate_modification.ts
ktrz Mar 27, 2022
bdd5e69
add debug info fo ci_validate_modification.ts
ktrz Mar 27, 2022
602ca3f
Merge branch 'master' into push-other-repo
ktrz May 19, 2022
8e0e38e
debugging WIP
ktrz May 19, 2022
807ecae
debugging WIP
ktrz May 19, 2022
2f08895
debugging WIP
ktrz May 19, 2022
17ce6ca
debugging WIP
ktrz May 19, 2022
05b2b40
debugging WIP
ktrz May 19, 2022
92f3ef0
debugging WIP
ktrz May 19, 2022
da04798
debugging WIP
ktrz May 19, 2022
a000404
debugging WIP
ktrz May 19, 2022
02b21f2
revert debugging changes
ktrz May 19, 2022
ec0324a
fix unit tests
ktrz May 19, 2022
214be67
add check for a new param in CI
ktrz May 19, 2022
de7996f
fix gh-repository param
ktrz May 19, 2022
8b49731
debug WIP
ktrz May 19, 2022
8f1c2b0
use matrix
ktrz May 19, 2022
30bf392
improve ci_validate_modification.ts
ktrz May 19, 2022
0c57bbe
update node version in ci runner
ktrz May 19, 2022
66dd7da
debug WIP
ktrz May 19, 2022
624896d
debug WIP
ktrz May 19, 2022
b9ddd89
pass github-token
ktrz May 19, 2022
f4a9ca3
fix expression in yaml file
ktrz May 19, 2022
99fb4d0
fix yaml
ktrz May 19, 2022
31a7824
fix yaml
ktrz May 19, 2022
411b2eb
fix yaml
ktrz May 19, 2022
b0dc086
fix order of git params
ktrz May 19, 2022
5495341
simplify git command
ktrz May 19, 2022
88162ce
simplify git command
ktrz May 19, 2022
cac24fc
fix git command
ktrz May 19, 2022
efd334f
hopefully fix git command
ktrz May 19, 2022
4acee7e
hopefully fix git command
ktrz May 19, 2022
32c02b3
debugging WIP
ktrz May 19, 2022
14060e0
try using --work-dir option
ktrz May 19, 2022
4693f68
try using --work-tree option
ktrz May 19, 2022
915edab
try using --git-dir option
ktrz May 19, 2022
afd63b7
fix cloning logic
ktrz May 19, 2022
e9ee6fb
try ignoring benchmark-data-repository folder
ktrz May 19, 2022
0909468
fix git add
ktrz May 19, 2022
c65776b
fix git commands for adding new data.json and index.html file
ktrz May 19, 2022
53e8c97
debugging WIP
ktrz May 19, 2022
207f8f2
debugging WIP
ktrz May 19, 2022
65b9621
auto push once
ktrz May 19, 2022
d22cb05
add BENCHMARK_ACTION_BOT_TOKEN
ktrz May 19, 2022
5ad42cc
print after script
ktrz May 19, 2022
8fce255
comment out unnecessary noise
ktrz May 19, 2022
d24b497
debug WIP
ktrz May 19, 2022
55ba839
print the whole diff
ktrz May 19, 2022
baf79a5
new approach
ktrz May 19, 2022
fb3bf2d
new approach v2
ktrz May 19, 2022
bf8cabd
new approach v3
ktrz May 19, 2022
152ef6e
add separate workflow file for storing results in separate repo
ktrz May 19, 2022
eefe2ff
copy correct file
ktrz May 19, 2022
c99b648
checkout other repo
ktrz May 19, 2022
b9f8b71
fix regular CI
ktrz May 19, 2022
df5e7bc
fix separate repo CI
ktrz May 19, 2022
346eb59
no need to checkout back if pushing to separate repo
ktrz May 19, 2022
388793c
check if token provided when gh-repository is set
ktrz May 19, 2022
4191b15
cleanup unnecessary changes
ktrz May 19, 2022
60a2ee2
improve ci_validate_modification.ts script
ktrz May 19, 2022
71575c3
fix last failing build
ktrz May 19, 2022
5595f64
auto-push to a test branch
ktrz May 28, 2022
1dd5cdf
auto-push to a test branch (push to proper branch)
ktrz May 28, 2022
bb4c773
uncomment remaining jobs
ktrz May 28, 2022
7d7d037
remove unnecessary `skip-fetch-gh-pages` option
ktrz May 28, 2022
fa41cb8
add push to other repo on merge to master
ktrz May 28, 2022
0c36b6e
Merge branch 'master' into push-other-repo
ktrz May 28, 2022
03043dd
disable push to other repo until new version is released
ktrz May 28, 2022
1b1c8f5
cleanup
ktrz May 28, 2022
31deff6
update CHANGELOG.md and fix yamllint warnings
ktrz May 28, 2022
af54762
update README.md
ktrz May 28, 2022
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
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface Config {
tool: ToolType;
outputFilePath: string;
ghPagesBranch: string;
ghRepository: string | undefined;
benchmarkDataDirPath: string;
githubToken: string | undefined;
autoPush: boolean;
Expand Down Expand Up @@ -228,6 +229,7 @@ export async function configFromJobInput(): Promise<Config> {
const tool: string = core.getInput('tool');
let outputFilePath: string = core.getInput('output-file-path');
const ghPagesBranch: string = core.getInput('gh-pages-branch');
const ghRepository: string = core.getInput('gh-repository');
let benchmarkDataDirPath: string = core.getInput('benchmark-data-dir-path');
const name: string = core.getInput('name');
const githubToken: string | undefined = core.getInput('github-token') || undefined;
Expand Down Expand Up @@ -270,6 +272,7 @@ export async function configFromJobInput(): Promise<Config> {
tool,
outputFilePath,
ghPagesBranch,
ghRepository,
benchmarkDataDirPath,
githubToken,
autoPush,
Expand Down
23 changes: 21 additions & 2 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ export async function cmd(...args: string[]): Promise<string> {
return res.stdout;
}

function getRemoteUrl(token: string): string {
function getRemoteUrl(token: string, serverName?: string): string {
const { repo, owner } = github.context.repo;
const serverName = getServerName(github.context.payload.repository?.html_url);
if (!serverName) {
serverName = getServerName(github.context.payload.repository?.html_url);
}
return `https://x-access-token:${token}@${serverName}/${owner}/${repo}.git`;
}

Expand Down Expand Up @@ -107,3 +109,20 @@ export async function fetch(token: string | undefined, branch: string, ...option

return cmd(...args);
}

export async function clone(
token: string | undefined,
ghRepository: string,
branch: string,
...options: string[]
): Promise<string> {
core.debug(`Executing 'git fetch' to branch '${branch}' with token and options '${options.join(' ')}'`);
ktbarrett marked this conversation as resolved.
Show resolved Hide resolved

const remote = token !== undefined ? getRemoteUrl(token, ghRepository) : 'origin';
ktrz marked this conversation as resolved.
Show resolved Hide resolved
let args = ['clone', remote, branch];
if (options.length > 0) {
args = args.concat(options);
}

return cmd(...args);
}
39 changes: 27 additions & 12 deletions src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ async function writeBenchmarkToGitHubPagesWithRetry(
name,
tool,
ghPagesBranch,
ghRepository,
benchmarkDataDirPath,
githubToken,
autoPush,
Expand All @@ -380,7 +381,14 @@ async function writeBenchmarkToGitHubPagesWithRetry(
// FIXME: This payload is not available on `schedule:` or `workflow_dispatch:` events.
const isPrivateRepo = github.context.payload.repository?.private ?? false;

if (!skipFetchGhPages && (!isPrivateRepo || githubToken)) {
let benchmarkBaseDir = './';
let extraGitArguments: string[] = [];

if (!skipFetchGhPages && ghRepository) {
await git.clone(githubToken, ghRepository, ghPagesBranch, 'benchmarkDataRepository');
benchmarkBaseDir = './benchmarkDataRepository/';
extraGitArguments = ['--work-tree=' + benchmarkBaseDir, '--git-dir=' + benchmarkBaseDir + '.git'];
} else if (!skipFetchGhPages && (!isPrivateRepo || githubToken)) {
ktrz marked this conversation as resolved.
Show resolved Hide resolved
await git.pull(githubToken, ghPagesBranch);
} else if (isPrivateRepo && !skipFetchGhPages) {
core.warning(
Expand All @@ -389,20 +397,25 @@ async function writeBenchmarkToGitHubPagesWithRetry(
);
}

await io.mkdirP(benchmarkDataDirPath);
await io.mkdirP(benchmarkBaseDir + benchmarkDataDirPath);
ktrz marked this conversation as resolved.
Show resolved Hide resolved

const data = await loadDataJs(dataPath);
const data = await loadDataJs(benchmarkBaseDir + dataPath);
ktrz marked this conversation as resolved.
Show resolved Hide resolved
const prevBench = addBenchmarkToDataJson(name, bench, data, maxItemsInChart);

await storeDataJs(dataPath, data);
await storeDataJs(benchmarkBaseDir + dataPath, data);
ktrz marked this conversation as resolved.
Show resolved Hide resolved

await git.cmd('add', dataPath);
await addIndexHtmlIfNeeded(benchmarkDataDirPath);
await git.cmd('commit', '-m', `add ${name} (${tool}) benchmark result for ${bench.commit.id}`);
await addIndexHtmlIfNeeded(benchmarkBaseDir + benchmarkDataDirPath);
ktrz marked this conversation as resolved.
Show resolved Hide resolved
await git.cmd(
'commit',
'-m',
`add ${name} (${tool}) benchmark result for ${bench.commit.id}`,
...extraGitArguments,
);

if (githubToken && autoPush) {
try {
await git.push(githubToken, ghPagesBranch);
await git.push(githubToken, ghPagesBranch, ...extraGitArguments);
console.log(
`Automatically pushed the generated commit to ${ghPagesBranch} branch since 'auto-push' is set to true`,
);
Expand All @@ -416,7 +429,7 @@ async function writeBenchmarkToGitHubPagesWithRetry(

if (retry > 0) {
core.debug('Rollback the auto-generated commit before retry');
await git.cmd('reset', '--hard', 'HEAD~1');
await git.cmd('reset', '--hard', 'HEAD~1', ...extraGitArguments);

core.warning(
`Retrying to generate a commit and push to remote ${ghPagesBranch} with retry count ${retry}...`,
Expand All @@ -439,11 +452,13 @@ async function writeBenchmarkToGitHubPagesWithRetry(
}

async function writeBenchmarkToGitHubPages(bench: Benchmark, config: Config): Promise<Benchmark | null> {
const { ghPagesBranch, skipFetchGhPages, githubToken } = config;
if (!skipFetchGhPages) {
await git.fetch(githubToken, ghPagesBranch);
const { ghPagesBranch, skipFetchGhPages, ghRepository, githubToken } = config;
if (!ghRepository) {
ktrz marked this conversation as resolved.
Show resolved Hide resolved
if (!skipFetchGhPages) {
await git.fetch(githubToken, ghPagesBranch);
}
await git.cmd('switch', ghPagesBranch);
}
await git.cmd('switch', ghPagesBranch);
try {
return await writeBenchmarkToGitHubPagesWithRetry(bench, config, 10);
} finally {
Expand Down
2 changes: 2 additions & 0 deletions test/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ describe('configFromJobInput()', function () {
name: string;
tool: string;
ghPagesBranch: string;
ghRepository: string | undefined;
githubToken: string | undefined;
autoPush: boolean;
skipFetchGhPages: boolean;
Expand All @@ -191,6 +192,7 @@ describe('configFromJobInput()', function () {
name: 'Benchmark',
tool: 'cargo',
ghPagesBranch: 'gh-pages',
ghRepository: undefined,
autoPush: false,
skipFetchGhPages: false,
githubToken: undefined,
Expand Down
2 changes: 2 additions & 0 deletions test/write.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBe
tool: 'cargo',
outputFilePath: 'dummy', // Should not affect
ghPagesBranch: 'dummy', // Should not affect
ghRepository: undefined,
benchmarkDataDirPath: 'dummy', // Should not affect
githubToken: undefined,
autoPush: false,
Expand Down Expand Up @@ -892,6 +893,7 @@ describe.each(['https://github.com', 'https://github.enterprise.corp'])('writeBe
tool: 'cargo',
outputFilePath: 'dummy', // Should not affect
ghPagesBranch: 'gh-pages',
ghRepository: undefined,
benchmarkDataDirPath: 'data-dir', // Should not affect
githubToken: 'dummy token',
autoPush: true,
Expand Down