Skip to content

Commit

Permalink
[ci] Enable automated versioning with semantic-version
Browse files Browse the repository at this point in the history
  • Loading branch information
sman591 committed May 23, 2019
1 parent 5c081ce commit 4effbcc
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 16 deletions.
53 changes: 37 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
language: ruby
cache:
bundler: true
yarn: true
sudo: false
bundler_args: --path vendor --local --without development
env:
- DATABASE_URL="mysql2://travis@localhost/myapp_test"
before_script:
- mysql -u root -e "CREATE DATABASE myapp_test;"
- mysql -u root -e "GRANT ALL PRIVILEGES ON myapp_test.* TO 'travis'@'%';";
- mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
script:
- bin/rails db:migrate
- RUN_COVERAGE=travis bin/rails test
- bin/rails coverage:report
addons:
code_climate:
repo_token: a42e116d4d68894b025a60cb722a0b9ba2cf1c6497debb02993d0702284d2511
deploy:
provider: script
script: bash website/travis-deploy.sh
on:
branch: master
jobs:
include:
- stage: Tests
env:
- DATABASE_URL="mysql2://travis@localhost/myapp_test"
before_script:
- mysql -u root -e "CREATE DATABASE myapp_test;"
- mysql -u root -e "GRANT ALL PRIVILEGES ON myapp_test.* TO 'travis'@'%';";
- mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
script:
- bin/rails db:migrate
- RUN_COVERAGE=travis bin/rails test
- bin/rails coverage:report
- stage: Release + website update
language: node_js
node_js: lts/*
install: true
script: skip
deploy:
provider: script
skip_cleanup: true
script:
- npx semantic-release
on:
branch: master
- # stage name not required, will continue to use `Release + website update`
language: node_js
node_js: lts/*
cache:
yarn: true
script: skip
deploy:
provider: script
skip_cleanup: true
script: bash website/travis-deploy.sh
on:
branch: master
142 changes: 142 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// For 1.0 release only
const parserOpts = {
headerPattern: /^\[(\w*)] (.*)$/,
headerCorrespondence: [`type`, `subject`],
};

const writerOpts = {
transform: (commit, context) => {
let discard = true;
const issues = [];

commit.notes.forEach(note => {
note.title = `BREAKING CHANGES`;
discard = false;
});

if (commit.type === 'breaking') {
commit.type = 'Breaking Changes';
discard = false;
}

// Re-categorize
if (commit.type === 'dokku' || commit.type == 'heroku') {
commit.scope = commit.type;
commit.type = 'deploy';
}
if (commit.type === 'readme') {
commit.type = 'docs';
}
if (commit.type === 'codeclimate' || commit.type === 'travis') {
commit.scope = commit.type;
commit.type = 'ci';
}
if (commit.type === 'config') {
commit.type = 'improvement';
}
if (commit.type === 'blazer') {
commit.type = 'fix';
}

// Set up sections
if (commit.type === `feature` || commit.type === 'feat') {
commit.type = `Features`;
} else if (commit.type === `improvement`) {
commit.type = `Improvements`;
} else if (commit.type === `fix`) {
commit.type = `Bug Fixes`;
} else if (commit.type === `perf`) {
commit.type = `Performance Improvements`;
} else if (commit.type === `revert`) {
commit.type = `Reverts`;
} else if (commit.type === `docs`) {
commit.type = `Documentation`;
} else if (commit.type === `style`) {
commit.type = `Styles`;
} else if (commit.type === `refactor`) {
commit.type = `Code Refactoring`;
} else if (commit.type === `test`) {
commit.type = `Tests`;
} else if (commit.type === `deploy`) {
commit.type = `Deployment`;
} else if (discard) {
return;
} else if (commit.type === `build`) {
commit.type = `Build System`;
} else if (commit.type === `ci`) {
commit.type = `Continuous Integration`;
}

if (commit.scope === `*`) {
commit.scope = ``;
}

if (typeof commit.hash === `string`) {
commit.hash = commit.hash.substring(0, 7);
}

if (typeof commit.subject === `string`) {
let url = context.repository
? `${context.host}/${context.owner}/${context.repository}`
: context.repoUrl;
if (url) {
url = `${url}/issues/`;
// Issue URLs.
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
issues.push(issue);
return `[#${issue}](${url}${issue})`;
});
}
if (context.host) {
// User URLs.
commit.subject = commit.subject.replace(
/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g,
(_, username) => {
if (username.includes('/')) {
return `@${username}`;
}

return `[@${username}](${context.host}/${username})`;
}
);
}
}

// remove references that already appear in the subject
commit.references = commit.references.filter(reference => {
if (issues.indexOf(reference.issue) === -1) {
return true;
}

return false;
});

return commit;
},
groupBy: `type`,
commitGroupsSort: `title`,
commitsSort: [`scope`, `subject`],
noteGroupsSort: `title`,
};

module.exports = {
plugins: [
[
'@semantic-release/commit-analyzer',
{
preset: 'angular',
releaseRules: [{ type: 'breaking', release: 'major' }],
parserOpts,
},
],
[
'@semantic-release/release-notes-generator',
{
preset: 'angular',
parserOpts,
writerOpts,
},
],
'@semantic-release/github',
],
};

0 comments on commit 4effbcc

Please sign in to comment.