Skip to content

Commit

Permalink
Merge pull request #23 from haensl/22
Browse files Browse the repository at this point in the history
#22: Migrate to CircleCI.
  • Loading branch information
haensl authored Feb 2, 2021
2 parents f12a4ad + 7bc7edc commit 7c8f428
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 27 deletions.
275 changes: 275 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
# https://circleci.com/docs/2.1/language-javascript/
version: 2.1
commands:
extract-changelog-version:
steps:
- run:
name: extract changelog version
working_directory: ~/gulp-minify-inline-json
command: |
VERSION=$(head -n1 CHANGELOG.md | grep -o '\([0-9]\+\.\)\{2\}[0-9]\+')
echo "export VERSION=${VERSION}" >> $BASH_ENV
echo "export CHANGELOG_VERSION=${VERSION}" >> $BASH_ENV
echo "changelog version: ${VERSION}"
extract-package-json-version:
steps:
- run:
name: extract package.json version
working_directory: ~/gulp-minify-inline-json
command: |
PACKAGE_JSON_VERSION=$(node -e "console.info(require('./package').version)")
echo "export PACKAGE_JSON_VERSION=${PACKAGE_JSON_VERSION}" >> $BASH_ENV
echo "package.json version: ${PACKAGE_JSON_VERSION}"
extract-published-version:
steps:
- run:
name: extract latest published version
working_directory: ~/gulp-minify-inline-json
command: |
LIVE_VERSION=$(npm show gulp-minify-inline-json version || true)
[ -z "${LIVE_VERSION}" ] && LIVE_VERSION='0.0.0'
echo "export LIVE_VERSION=${LIVE_VERSION}" >> ${BASH_ENV}
echo "latest published version: ${LIVE_VERSION}"
extract-versions:
steps:
- extract-changelog-version
- extract-package-json-version
- extract-published-version

init:
steps:
- run:
name: update npm
command: sudo npm install -g npm@latest

prepare-repo:
steps:
- checkout
- restore_cache:
keys: gulp-minify-inline-json-dependencies-{{ checksum "package-lock.json" }}
- run:
name: install dependencies
command: npm i
- save_cache:
paths:
- node_modules
key: gulp-minify-inline-json-dependencies-{{ checksum "package-lock.json" }}
- extract-versions

create-test-project:
parameters:
project_name:
description: project name
type: string
default: test-app
steps:
- run:
working-directory: /tmp
name: create test application
command: |
mkdir /tmp/<< parameters.project_name >>
cd /tmp/<< parameters.project_name >> && npm init -y && echo "Created package.json" && cat package.json
package-information:
steps:
- run:
name: install tree
command: sudo apt-get -y install tree
- run:
name: gather bundle information
command: |
npm info gulp-minify-inline-json@${VERSION} > ./bundle.info
tree -s node_modules/gulp-minify-inline-json >> ./bundle.info
- store_artifacts:
path: bundle.info

workflows:
version: 2
default:
when: always
jobs:
- lint
- test
- bundle:
requires:
- lint
- test
- bundle-test:
requires:
- bundle
- ensure-versioned-correctly:
requires:
- bundle
- publish:
requires:
- ensure-versioned-correctly
- bundle-test
filters:
branches:
only: master
- package-test:
requires:
- publish
- publish-github-release:
requires:
- package-test

jobs:
lint:
docker:
- image: circleci/node:lts
working_directory: ~/gulp-minify-inline-json
steps:
- init
- prepare-repo
- run:
name: create test-results-folder
command: mkdir -p test-results/eslint
- run:
name: lint
command: npm run lint:ci
- store_test_results:
path: test-results

test:
docker:
- image: circleci/node:lts
working_directory: ~/gulp-minify-inline-json
steps:
- init
- prepare-repo
- run:
name: unit tests
command: npm run test:ci
- store_test_results:
path: test-results

bundle:
docker:
- image: circleci/node:lts
working_directory: ~/gulp-minify-inline-json
steps:
- init
- prepare-repo
- extract-versions
- run:
name: pack
environment:
NODE_ENV: 'production'
command: |
npm pack
mv gulp-minify-inline-json-${VERSION}.tgz gulp-minify-inline-json.tgz
- store_artifacts:
path: gulp-minify-inline-json.tgz
- persist_to_workspace:
root: ./
paths:
- CHANGELOG.md
- lib
- README.md
- LICENSE
- package.json
- package-lock.json
- .npmignore
- gulp-minify-inline-json.tgz

