Skip to content

Commit b141e7d

Browse files
authored
Merge pull request #42 from AlCalzone/circleci
Use CircleCI instead of travis
2 parents ad42cfc + 1da7d3f commit b141e7d

10 files changed

Lines changed: 347 additions & 44 deletions

File tree

.circleci/config.yml

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# Javascript Node CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
4+
#
5+
6+
# Define the used images
7+
node6: &node6
8+
working_directory: &workdir_node6 ~/node-tradfri-client/node6
9+
docker:
10+
- image: circleci/node:6
11+
12+
# use "latest" for lint and publish
13+
latest: &latest
14+
working_directory: &workdir_latest ~/node-tradfri-client/latest
15+
docker:
16+
- image: circleci/node:8
17+
18+
# some job filters
19+
tags_and_branches: &tags_and_branches
20+
filters:
21+
tags:
22+
only: /^v.*/
23+
24+
only_tags: &only_tags
25+
filters:
26+
tags:
27+
only: /^v.*/
28+
branches:
29+
ignore: /.*/
30+
31+
# Which files to preserve between jobs
32+
whitelist: &whitelist
33+
paths:
34+
- build/*
35+
- node_modules/*
36+
- src/*
37+
- test/*
38+
- coverage/*
39+
- .npmignore
40+
- package.json
41+
- README.md
42+
- tsconfig.json
43+
- tslint.json
44+
45+
version: 2
46+
jobs:
47+
# ----------------------------------------------------
48+
test_node6:
49+
<<: *node6
50+
51+
steps:
52+
- checkout
53+
54+
# Download and cache dependencies
55+
- restore_cache:
56+
keys:
57+
- v1-dependencies-node6-{{ checksum "package.json" }}
58+
59+
- run:
60+
name: Install Dependencies
61+
command: npm install
62+
- run:
63+
name: Remove unnecessary Dependencies
64+
command: npm ls || true ; npm prune
65+
66+
- save_cache:
67+
paths:
68+
- node_modules
69+
key: v1-dependencies-node6-{{ checksum "package.json" }}
70+
71+
- run:
72+
name: Run component tests
73+
command: npm run test
74+
75+
# ----------------------------------------------------
76+
test_latest:
77+
<<: *latest
78+
79+
steps:
80+
- checkout
81+
82+
# Download and cache dependencies
83+
- restore_cache:
84+
keys:
85+
- v1-dependencies-latest-{{ checksum "package.json" }}
86+
87+
- run:
88+
name: Install Dependencies
89+
command: npm install
90+
- run:
91+
name: Remove unnecessary Dependencies
92+
command: npm ls || true ; npm prune
93+
94+
- save_cache:
95+
paths:
96+
- node_modules
97+
key: v1-dependencies-latest-{{ checksum "package.json" }}
98+
99+
# on latest also lint the code
100+
- run:
101+
name: Lint TypeScript code
102+
command: npm run lint
103+
104+
- run:
105+
name: Run component tests
106+
command: npm run test
107+
108+
# persist the build files, so we can pick them up in the deploy job
109+
- persist_to_workspace:
110+
root: *workdir_latest
111+
<<: *whitelist
112+
113+
# ----------------------------------------------------
114+
# generates a clean build of the TypeScript sources
115+
# to make sure there were no leftover build files
116+
coverage:
117+
<<: *latest
118+
119+
steps:
120+
- attach_workspace:
121+
at: *workdir_latest
122+
123+
- run:
124+
name: Generate coverage report
125+
command: npm run coverage
126+
127+
- run: export COVERALLS_SERVICE_NAME="CircleCI"
128+
- run: export COVERALLS_SERVICE_JOB_ID="$CIRCLE_BUILD_NUM"
129+
130+
- run:
131+
name: Upload it to coveralls.io
132+
command: npm run coveralls
133+
134+
# ----------------------------------------------------
135+
# generates a clean build of the TypeScript sources
136+
# to make sure there were no leftover build files
137+
build:
138+
<<: *latest
139+
140+
steps:
141+
- attach_workspace:
142+
at: *workdir_latest
143+
144+
- run:
145+
name: Clean previous builds
146+
command: npm run prebuild
147+
148+
- run:
149+
name: Build the source files
150+
command: npm run build
151+
152+
- persist_to_workspace:
153+
root: *workdir_latest
154+
<<: *whitelist
155+
156+
# ----------------------------------------------------
157+
# Deploys the final package to NPM
158+
deploy:
159+
<<: *latest
160+
161+
steps:
162+
- attach_workspace:
163+
at: *workdir_latest
164+
165+
- run:
166+
name: Login to npm
167+
command: npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
168+
- run:
169+
name: Publish package to npm
170+
command: npm publish
171+
172+
# ----------------------------------------------------
173+
# Fit it all together
174+
workflows:
175+
version: 2
176+
177+
test-and-deploy:
178+
jobs:
179+
- test_node6:
180+
<<: *tags_and_branches
181+
- test_latest:
182+
<<: *tags_and_branches
183+
184+
- coverage:
185+
requires:
186+
- test_latest
187+
<<: *tags_and_branches
188+
189+
# build only on tagged builds and if all tests succeeded
190+
- build:
191+
requires:
192+
- test_node6
193+
- test_latest
194+
<<: *only_tags
195+
196+
# deploy only on tagged builds and if all tests succeeded
197+
- deploy:
198+
requires:
199+
- build
200+
<<: *only_tags

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ obj/
1515
coverage/
1616
maintenance/
1717
.travis.yml
18+
.circleci/

.travis.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# node-tradfri-client
22
Library to talk to IKEA Trådfri Gateways without external binaries
33

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

77
*Requires NodeJS >= 6.x*

maintenance/find-unused-exports.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

maintenance/release.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// tslint:disable:no-var-requires
2+
// tslint:disable:no-console
3+
4+
/*
5+
6+
Bumps the package version and releases a new tag
7+
to set off a CI and npm release run
8+
9+
CALL THIS WITH:
10+
npm run release -- [<releaseType> [<postfix]] [--dry]
11+
or
12+
npm run release -- <version> [--dry]
13+
14+
*/
15+
16+
import { execSync } from "child_process";
17+
import * as fs from "fs";
18+
import * as path from "path";
19+
import * as readline from "readline";
20+
const semver = require("semver");
21+
const colors = require("colors/safe");
22+
import { argv } from "yargs";
23+
24+
const rootDir = path.resolve(__dirname, "../");
25+
26+
const packPath = path.join(rootDir, "package.json");
27+
const pack = require(packPath);
28+
// const ioPackPath = path.join(rootDir, "io-package.json");
29+
// const ioPack = require(ioPackPath);
30+
31+
function fail(reason: string) {
32+
console.error("");
33+
console.error(colors.red(reason));
34+
console.error("");
35+
process.exit(0);
36+
}
37+
38+
// check if there are untracked changes
39+
const gitStatus = execSync("git status", {cwd: rootDir, encoding: "utf8"});
40+
if (/have diverged/.test(gitStatus)) {
41+
if (!argv.dry) fail(colors.red("Cannot continue, the local branch has diverged from the git repo!"));
42+
else console.log(colors.yellow("This is a dry run. The full run would fail due to a diverged branch\n"));
43+
} else if (!/working tree clean/.test(gitStatus)) {
44+
if (!argv.dry) fail(colors.red("Cannot continue, the local branch has uncommited changes!"));
45+
else console.log(colors.yellow("This is a dry run. The full run would fail due to uncommited changes\n"));
46+
} else if (/Your branch is behind/.test(gitStatus)) {
47+
if (!argv.dry) fail(colors.red("Cannot continue, the local branch is behind the remote changes!"));
48+
else console.log(colors.yellow("This is a dry run. The full run would fail due to the local branch being behind\n"));
49+
} else if (/Your branch is up\-to\-date/.test(gitStatus) || /Your branch is ahead/.test(gitStatus)) {
50+
// all good
51+
}
52+
53+
const releaseTypes = ["major", "premajor", "minor", "preminor", "patch", "prepatch", "prerelease"];
54+
55+
const releaseType = argv._[0] || "patch";
56+
let newVersion = releaseType;
57+
const oldVersion = pack.version as string;
58+
if (releaseTypes.indexOf(releaseType) > -1) {
59+
if (releaseType.startsWith("pre") && argv._.length >= 2) {
60+
// increment to pre-release with an additional prerelease string
61+
newVersion = semver.inc(oldVersion, releaseType, argv._[1]);
62+
} else {
63+
newVersion = semver.inc(oldVersion, releaseType);
64+
}
65+
console.log(`bumping version ${colors.blue(oldVersion)} to ${colors.gray(releaseType)} version ${colors.green(newVersion)}\n`);
66+
} else {
67+
// increment to specific version
68+
newVersion = semver.clean(newVersion);
69+
if (newVersion == null) {
70+
fail(`invalid version string "${newVersion}"`);
71+
} else {
72+
// valid version string => check if its actually newer
73+
if (!semver.gt(newVersion, pack.version)) {
74+
fail(`new version ${newVersion} is NOT > than package.json version ${pack.version}`);
75+
}
76+
// if (!semver.gt(newVersion, ioPack.common.version)) {
77+
// fail(`new version ${newVersion} is NOT > than io-package.json version ${ioPack.common.version}`);
78+
// }
79+
}
80+
console.log(`bumping version ${oldVersion} to specific version ${newVersion}`);
81+
}
82+
83+
if (argv.dry) {
84+
console.log(colors.yellow("dry run:") + " not updating package files");
85+
} else {
86+
console.log(`updating package.json from ${colors.blue(pack.version)} to ${colors.green(newVersion)}`);
87+
pack.version = newVersion;
88+
fs.writeFileSync(packPath, JSON.stringify(pack, null, 2));
89+
90+
// console.log(`updating io-package.json from ${colors.blue(ioPack.common.version)} to ${colors.green(newVersion)}`);
91+
// ioPack.common.version = newVersion;
92+
// fs.writeFileSync(ioPackPath, JSON.stringify(ioPack, null, 4));
93+
}
94+
95+
const gitCommands = [
96+
`git add -A`,
97+
`git commit -m "release v${newVersion} [skip ci]"`,
98+
`git push`,
99+
`git tag v${newVersion}`,
100+
`git push origin --tags`,
101+
];
102+
if (argv.dry) {
103+
console.log(colors.yellow("dry run:") + " I would execute this:");
104+
for (const command of gitCommands) {
105+
console.log(" " + command);
106+
}
107+
} else {
108+
for (const command of gitCommands) {
109+
console.log(`executing "${colors.blue(command)}" ...`);
110+
execSync(command, {cwd: rootDir});
111+
}
112+
}
113+
114+
console.log("");
115+
console.log(colors.green("done!"));
116+
console.log("");
117+
118+
process.exit(0);

maintenance/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compileOnSave": true,
3+
"compilerOptions": {
4+
"declaration": false,
5+
"noEmit": true,
6+
"module": "commonjs",
7+
"moduleResolution": "node",
8+
"noImplicitAny": true,
9+
"target": "es2015",
10+
},
11+
"include": [
12+
"./*.ts"
13+
]
14+
}

0 commit comments

Comments
 (0)