feat: Add pre-commit script file (hook)
The idea is to have a way for users to be able to manipulate their repositories in different ways right before the git-add-git-commit phase. Might be useful in a lot of different ways: updating arbitrary files that are not directly related to the package version, but need to have an information about the next version and being commited before the said version released; or running some chores right before the commit: including updating docs, dependencies, running scripts, etc.releases/v3
parent
6a0f767db5
commit
0aa82ce2ad
|
@ -21,6 +21,29 @@ jobs:
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.github_token }}
|
github-token: ${{ secrets.github_token }}
|
||||||
|
|
||||||
|
test-pre-commit:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: "./"
|
||||||
|
|
||||||
|
- run: test -f pre-commit.test.json && (echo should not be here yet && exit 1) || exit 0
|
||||||
|
|
||||||
|
- name: Generate changelog
|
||||||
|
id: changelog
|
||||||
|
uses: ./
|
||||||
|
env:
|
||||||
|
ENV: 'dont-use-git'
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.github_token }}
|
||||||
|
pre-commit: ${{ github.workspace }}/test/pre-commit.js
|
||||||
|
skip-on-empty: 'false'
|
||||||
|
|
||||||
|
- run: test -f pre-commit.test.json || (echo should be here && exit 1)
|
||||||
|
- run: cat pre-commit.test.json
|
||||||
|
|
||||||
test-git:
|
test-git:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
|
@ -79,6 +79,10 @@ inputs:
|
||||||
default: 'false'
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
|
pre-commit:
|
||||||
|
description: 'Path to the pre-commit script file'
|
||||||
|
required: false
|
||||||
|
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
changelog:
|
changelog:
|
||||||
|
|
12
src/index.js
12
src/index.js
|
@ -13,6 +13,7 @@ async function run() {
|
||||||
const gitUserEmail = core.getInput('git-user-email')
|
const gitUserEmail = core.getInput('git-user-email')
|
||||||
const tagPrefix = core.getInput('tag-prefix')
|
const tagPrefix = core.getInput('tag-prefix')
|
||||||
const preset = core.getInput('preset')
|
const preset = core.getInput('preset')
|
||||||
|
const preCommit = core.getInput('pre-commit')
|
||||||
const outputFile = core.getInput('output-file')
|
const outputFile = core.getInput('output-file')
|
||||||
const releaseCount = core.getInput('release-count')
|
const releaseCount = core.getInput('release-count')
|
||||||
const versionFile = core.getInput('version-file')
|
const versionFile = core.getInput('version-file')
|
||||||
|
@ -31,6 +32,10 @@ async function run() {
|
||||||
core.info(`Using "${tagPrefix}" as tag prefix`)
|
core.info(`Using "${tagPrefix}" as tag prefix`)
|
||||||
core.info(`Using "${outputFile}" as output file`)
|
core.info(`Using "${outputFile}" as output file`)
|
||||||
|
|
||||||
|
if (preCommit) {
|
||||||
|
core.info(`Using "${preCommit}" as pre-commit script`)
|
||||||
|
}
|
||||||
|
|
||||||
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'}"`)
|
||||||
|
|
||||||
|
@ -97,6 +102,13 @@ async function run() {
|
||||||
|
|
||||||
if (!skipCommit) {
|
if (!skipCommit) {
|
||||||
// Add changed files to git
|
// Add changed files to git
|
||||||
|
if (preCommit) {
|
||||||
|
await require(preCommit).preCommit({
|
||||||
|
workspace: process.env.GITHUB_WORKSPACE,
|
||||||
|
tag: gitTag,
|
||||||
|
version: versioning.newVersion,
|
||||||
|
})
|
||||||
|
}
|
||||||
await git.add('.')
|
await git.add('.')
|
||||||
await git.commit(gitCommitMessage.replace('{version}', gitTag))
|
await git.commit(gitCommitMessage.replace('{version}', gitTag))
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
exports.preCommit = (props) => {
|
||||||
|
const body = {
|
||||||
|
workspace: props.workspace,
|
||||||
|
tag: props.tag,
|
||||||
|
version: props.version,
|
||||||
|
random: Math.random(),
|
||||||
|
}
|
||||||
|
|
||||||
|
const dest = path.resolve(props.workspace, 'pre-commit.test.json')
|
||||||
|
|
||||||
|
fs.writeFileSync(dest, JSON.stringify(body, null, 2))
|
||||||
|
}
|
Loading…
Reference in New Issue