Skip to content

Commit

Permalink
feat(bump): initial bump attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuef committed Jul 21, 2020
1 parent 4c0cca9 commit 7ae5bf2
Show file tree
Hide file tree
Showing 3,012 changed files with 249,574 additions and 2 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Empty file added .gitignore
Empty file.
6 changes: 5 additions & 1 deletion README.md
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`
16 changes: 16 additions & 0 deletions action.yml
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'
92 changes: 92 additions & 0 deletions 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()
1 change: 1 addition & 0 deletions node_modules/.bin/JSONStream

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/conventional-changelog-writer

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/conventional-commits-parser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/conventional-recommended-bump

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/get-pkg-repo

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/git-raw-commits

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/git-semver-tags

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/handlebars

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/shjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/standard-version

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/strip-indent

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/uglifyjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7ae5bf2

Please sign in to comment.