From 47459c6bbb4e2acf60e9a649171442c4b2676631 Mon Sep 17 00:00:00 2001 From: rhysd Date: Sat, 16 Nov 2019 09:18:58 +0900 Subject: [PATCH] v1.1.2 --- action.yml | 7 +++++-- git.js | 5 +++-- write.js | 19 ++++++++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 02e08c231..4e3510d0a 100644 --- a/action.yml +++ b/action.yml @@ -22,10 +22,13 @@ inputs: required: true default: 'dev/bench' github-token: - description: 'GitHub API token to pull/push GitHub pages branch and deploy GitHub pages' + description: 'GitHub API token to pull/push GitHub pages branch and deploy GitHub pages. For public repository, this must be personal access token. Please read README.md for more details' required: false + auto-push: + description: 'Push GitHub Pages branch to remote automatically. This option requires github-token input' + required: false + default: false runs: using: 'node12' main: 'index.js' - diff --git a/git.js b/git.js index bbade8118..1f006d213 100644 --- a/git.js +++ b/git.js @@ -32,8 +32,9 @@ async function capture(cmd, args) { } catch (err) { const info = JSON.stringify(res); - core.debug(`Command '${args}' failed with args ${args.join(' ')}: ${info}`); - throw err; + const msg = `Command '${cmd}' failed with args '${args.join(' ')}': ${info}`; + core.debug(msg); + throw new Error(msg); } } async function cmd(...args) { diff --git a/write.js b/write.js index d2dbcfb4b..a7fc1dc32 100644 --- a/write.js +++ b/write.js @@ -58,6 +58,23 @@ async function addIndexHtmlIfNeeded(dir) { await git.cmd('add', indexHtml); console.log('Created default index.html at', indexHtml); } +async function pushGitHubPages(token, branch) { + try { + await git.push(token, branch); + return; + } + catch (err) { + if (!(err instanceof Error) || !err.message.includes('[remote rejected]')) { + throw err; + } + // Fall through + } + core.warning('Auto push failed because remote seemed to be updated after git pull. Retrying...'); + // Retry push after pull with rebasing + await git.pull(token, branch, '--rebase'); + await git.push(token, branch); + core.debug('Retrying auto push was successfully done'); +} async function writeBenchmark(bench, config) { var _a, _b, _c, _d; const { name, tool, ghPagesBranch, benchmarkDataDirPath, githubToken, autoPush } = config; @@ -85,7 +102,7 @@ async function writeBenchmark(bench, config) { await addIndexHtmlIfNeeded(benchmarkDataDirPath); await git.cmd('-c', 'user.name=github-action-benchmark', '-c', 'user.email=github@users.noreply.github.com', 'commit', '-m', `add ${name} (${tool}) benchmark result for ${bench.commit.id}`); if (githubToken && autoPush) { - await git.push(githubToken, ghPagesBranch); + await pushGitHubPages(githubToken, ghPagesBranch); console.log(`Automatically pushed the generated commit to ${ghPagesBranch} branch since 'auto-push' is set to true`); } else {