-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
# Auto Rust Version Bumper | ||
# Auto Rust Version Bumper GitHub Action | ||
|
||
Using [conventional commits]() this action will automatically detect the appropriate version for a release, update the changelog and Cargo.toml and push the release to your master branch. | ||
|
||
## Inputs | ||
|
||
- `personal-access-token`: *required* Needed to push changes to the branch in question. If this is a standard github action secret, and _not_ a personal access token, it can still push, but this will not trigger any other actions. | ||
- `branch` : branch to push changelog changes to. defaults to `master` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: 'Rust Auto Version Bumper' | ||
description: "Automatically bump rust crate's changelog version based upon conventional commits." | ||
inputs: | ||
personal-access-token: # github secret for pushing changes to repo | ||
description: 'Github Action access token for updating the repo. This should be a personal action token, and _not_ the standard secret token (which cannot push/trigger other actions, such as release steps on tag eg)' | ||
required: true | ||
branch: # github secret for pushing changes to repo | ||
description: 'Branch to push to. Defaults to `master`' | ||
required: true | ||
default: 'master' | ||
# outputs: | ||
# time: # id of output | ||
# description: 'Version update' | ||
runs: | ||
using: 'node12' | ||
main: 'index.js' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
const core = require('@actions/core'); | ||
const exec = require('@actions/exec'); | ||
const standardVersion = require('standard-version'); | ||
const toml = require('@iarna/toml') | ||
const fs = require('fs'); | ||
|
||
const bump = async () => { | ||
try { | ||
core.debug("Running rust auto bumper "); | ||
const token = core.getInput('personal-access-token'); | ||
const branch = core.getInput('branch'); | ||
|
||
if( token.length === 0 ) { | ||
core.setFailed("`personal-access-token must be set") | ||
} | ||
|
||
await exec.exec('git config --local user.email "action@github.com"'); | ||
await exec.exec('git config --local user.name "GitHub Action"'); | ||
|
||
let actor = process.env.GITHUB_ACTOR; | ||
let repo = process.env.GITHUB_REPOSITORY; | ||
|
||
// bump the version | ||
await standardVersion({ | ||
noVerify: true, | ||
silent: false, | ||
}); | ||
|
||
// get info for update to commit + cargo | ||
let version = ''; | ||
let myError = ''; | ||
|
||
const versionOptions = {}; | ||
versionOptions.listeners = { | ||
stdout: (data) => { | ||
version += data.toString(); | ||
}, | ||
stderr: (data) => { | ||
myError += data.toString(); | ||
} | ||
}; | ||
|
||
await exec.exec('git', ['describe', '--tags'], versionOptions); | ||
|
||
version = version.trim(); | ||
cargo_version = version.replace('v', ''); | ||
let commit_message = ''; | ||
core.debug(`Version bumped successfully to ${version}`); | ||
|
||
const msg_options = {}; | ||
msg_options.listeners = { | ||
stdout: (data) => { | ||
commit_message += data.toString(); | ||
}, | ||
stderr: (data) => { | ||
myError += data.toString(); | ||
} | ||
}; | ||
|
||
await exec.exec('git', ['log', '-1', '--pretty=%B'], msg_options); | ||
core.debug(`Commit message added was: ${commit_message}`); | ||
|
||
// parse and update cargo.toml | ||
let cargo = fs.readFileSync('Cargo.toml'); | ||
|
||
var json = toml.parse(cargo); | ||
// special vargo version to remove "v" | ||
json.package.version = cargo_version; | ||
|
||
let cargoUpdated = toml.stringify(json); | ||
|
||
fs.writeFileSync('Cargo.toml', cargoUpdated); | ||
|
||
// commit changes | ||
await exec.exec('git', ['reset', '--soft', 'HEAD~1']); | ||
await exec.exec('git', ['add', '--all']); | ||
await exec.exec('git', ['commit', '-m', commit_message]); | ||
await exec.exec('git', ['tag', version, '-f']); | ||
|
||
// update branch with changes | ||
core.debug(`Attempting to push to ${branch}`); | ||
|
||
await exec.exec(`git push "https://${actor}:${token}@github.com/${repo}" HEAD:${branch} --tags`); | ||
|
||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
|
||
} | ||
|
||
|
||
bump() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.