added package lock
This commit is contained in:
parent
f6135c0d25
commit
31f95b53bb
|
@ -1,3 +1,2 @@
|
|||
node_modules
|
||||
package-lock.json
|
||||
.nyc_output
|
||||
|
|
|
@ -2,16 +2,14 @@
|
|||
|
||||
GitHub Action for automated npm version bump.
|
||||
|
||||
This Action publishes a package to npm. It is meant to be used on every successful merge to master but
|
||||
This Action bumps the version in package.json and push it back to the repo.
|
||||
It is meant to be used on every successful merge to master but
|
||||
you'll need to configured that workflow yourself. You can look to the
|
||||
[`.github/workflows/push.yml`](./.github/workflows/push.yml) file in this project as an example.
|
||||
|
||||
### Workflow
|
||||
|
||||
* Check for the latest version number published to npm.
|
||||
* Lookup all commits between the git commit that triggered the action and the latest publish.
|
||||
* If the package hasn't been published or the prior publish does not include a git hash, we'll
|
||||
only pull the commit data that triggered the action.
|
||||
* Based on the commit messages, increment the version from the lastest release.
|
||||
* If the string "BREAKING CHANGE" is found anywhere in any of the commit messages or descriptions the major
|
||||
version will be incremented.
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ -n "$NPM_AUTH_TOKEN" ]; then
|
||||
# Respect NPM_CONFIG_USERCONFIG if it is provided, default to $HOME/.npmrc
|
||||
NPM_CONFIG_USERCONFIG="${NPM_CONFIG_USERCONFIG-"$HOME/.npmrc"}"
|
||||
NPM_REGISTRY_URL="${NPM_REGISTRY_URL-registry.npmjs.org}"
|
||||
NPM_STRICT_SSL="${NPM_STRICT_SSL-true}"
|
||||
NPM_REGISTRY_SCHEME="https"
|
||||
if ! $NPM_STRICT_SSL
|
||||
then
|
||||
NPM_REGISTRY_SCHEME="http"
|
||||
fi
|
||||
|
||||
# Allow registry.npmjs.org to be overridden with an environment variable
|
||||
printf "//%s/:_authToken=%s\\nregistry=%s\\nstrict-ssl=%s" "$NPM_REGISTRY_URL" "$NPM_AUTH_TOKEN" "${NPM_REGISTRY_SCHEME}://$NPM_REGISTRY_URL" "${NPM_STRICT_SSL}" > "$NPM_CONFIG_USERCONFIG"
|
||||
|
||||
chmod 0600 "$NPM_CONFIG_USERCONFIG"
|
||||
fi
|
||||
|
||||
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
|
||||
|
||||
git config user.name "Bump Version"
|
||||
git config user.email "gh-action-bump-version@users.noreply.github.com"
|
||||
git remote add gh-action-bump-version "${remote_repo}"
|
||||
|
||||
if [ "$GITHUB_REPOSITORY" = "phips28/gh-action-bump-version" ]
|
||||
then
|
||||
echo "node gh-action-bump-version-run.js"
|
||||
sh -c "node gh-action-bump-version-run.js $*"
|
||||
else
|
||||
echo "npx gh-action-bump-version"
|
||||
sh -c "npx gh-action-bump-version $*"
|
||||
fi
|
|
@ -1,46 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
const event = JSON.parse(fs.readFileSync('/github/workflow/event.json').toString())
|
||||
|
||||
let pkg = require(path.join(process.cwd(), 'package.json'))
|
||||
|
||||
const run = async () => {
|
||||
console.log('event:', event)
|
||||
let messages = event.commits.map(commit => commit.message + '\n' + commit.body)
|
||||
|
||||
const commitMessage = 'version bump to'
|
||||
const isVersionBump = messages.map(message => message.toLowerCase().includes(commitMessage)).includes(true)
|
||||
if (isVersionBump) {
|
||||
return
|
||||
}
|
||||
|
||||
let version = 'patch'
|
||||
if (messages.map(message => message.includes('BREAKING CHANGE')).includes(true)) {
|
||||
version = 'major'
|
||||
} else if (messages.map(message => message.toLowerCase().startsWith('feat')).includes(true)) {
|
||||
version = 'minor'
|
||||
}
|
||||
|
||||
const exec = str => {
|
||||
return process.stdout.write(execSync(str))
|
||||
}
|
||||
|
||||
let current = pkg.version.toString()
|
||||
exec(`git checkout master`)
|
||||
exec(`npm version --allow-same-version=true --git-tag-version=false ${current} `)
|
||||
console.log('current:', current, '/', 'version:', version)
|
||||
let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString()
|
||||
console.log('new version:', newVersion)
|
||||
exec(`git commit -a -m 'ci: ${commitMessage} ${newVersion}'`)
|
||||
|
||||
const remoteRepo = `https://${process.env.GITHUB_ACTOR}:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`
|
||||
console.log('remoteRepo:', remoteRepo)
|
||||
|
||||
exec(`git tag ${newVersion}`)
|
||||
exec(`git push "${remoteRepo}" --follow-tags`)
|
||||
exec(`git push "${remoteRepo}" --tags`)
|
||||
}
|
||||
run()
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue