Skip to content

Commit

Permalink
Merge pull request #42 from AlCalzone/circleci
Browse files Browse the repository at this point in the history
Use CircleCI instead of travis
  • Loading branch information
AlCalzone authored Mar 9, 2018
2 parents ad42cfc + 1da7d3f commit b141e7d
Show file tree
Hide file tree
Showing 10 changed files with 347 additions and 44 deletions.
200 changes: 200 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#

# Define the used images
node6: &node6
working_directory: &workdir_node6 ~/node-tradfri-client/node6
docker:
- image: circleci/node:6

# use "latest" for lint and publish
latest: &latest
working_directory: &workdir_latest ~/node-tradfri-client/latest
docker:
- image: circleci/node:8

# some job filters
tags_and_branches: &tags_and_branches
filters:
tags:
only: /^v.*/

only_tags: &only_tags
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/

# Which files to preserve between jobs
whitelist: &whitelist
paths:
- build/*
- node_modules/*
- src/*
- test/*
- coverage/*
- .npmignore
- package.json
- README.md
- tsconfig.json
- tslint.json

version: 2
jobs:
# ----------------------------------------------------
test_node6:
<<: *node6

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-node6-{{ checksum "package.json" }}

- run:
name: Install Dependencies
command: npm install
- run:
name: Remove unnecessary Dependencies
command: npm ls || true ; npm prune

- save_cache:
paths:
- node_modules
key: v1-dependencies-node6-{{ checksum "package.json" }}

- run:
name: Run component tests
command: npm run test

# ----------------------------------------------------
test_latest:
<<: *latest

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-latest-{{ checksum "package.json" }}

- run:
name: Install Dependencies
command: npm install
- run:
name: Remove unnecessary Dependencies
command: npm ls || true ; npm prune

- save_cache:
paths:
- node_modules
key: v1-dependencies-latest-{{ checksum "package.json" }}

# on latest also lint the code
- run:
name: Lint TypeScript code
command: npm run lint

- run:
name: Run component tests
command: npm run test

# persist the build files, so we can pick them up in the deploy job
- persist_to_workspace:
root: *workdir_latest
<<: *whitelist

# ----------------------------------------------------
# generates a clean build of the TypeScript sources
# to make sure there were no leftover build files
coverage:
<<: *latest

steps:
- attach_workspace:
at: *workdir_latest

- run:
name: Generate coverage report
command: npm run coverage

- run: export COVERALLS_SERVICE_NAME="CircleCI"
- run: export COVERALLS_SERVICE_JOB_ID="$CIRCLE_BUILD_NUM"

- run:
name: Upload it to coveralls.io
command: npm run coveralls

# ----------------------------------------------------
# generates a clean build of the TypeScript sources
# to make sure there were no leftover build files
build:
<<: *latest

steps:
- attach_workspace:
at: *workdir_latest

- run:
name: Clean previous builds
command: npm run prebuild

- run:
name: Build the source files
command: npm run build

- persist_to_workspace:
root: *workdir_latest
<<: *whitelist

# ----------------------------------------------------
# Deploys the final package to NPM
deploy:
<<: *latest

steps:
- attach_workspace:
at: *workdir_latest

- run:
name: Login to npm
command: npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
- run:
name: Publish package to npm
command: npm publish

# ----------------------------------------------------
# Fit it all together
workflows:
version: 2

test-and-deploy:
jobs:
- test_node6:
<<: *tags_and_branches
- test_latest:
<<: *tags_and_branches

- coverage:
requires:
- test_latest
<<: *tags_and_branches

# build only on tagged builds and if all tests succeeded
- build:
requires:
- test_node6
- test_latest
<<: *only_tags

# deploy only on tagged builds and if all tests succeeded
- deploy:
requires:
- build
<<: *only_tags
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ obj/
coverage/
maintenance/
.travis.yml
.circleci/
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# node-tradfri-client
Library to talk to IKEA Trådfri Gateways without external binaries

[![Build Status](https://travis-ci.org/AlCalzone/node-tradfri-client.svg?branch=master)](https://travis-ci.org/AlCalzone/node-tradfri-client)
[![Build Status](https://img.shields.io/circleci/project/github/AlCalzone/node-tradfri-client.svg)](https://circleci.com/gh/AlCalzone/node-tradfri-client)
[![Coverage Status](https://img.shields.io/coveralls/github/AlCalzone/node-tradfri-client.svg)](https://coveralls.io/github/AlCalzone/node-tradfri-client)

*Requires NodeJS >= 6.x*
Expand Down
24 changes: 0 additions & 24 deletions maintenance/find-unused-exports.ts

This file was deleted.

118 changes: 118 additions & 0 deletions maintenance/release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// tslint:disable:no-var-requires
// tslint:disable:no-console

/*
Bumps the package version and releases a new tag
to set off a CI and npm release run
CALL THIS WITH:
npm run release -- [<releaseType> [<postfix]] [--dry]
or
npm run release -- <version> [--dry]
*/

import { execSync } from "child_process";
import * as fs from "fs";
import * as path from "path";
import * as readline from "readline";
const semver = require("semver");
const colors = require("colors/safe");
import { argv } from "yargs";

const rootDir = path.resolve(__dirname, "../");

const packPath = path.join(rootDir, "package.json");
const pack = require(packPath);
// const ioPackPath = path.join(rootDir, "io-package.json");
// const ioPack = require(ioPackPath);

function fail(reason: string) {
console.error("");
console.error(colors.red(reason));
console.error("");
process.exit(0);
}

// check if there are untracked changes
const gitStatus = execSync("git status", {cwd: rootDir, encoding: "utf8"});
if (/have diverged/.test(gitStatus)) {
if (!argv.dry) fail(colors.red("Cannot continue, the local branch has diverged from the git repo!"));
else console.log(colors.yellow("This is a dry run. The full run would fail due to a diverged branch\n"));
} else if (!/working tree clean/.test(gitStatus)) {
if (!argv.dry) fail(colors.red("Cannot continue, the local branch has uncommited changes!"));
else console.log(colors.yellow("This is a dry run. The full run would fail due to uncommited changes\n"));
} else if (/Your branch is behind/.test(gitStatus)) {
if (!argv.dry) fail(colors.red("Cannot continue, the local branch is behind the remote changes!"));
else console.log(colors.yellow("This is a dry run. The full run would fail due to the local branch being behind\n"));
} else if (/Your branch is up\-to\-date/.test(gitStatus) || /Your branch is ahead/.test(gitStatus)) {
// all good
}

const releaseTypes = ["major", "premajor", "minor", "preminor", "patch", "prepatch", "prerelease"];

const releaseType = argv._[0] || "patch";
let newVersion = releaseType;
const oldVersion = pack.version as string;
if (releaseTypes.indexOf(releaseType) > -1) {
if (releaseType.startsWith("pre") && argv._.length >= 2) {
// increment to pre-release with an additional prerelease string
newVersion = semver.inc(oldVersion, releaseType, argv._[1]);
} else {
newVersion = semver.inc(oldVersion, releaseType);
}
console.log(`bumping version ${colors.blue(oldVersion)} to ${colors.gray(releaseType)} version ${colors.green(newVersion)}\n`);
} else {
// increment to specific version
newVersion = semver.clean(newVersion);
if (newVersion == null) {
fail(`invalid version string "${newVersion}"`);
} else {
// valid version string => check if its actually newer
if (!semver.gt(newVersion, pack.version)) {
fail(`new version ${newVersion} is NOT > than package.json version ${pack.version}`);
}
// if (!semver.gt(newVersion, ioPack.common.version)) {
// fail(`new version ${newVersion} is NOT > than io-package.json version ${ioPack.common.version}`);
// }
}
console.log(`bumping version ${oldVersion} to specific version ${newVersion}`);
}

if (argv.dry) {
console.log(colors.yellow("dry run:") + " not updating package files");
} else {
console.log(`updating package.json from ${colors.blue(pack.version)} to ${colors.green(newVersion)}`);
pack.version = newVersion;
fs.writeFileSync(packPath, JSON.stringify(pack, null, 2));

// console.log(`updating io-package.json from ${colors.blue(ioPack.common.version)} to ${colors.green(newVersion)}`);
// ioPack.common.version = newVersion;
// fs.writeFileSync(ioPackPath, JSON.stringify(ioPack, null, 4));
}

const gitCommands = [
`git add -A`,
`git commit -m "release v${newVersion} [skip ci]"`,
`git push`,
`git tag v${newVersion}`,
`git push origin --tags`,
];
if (argv.dry) {
console.log(colors.yellow("dry run:") + " I would execute this:");
for (const command of gitCommands) {
console.log(" " + command);
}
} else {
for (const command of gitCommands) {
console.log(`executing "${colors.blue(command)}" ...`);
execSync(command, {cwd: rootDir});
}
}

console.log("");
console.log(colors.green("done!"));
console.log("");

process.exit(0);
14 changes: 14 additions & 0 deletions maintenance/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compileOnSave": true,
"compilerOptions": {
"declaration": false,
"noEmit": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"target": "es2015",
},
"include": [
"./*.ts"
]
}
Loading

0 comments on commit b141e7d

Please sign in to comment.