pull git config init into dedicated method

releases/v3
Michael Bianco 2023-05-18 06:54:29 -06:00
parent 1607ac70d5
commit bbae9470db
No known key found for this signature in database
GPG Key ID: E5E32D3B0D0B4261
2 changed files with 18 additions and 17 deletions

View File

@ -14,10 +14,6 @@ module.exports = new (class Git {
// Make the Github token secret // Make the Github token secret
core.setSecret(githubToken) core.setSecret(githubToken)
const gitUserName = core.getInput('git-user-name')
const gitUserEmail = core.getInput('git-user-email')
const gitUrl = core.getInput('git-url')
// if the env is dont-use-git then we mock exec as we are testing a workflow // if the env is dont-use-git then we mock exec as we are testing a workflow
if (ENV === 'dont-use-git') { if (ENV === 'dont-use-git') {
this.exec = (command) => { this.exec = (command) => {
@ -30,19 +26,22 @@ module.exports = new (class Git {
} }
} }
} }
}
// use a self-invoking async function to await promises inside a constructor init = async () => {
// this avoids git config lock errors which are triggered when multiple `git config` commands are run const gitUserName = core.getInput('git-user-name')
(async () => { const gitUserEmail = core.getInput('git-user-email')
// Set config const gitUrl = core.getInput('git-url')
await this.config('user.name', gitUserName) const githubToken = core.getInput('github-token')
await this.config('user.email', gitUserEmail)
// Update the origin // Set config
if (githubToken) { await this.config('user.name', gitUserName)
await this.updateOrigin(`https://x-access-token:${githubToken}@${gitUrl}/${GITHUB_REPOSITORY}.git`) await this.config('user.email', gitUserEmail)
}
})() // Update the origin
if (githubToken) {
await this.updateOrigin(`https://x-access-token:${githubToken}@${gitUrl}/${GITHUB_REPOSITORY}.git`)
}
} }
/** /**

View File

@ -79,6 +79,8 @@ async function run() {
core.info(`Skipping empty releases is "${skipEmptyRelease ? 'enabled' : 'disabled'}"`) core.info(`Skipping empty releases is "${skipEmptyRelease ? 'enabled' : 'disabled'}"`)
core.info(`Skipping the update of the version file is "${skipVersionFile ? 'enabled' : 'disabled'}"`) core.info(`Skipping the update of the version file is "${skipVersionFile ? 'enabled' : 'disabled'}"`)
await git.init()
if (!skipGitPull) { if (!skipGitPull) {
core.info('Pull to make sure we have the full git history') core.info('Pull to make sure we have the full git history')
await git.pull() await git.pull()