bundle-test:
docker:
- image: circleci/node:lts
steps:
- init
- attach_workspace:
at: ~/gulp-minify-inline-json
- extract-versions
- create-test-project
- run:
name: install module
working_directory: /tmp/test-app
command: |
npm i -S ~/gulp-minify-inline-json/gulp-minify-inline-json.tgz
- run:
name: test module exports function
working_directory: /tmp/test-app
command: |
node -e "const gulpMinifyInlineJson = require('gulp-minify-inline-json'); const assert = require('assert').strict; assert.deepEqual(typeof gulpMinifyInlineJson, 'function');"
ensure-versioned-correctly:
docker:
- image: circleci/node:lts
working_directory: ~/gulp-minify-inline-json
steps:
- init
- attach_workspace:
at: ~/gulp-minify-inline-json
- extract-versions
- run:
name: changelog matches package.json
command: |
test ${PACKAGE_JSON_VERSION} = ${CHANGELOG_VERSION}
- run:
name: pacakge.json greater than live
command: |
node \<<VERSION_CHECK
const pkgVersion = require('./package').version
.split('.')
.map((i) => parseInt(i, 10));
const liveVersion = process.env.LIVE_VERSION
.split('.')
.map((i) => parseInt(i, 10));
const isGreater = pkgVersion.reduce((isGreater, part, i) => {
return isGreater || (part > liveVersion[i]);
}, false);
if (!isGreater) {
process.exit(1);
}
VERSION_CHECK
publish:
docker:
- image: circleci/node:lts
working_directory: ~/gulp-minify-inline-json
steps:
- init
- attach_workspace:
at: ~/gulp-minify-inline-json
- run:
name: setup npm registry token
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- run:
name: publish node module
command: npm publish --access public

package-test:
docker:
- image: circleci/node:lts
steps:
- init
- create-test-project
- run:
name: install module
working_directory: /tmp/test-app
command: |
npm i -S gulp-minify-inline-json
- run:
name: test module exports function
working_directory: /tmp/test-app
command: |
node -e "const gulpMinifyInlineJson = require('gulp-minify-inline-json'); const assert = require('assert').strict; assert.deepEqual(typeof gulpMinifyInlineJson, 'function');"
- package-information

publish-github-release:
docker:
- image: cibuilds/github
steps:
- attach_workspace:
at: ~/gulp-minify-inline-json
- extract-changelog-version
- run:
name: publish github release
working_directory: ~/gulp-minify-inline-json
command: |
cp ./gulp-minify-inline-json.tgz ./gulp-minify-inline-json-${VERSION}.tgz
CHANGES=$(awk "/## ${VERSION}/,/^$/" CHANGELOG.md)
echo "Publishing release v${VERSION} to Github.\nChanges:"
echo $CHANGES
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete -n "v${VERSION}" -b "${CHANGES}" "v${VERSION}" ./gulp-minify-inline-json-${VERSION}.tgz
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.*
*.md
*.config.js
test/
CHANGELOG.md
test-results/
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.4.0
* [#22: Migrate to CircleCI.](https://github.com/haensl/gulp-minify-inline-json/issues/22)

## 1.3.5
* [#19: Update dependencies.](https://github.com/haensl/gulp-minify-inline-json/issues/19)
* Internalize eslint configuration into `package.json`.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![NPM](https://nodei.co/npm/gulp-minify-inline-json.png?downloads=true)](https://nodei.co/npm/gulp-minify-inline-json/)

[![npm version](https://badge.fury.io/js/gulp-minify-inline-json.svg)](http://badge.fury.io/js/gulp-minify-inline-json)
[![Build Status](https://travis-ci.org/haensl/gulp-minify-inline-json.svg?branch=master)](https://travis-ci.org/haensl/gulp-minify-inline-json)
[![CircleCI](https://circleci.com/gh/haensl/gulp-minify-inline-json.svg?style=svg)](https://circleci.com/gh/haensl/gulp-minify-inline-json)

Minifies inline `<script>` tags containing JSON data, i.e. `application/json` and `application/ld+json`.

Expand Down
Loading

0 comments on commit 7c8f428

Please sign in to comment.