fix: Fixed silent git errors #74

releases/v3
Tycho Bokdam 2020-12-14 22:57:38 +01:00
parent d55112e04c
commit 7c35f3c286
No known key found for this signature in database
GPG Key ID: A0FAE77C8CDF33C7
4 changed files with 70 additions and 33 deletions

View File

@ -11,7 +11,6 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log - run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'" - run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'" - run: "git config --global user.name 'Awesome Github action'"
@ -34,6 +33,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- name: Generate changelog - name: Generate changelog
id: changelog id: changelog
@ -58,6 +61,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- run: touch ./test-file-empty.json - run: touch ./test-file-empty.json
@ -81,6 +88,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- run: test -f pre-commit.test.json && (echo should not be here yet && exit 1) || exit 0 - run: test -f pre-commit.test.json && (echo should not be here yet && exit 1) || exit 0
@ -107,6 +118,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- run: test -f pre-changelog-generation.test.json && (echo should not be here yet && exit 1) || exit 0 - run: test -f pre-changelog-generation.test.json && (echo should not be here yet && exit 1) || exit 0
@ -136,6 +151,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- name: Generate changelog - name: Generate changelog
id: changelog id: changelog
@ -155,6 +174,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- run: git tag | xargs git tag -d - run: git tag | xargs git tag -d
@ -176,6 +199,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- name: Generate changelog - name: Generate changelog
id: changelog id: changelog
@ -196,6 +223,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- run: touch ./test-file-empty.yaml - run: touch ./test-file-empty.yaml
@ -220,6 +251,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- name: Generate changelog - name: Generate changelog
id: changelog id: changelog
@ -242,6 +277,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- name: Generate changelog - name: Generate changelog
id: changelog id: changelog
@ -262,6 +301,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- name: Generate changelog - name: Generate changelog
id: changelog id: changelog
@ -284,6 +327,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- run: touch ./test-file-empty.toml - run: touch ./test-file-empty.toml
@ -308,6 +355,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- name: Generate changelog - name: Generate changelog
id: changelog id: changelog
@ -327,6 +378,10 @@ jobs:
path: "./" path: "./"
- run: npm ci --prod - run: npm ci --prod
- run: touch ./fake-file.log
- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit -m 'feat: Added fake file so version will be bumped'"
- name: Generate Changelog - name: Generate Changelog
id: changelog id: changelog

View File

@ -86,7 +86,8 @@ inputs:
fallback-version: fallback-version:
description: 'The fallback version, if no older one can be detected, or if it is the first one' description: 'The fallback version, if no older one can be detected, or if it is the first one'
default: '0.1.0' default: '0.1.0'
required: false
config-file-path: config-file-path:
description: 'Path to the conventional changelog config file. If set, the preset setting will be ignored' description: 'Path to the conventional changelog config file. If set, the preset setting will be ignored'
required: false required: false

View File

@ -37,28 +37,14 @@ module.exports = new (class Git {
* @param command * @param command
* @return {Promise<>} * @return {Promise<>}
*/ */
exec = command => new Promise(async(resolve, reject) => { exec = (command) => new Promise(async(resolve, reject) => {
let myOutput = '' const exitCode = await exec.exec(`git ${command}`)
let myError = ''
const options = { if (exitCode === 0) {
listeners: { resolve()
stdout: (data) => {
myOutput += data.toString()
},
stderr: (data) => {
myError += data.toString()
},
},
}
try { } else {
await exec.exec(`git ${command}`, null, options) reject(`Command "git ${command}" exited with code ${exitCode}.`)
resolve(myOutput)
} catch (e) {
reject(e)
} }
}) })
@ -77,7 +63,7 @@ module.exports = new (class Git {
* @param file * @param file
* @returns {*} * @returns {*}
*/ */
add = file => this.exec(`add ${file}`) add = (file) => this.exec(`add ${file}`)
/** /**
* Commit all changes * Commit all changes
@ -124,7 +110,7 @@ module.exports = new (class Git {
* *
* @return {Promise<>} * @return {Promise<>}
*/ */
isShallow = async () => { isShallow = async() => {
const isShallow = await this.exec('rev-parse --is-shallow-repository') const isShallow = await this.exec('rev-parse --is-shallow-repository')
// isShallow does not return anything on local machine // isShallow does not return anything on local machine
@ -141,7 +127,7 @@ module.exports = new (class Git {
* @param repo * @param repo
* @return {Promise<>} * @return {Promise<>}
*/ */
updateOrigin = repo => this.exec(`remote set-url origin ${repo}`) updateOrigin = (repo) => this.exec(`remote set-url origin ${repo}`)
/** /**
* Creates git tag * Creates git tag
@ -149,6 +135,6 @@ module.exports = new (class Git {
* @param tag * @param tag
* @return {Promise<>} * @return {Promise<>}
*/ */
createTag = tag => this.exec(`tag -a ${tag} -m "${tag}"`) createTag = (tag) => this.exec(`tag -a ${tag} -m "${tag}"`)
})() })()

View File

@ -172,12 +172,7 @@ async function run() {
await git.createTag(gitTag) await git.createTag(gitTag)
core.info('Push all changes') core.info('Push all changes')
try { await git.push()
await git.push()
} catch (error) {
core.setFailed(error.message)
}
// Set outputs so other actions (for example actions/create-release) can use it // Set outputs so other actions (for example actions/create-release) can use it
core.setOutput('changelog', stringChangelog) core.setOutput('changelog', stringChangelog)
@ -187,7 +182,7 @@ async function run() {
core.setOutput('skipped', 'false') core.setOutput('skipped', 'false')
}) })
} catch (error) { } catch (error) {
core.setFailed(error.message) core.setFailed(error)
} }
} }