From 8c539d4cb1ae5a61a8daebd720cbc8e1e373e49d Mon Sep 17 00:00:00 2001 From: Armano Date: Tue, 22 Aug 2023 20:02:52 +0200 Subject: [PATCH] fix: add github CI pipeline --- .github/workflows/ci.yml | 42 +++++++++++++++++++++ .github/workflows/release.yml | 41 ++++++++++++++++++++ .gitignore | 2 + .travis.yml | 26 ------------- .zuul.yml | 18 --------- Makefile | 70 ----------------------------------- README.md | 4 +- index.js | 36 +++++++++--------- package.json | 15 ++++---- test/index.js | 44 +++++++++++----------- 10 files changed, 134 insertions(+), 164 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml delete mode 100644 .zuul.yml delete mode 100644 Makefile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c9d3802 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - '**' + +jobs: + build: + name: Build + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [14.x, 16.x, 18.x] + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Lint code + run: npm run lint + + - name: Test code + run: npm run test + + - name: Test dts + run: npm run test:dts + + - name: Build + run: npm run build + + - name: Test code + run: npm run test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..77976bd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,41 @@ +name: Release +on: workflow_dispatch +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.x + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Lint code + run: npm run lint + + - name: Test code + run: npm run test + + - name: Build + run: npm run build + + - name: Test code + run: npm run test + + - name: Test dts + run: npm run test:dts + + - name: Semantic Release + uses: cycjimmy/semantic-release-action@v2 + with: + branches: | + [ + 'master' + ] + env: + NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 0972d12..9521a87 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules coverage package-lock.json +.idea +.vscode diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f13e349..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -sudo: false -language: node_js -node_js: -- stable -- 10 -- 9 -- 8 -before_install: -- npm install -g npm -env: - global: - - secure: he3kGOmSy6s97OdYRUq+k13w2WfIxzKfuDVysMfjOEV1U7YCq6tVeA6rm37yuyyaN3776he/fvPcK1Jd+FNfm8hzJMEu6QHqSd+Ri+q/32P+aXcEq2MEPMdsDAUpFqjT2p7BDPqH4a8DcJ0p48iXP+H2K3+HBaXNrneNLnU+6I8= - - secure: HHxNmsHXJ3p9MBDXHmlSUYWaNX4KEq+VVpK4tlK1g67mGwPdlG9eFB4QFPTitYhqSTexCWSc9QwvPWVTWXzWemvwu6wBATxvKED8CKjTIlO2mOpwigV5KT7op7LU3f8WXvU+n5wV0ftHKU1nuDUu0ZgZEU4V9cAy9hMxNRmwpk8= - - secure: jvL8J6LnjpPwrrGqHu3bUAxdZByq9pMITkhRrxCbYMFcQQRFynqEdbY/c1dldei03HKx4sA76UtlbGPe78wWepSE2zBPuq8XpyRR2oCgmJsYfdNuv6op6Pmx20TJwBCXp1nlAOS+Fm3JLv72N3LZS63YhB1aRi+XEmhm7SbQ3gk= - matrix: - - TEST=node - - TEST=browser -script: make travis -matrix: - exclude: - - node_js: 8 - env: TEST=browser - - node_js: 9 - env: TEST=browser - - node_js: 10 - env: TEST=browser diff --git a/.zuul.yml b/.zuul.yml deleted file mode 100644 index 4030f0e..0000000 --- a/.zuul.yml +++ /dev/null @@ -1,18 +0,0 @@ -ui: tape -browserify: - - transform: brfs -browsers: - - name: chrome - version: latest - - name: firefox - version: latest - - name: ie - version: 9..latest - - name: iphone - version: latest - - name: safari - version: latest - - name: android - version: latest - - name: microsoftedge - version: latest diff --git a/Makefile b/Makefile deleted file mode 100644 index b494deb..0000000 --- a/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -MAKEFLAGS += --warn-undefined-variables -PATH := node_modules/.bin:$(PATH) -SHELL := /bin/bash - -.SHELLFLAGS := -eu -o pipefail -c -.DEFAULT_GOAL := all -.DELETE_ON_ERROR: -.SUFFIXES: - -TEST ?= node -version ?= patch - -node_modules: package.json - @npm prune - @npm install - @touch node_modules - -.PHONY: clean -clean: - @$(RM) -fr node_modules - @$(RM) -fr npm-debug.log - @$(RM) -fr coverage - -.PHONY: fmt -fmt: node_modules - @standard --fix - -.PHONY: lint -lint: node_modules - @standard - -.PHONY: test -test: lint - @if [ "$(TEST)" = "browser" ]; \ - then make test-browser; \ - else make test-node; \ - fi - -.PHONY: test-node -test-node: node_modules - tape test/index.js - -.PHONY: test-browser -test-browser: node_modules -ifeq ($(TRAVIS_PULL_REQUEST),true) - zuul -- test/index.js -endif - -.PHONY: zuul -zuul: node_modules - zuul --local 8080 --ui tape -- test/index.js - -.PHONY: release -release: test - npm version $(version) - git push && git push --tags - npm publish - -.PHONY: coverage -coverage: node_modules index.js test/index.js node_modules - @istanbul cover --report html --print detail ./test/index.js - @touch coverage - -.PHONY: coveralls -coveralls: node_modules coverage - @istanbul report lcov - (cat coverage/lcov.info | coveralls) || exit 0 - -.PHONY: travis -travis: test coveralls diff --git a/README.md b/README.md index e38e510..1b5283d 100644 --- a/README.md +++ b/README.md @@ -152,8 +152,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI [jekyll]: https://github.com/mojombo/jekyll [coverage-img]: https://img.shields.io/coveralls/jxson/front-matter.svg [coverage-url]: https://coveralls.io/r/jxson/front-matter?branch=master -[build-img]: https://img.shields.io/travis/jxson/front-matter/master.svg -[build-url]: http://travis-ci.org/jxson/front-matter +[build-img]: https://github.com/jxson/front-matter/workflows/CI/badge.svg +[build-url]: https://github.com/jxson/front-matter/actions/workflows/ci.yml?query=branch%3Amaster [npm-img]: https://img.shields.io/npm/dm/front-matter.svg [npm-url]: https://npmjs.org/package/front-matter [github-img]: https://img.shields.io/github/stars/jxson/front-matter.svg?style=social&label=Star diff --git a/index.js b/index.js index d518f1d..b41ede0 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ -var parser = require('js-yaml') -var optionalByteOrderMark = '\\ufeff?' -var platform = typeof process !== 'undefined' ? process.platform : '' -var pattern = '^(' + +const parser = require('js-yaml') +const optionalByteOrderMark = '\\ufeff?' +const platform = typeof process !== 'undefined' ? process.platform : '' +const pattern = '^(' + optionalByteOrderMark + '(= yaml =|---)' + '$([\\s\\S]*?)' + @@ -11,17 +11,17 @@ var pattern = '^(' + '(?:\\n)?)' // NOTE: If this pattern uses the 'g' flag the `regex` variable definition will // need to be moved down into the functions that use it. -var regex = new RegExp(pattern, 'm') +const regex = new RegExp(pattern, 'm') module.exports = extractor module.exports.test = test function extractor (string, options) { string = string || '' - var defaultOptions = { allowUnsafe: false } + const defaultOptions = { allowUnsafe: false } options = options instanceof Object ? { ...defaultOptions, ...options } : defaultOptions options.allowUnsafe = Boolean(options.allowUnsafe) - var lines = string.split(/(\r?\n)/) + const lines = string.split(/(\r?\n)/) if (lines[0] && /= yaml =|---/.test(lines[0])) { return parse(string, options.allowUnsafe) } else { @@ -34,9 +34,9 @@ function extractor (string, options) { } function computeLocation (match, body) { - var line = 1 - var pos = body.indexOf('\n') - var offset = match.index + match[0].length + let line = 1 + let pos = body.indexOf('\n') + const offset = match.index + match[0].length while (pos !== -1) { if (pos >= offset) { @@ -50,7 +50,7 @@ function computeLocation (match, body) { } function parse (string, allowUnsafe) { - var match = regex.exec(string) + const match = regex.exec(string) if (!match) { return { attributes: {}, @@ -59,15 +59,15 @@ function parse (string, allowUnsafe) { } } - var loader = allowUnsafe ? parser.load : parser.safeLoad - var yaml = match[match.length - 1].replace(/^\s+|\s+$/g, '') - var attributes = loader(yaml) || {} - var body = string.replace(match[0], '') - var line = computeLocation(match, string) + const loader = allowUnsafe ? parser.load : parser.safeLoad + const yaml = match[match.length - 1].replace(/^\s+|\s+$/g, '') + const attributes = loader(yaml) || {} + const body = string.replace(match[0], '') + const line = computeLocation(match, string) return { - attributes: attributes, - body: body, + attributes, + body, bodyBegin: line, frontmatter: yaml } diff --git a/package.json b/package.json index b881e7a..2e9ccee 100644 --- a/package.json +++ b/package.json @@ -17,19 +17,18 @@ }, "main": "index.js", "scripts": { - "test": "make test && check-dts" + "lint": "standard", + "lint-fix": "standard --fix", + "test": "tape test/*.js", + "test:dts": "check-dts" }, "dependencies": { "js-yaml": "^3.13.1" }, "devDependencies": { - "brfs": "^2.0.2", - "check-dts": "^0.3.0", - "coveralls": "^3.0.9", - "istanbul": "^0.4.5", - "standard": "^14.3.4", - "tape": "^4.4.0", - "zuul": "^3.12.0" + "check-dts": "^0.7.2", + "standard": "^17.1.0", + "tape": "^5.6.6" }, "files": [ "index.d.ts" diff --git a/test/index.js b/test/index.js index d880f44..3e4e2f3 100644 --- a/test/index.js +++ b/test/index.js @@ -1,7 +1,7 @@ -var fm = require('../') -var fs = require('fs') -var path = require('path') -var test = require('tape') +const fm = require('../') +const fs = require('fs') +const path = require('path') +const test = require('tape') test('var fm = require("front-matter")', function (t) { t.equal(typeof fm, 'function') @@ -15,7 +15,7 @@ test('fm(string) - parse yaml delinetead by `---`', function (t) { function (err, data) { t.error(err, 'read(...) should not error') - var content = fm(data) + const content = fm(data) t.ok(content.attributes, 'should have `attributes` key') t.equal(content.attributes.title, 'Three dashes marks the spot') @@ -44,9 +44,9 @@ test('fm(string) - parse yaml delinetead by `= yaml =`', function (t) { function (err, data) { t.error(err, 'read(...) should not error') - var content = fm(data) - var meta = content.attributes - var body = content.body + const content = fm(data) + const meta = content.attributes + const body = content.body t.equal(meta.title, "I couldn't think of a better name") t.equal(meta.description, 'Just an example of using `= yaml =`') @@ -64,9 +64,9 @@ test('fm(string) - parse yaml ended by `...`', function (t) { function (err, data) { t.error(err, 'read(...) should not error') - var content = fm(data) - var meta = content.attributes - var body = content.body + const content = fm(data) + const meta = content.attributes + const body = content.body t.equal(meta.title, 'Example with dots document ending') t.equal(meta.description, 'Just an example of using `...`') @@ -78,7 +78,7 @@ test('fm(string) - parse yaml ended by `...`', function (t) { }) test('fm(string) - string missing front-matter', function (t) { - var content = fm('No front matter here') + const content = fm('No front matter here') t.equal(content.body, 'No front matter here') t.end() @@ -91,7 +91,7 @@ test('fm(string) - string missing body', function (t) { function (err, data) { t.error(err, 'read(...) should not error') - var content = fm(data) + const content = fm(data) t.equal(content.attributes.title, 'Three dashes marks the spot') t.equal(content.attributes.tags.length, 3) @@ -121,8 +121,8 @@ test('fm(string) - wrapped test in yaml', function (t) { function (err, data) { t.error(err, 'read(...) should not error') - var content = fm(data) - var folded = [ + const content = fm(data) + const folded = [ 'There once was a man from Darjeeling', 'Who got on a bus bound for Ealing', ' It said on the door', @@ -145,7 +145,7 @@ test('fm(string) - strings with byte order mark', function (t) { function (err, data) { t.error(err, 'read(...) should not error') - var content = fm(data) + const content = fm(data) t.equal(content.attributes.title, "Relax guy, I'm not hiding any BOMs") @@ -160,7 +160,7 @@ test('fm(string) - no front matter, markdown with hr', function (t) { function (err, data) { t.error(err, 'read should not error') - var content = fm(data) + const content = fm(data) t.equal(content.body, data) t.equal(content.bodyBegin, 1) t.end() @@ -173,7 +173,7 @@ test('fm(string, true) - complex and unsafe yaml', function (t) { 'utf8', function (err, data) { t.error(err, 'read(...) should not error') - var content = fm(data, { allowUnsafe: true }) + const content = fm(data, { allowUnsafe: true }) t.ok(content.attributes, 'should have `attributes` key') t.equal(content.attributes.title, 'This is a title!') t.equal(content.attributes.contact, null) @@ -210,9 +210,9 @@ test('fm.test(string) - no front-matter', function (t) { }) test('Supports live updating', function (t) { - var seperator = '---' - var string = '' - for (var i = 0; i < seperator.length; i++) { + const seperator = '---' + let string = '' + for (let i = 0; i < seperator.length; i++) { string += seperator[i] try { @@ -225,7 +225,7 @@ test('Supports live updating', function (t) { string += '\n' string += 'foo: bar' - var content = fm(string) + let content = fm(string) t.same(content, { attributes: {},