Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI/CD with GitHub Actions #274

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release

on:
push:
branches:
- master

jobs:
main:
name: Test, Tag Commit and Release to NPM
runs-on: ubuntu-latest
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.KARMARUNNERBOT_GITHUB_TOKEN }}
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
steps:
- uses: actions/checkout@v2
with:
token: ${{ env.GITHUB_TOKEN }}
- uses: actions/setup-node@v2
with:
node-version: "12.x"
cache: "yarn"
- run: yarn
- run: yarn run-example
- run: yarn build
- run: yarn run release
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test

on:
pull_request:
branches:
- master

jobs:
main:
name: Test
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.KARMARUNNERBOT_GITHUB_TOKEN }}
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-node@v2
with:
node-version: "12.x"
cache: "yarn"
- run: yarn
- run: yarn build
- run: yarn run-example
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "./dist/index.js",
"scripts": {
"build": "tsc -p src",
"run-example": "yarn build && yarn copy-dist-to-modules && yarn run-example-karma",
"copy-dist-to-modules": "rm -rf node_modules/karma-sauce-launcher && mv dist/ node_modules/karma-sauce-launcher",
"run-example-karma": "yarn karma start examples/karma.conf-ci.js"
"run-example": "yarn karma start examples/karma.conf-ci.js",
"release": "semantic-release"
},
"files": [
"dist"
Expand Down
44 changes: 30 additions & 14 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
module.exports = {
debug: true,
branches: 'master',
branches: "master",
verifyConditions: [
'@semantic-release/changelog',
'@semantic-release/github',
'@semantic-release/npm'
"@semantic-release/changelog",
"@semantic-release/github",
"@semantic-release/npm",
],
prepare: [
'@semantic-release/changelog',
'@semantic-release/git',
'@semantic-release/npm'
"./tools/update-contributors",
"@semantic-release/changelog",
"@semantic-release/git",
"@semantic-release/npm",
],
publish: [
'@semantic-release/github',
'@semantic-release/npm'
publish: ["@semantic-release/github", "@semantic-release/npm"],
success: ["@semantic-release/github"],

// The release rules determine what kind of release should be triggered
// based on the information included in the commit message. The default
// rules used by semantic-release are the same, but they are set explicitly
// for better visibility.
// See https://github.com/semantic-release/commit-analyzer/blob/master/lib/default-release-rules.js
releaseRules: [
{ breaking: true, release: "major" },
{ revert: true, release: "patch" },
{ type: "feat", release: "minor" },
{ type: "fix", release: "patch" },
{ type: "perf", release: "patch" },
],
success: [
'@semantic-release/github'
]
}

// The preset determines which commits are included in the changelog and how
// the changelog is formatted. The default value used by semantic-release is
// the same, but it is set explicitly for visibility.
// See https://semantic-release.gitbook.io/semantic-release/#commit-message-format
// See https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular
preset: "angular",
};
30 changes: 30 additions & 0 deletions tools/update-contributors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// From https://github.com/karma-runner/karma/blob/master/tools/update-contributors.js
// When modifying this file also modify upstream.
const { execSync } = require("child_process");
const { readFileSync, writeFileSync } = require("fs");
const { resolve } = require("path");

const prepare = async (pluginConfig, { logger }) => {
// Example output:
// 1042 Vojta Jina <vojta.jina@gmail.com>
// 412 Friedel Ziegelmayer <friedel.ziegelmayer@gmail.com>
// 206 dignifiedquire <friedel.ziegelmayer@gmail.com>
// 139 johnjbarton <johnjbarton@johnjbarton.com>
const stdout = execSync("git log --pretty=short | git shortlog -nse", {
encoding: "utf8",
});

const pkgPath = resolve(__dirname, "..", "package.json");
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));

// First line is already included as author field. Last line is dropped as it is an empty line.
pkg.contributors = stdout
.split("\n")
.slice(1, -1)
.map((line) => line.replace(/^[\W\d]+/, ""));
writeFileSync(pkgPath, JSON.stringify(pkg, undefined, " ") + "\n", "utf8");

logger.info("Updated contributors list.");
};

module.exports = { prepare };