Skip to content

Commit

Permalink
build: add automate release (#10)
Browse files Browse the repository at this point in the history
build: add automate release
  • Loading branch information
Kikobeats authored Jun 21, 2019
2 parents de1e8d6 + a9ed0ae commit 4d08cc5
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ coverage
############################
# Other
############################
.envrc
30 changes: 27 additions & 3 deletions .travis.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
language: node_js

node_js:
- "node"
- "lts/*"
after_success: npm run coveralls
- lts/*
- node

after_success: npm run coverage

stages:
- Test
- name: Release
if: branch = master AND commit_message !~ /(release|no-release)/

jobs:
include:
- stage: Release
node_js: lts/*
install: npm install --no-package-lock
before_deploy:
- git config user.email ${GITHUB_EMAIL:-"travis@travis-ci.org"}
- git config user.name ${GITHUB_USER:-"Travis CI"}
- git remote set-url origin https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
- git checkout master
deploy:
skip_cleanup: true
provider: script
script: npm run release
on:
branch: master
58 changes: 42 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,71 @@
"p-any": "~2.1.0"
},
"devDependencies": {
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
"ava": "latest",
"ci-publish": "latest",
"conventional-github-releaser": "latest",
"coveralls": "latest",
"finepack": "latest",
"git-authors-cli": "latest",
"git-dirty": "latest",
"husky": "latest",
"lint-staged": "latest",
"npm-check-updates": "latest",
"nyc": "latest",
"prettier-standard": "latest",
"standard": "latest",
"standard-markdown": "latest"
},
"engines": {
"node": ">= 6"
"node": ">=8"
},
"files": [
"index.js"
],
"scripts": {
"clean": "rm -rf node_modules",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"lint": "standard-markdown README.md && standard",
"postrelease": "npm run release:tags && npm run release:github && ci-publish --access=public",
"precommit": "lint-staged",
"prerelease": "npm run update:check",
"pretest": "npm run lint",
"pretty": "prettier-standard index.js {core,test,bin}/**/*.js --single-quote",
"test": "nyc ava"
"preversion": "git-authors-cli && git add package.json",
"release": "standard-version -a",
"release:github": "conventional-github-releaser -p angular",
"release:tags": "git push --follow-tags origin HEAD:master",
"test": "nyc ava",
"update": "ncu -a",
"update:check": "ncu -- --error-level 2"
},
"license": "MIT",
"lint-staged": {
"package.json": [
"finepack",
"git add"
],
"*.js": [
"prettier-standard",
"git add"
],
"*.md": [
"standard-markdown",
"git add"
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"linters": {
"package.json": [
"finepack",
"git add"
],
"*.js": [
"prettier-standard",
"git add"
],
"*.md": [
"standard-markdown",
"git add"
]
}
}
}
41 changes: 18 additions & 23 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,56 @@ const test = require('ava')

const reachableUrl = require('..')

test('resolve HEAD request', async t => {
const url = 'https://google.com'
const res = await reachableUrl(url)
const range = n => [...Array(n).keys()]

t.is(200, res.statusCode)
t.is('HEAD', res.req.method)
})

test('resolve GET request', async t => {
const url = 'https://httpbin-org.herokuapp.com/get'
const res = await reachableUrl(url)

t.is(200, res.statusCode)
t.is('GET', res.req.method)
test('resolve HEAD/GET request', async t => {
const url = 'https://httpbin.org/get'
const promises = range(10).map(() => reachableUrl(url))
const results = await Promise.all(promises)
const statusCodes = results.map(result => result.statusCode)
const methods = results.map(result => result.req.method)
t.true(statusCodes.every(value => value === 200))
t.true(methods.some(value => value === 'HEAD'))
t.true(methods.some(value => value === 'GET'))
})

test('resolve redirect', async t => {
const url = 'https://github.com/kikobeats/splashy'
const res = await reachableUrl(url)

t.deepEqual(res.redirectUrls, ['https://github.com/kikobeats/splashy'])
t.deepEqual(res.redirectStatusCodes, [301])
t.is('https://github.com/microlinkhq/splashy', res.url)
t.is(200, res.statusCode)
})

test('resolve multiple redirects', async t => {
const url = 'https://httpbin-org.herokuapp.com/redirect/3'
const url = 'https://httpbin.org/redirect/3'
const res = await reachableUrl(url)

t.deepEqual(res.redirectUrls, [
'https://httpbin-org.herokuapp.com/redirect/3',
'https://httpbin-org.herokuapp.com/relative-redirect/2',
'https://httpbin-org.herokuapp.com/relative-redirect/1'
'https://httpbin.org/redirect/3',
'https://httpbin.org/relative-redirect/2',
'https://httpbin.org/relative-redirect/1'
])
t.deepEqual(res.redirectStatusCodes, [302, 302, 302])
t.is('https://httpbin-org.herokuapp.com/get', res.url)
t.is('https://httpbin.org/get', res.url)
t.is(200, res.statusCode)
})

test('passing options', async t => {
const url =
'https://httpbin-org.herokuapp.com/redirect-to?url=http%3A%2F%2Fexample.com%2F'
const url = 'https://httpbin.org/redirect-to?url=http%3A%2F%2Fexample.com%2F'
const res = await reachableUrl(url, { followRedirect: false })
t.is(302, res.statusCode)
})

test('resolve non encoding urls', async t => {
const urlOne =
'https://www.metro.se/artikel/pr-experterna-s-försöker-ta-kommando-över-svenskhet-i-valfilm'
'https://www.metro.se/nyheter/pr-experterna:-s-forsoker-ta-kommando-over-"svenskhet"-i-valfilm-fZlCYGEtZA'
const resOne = await reachableUrl(urlOne)
t.is(resOne.url, new URL(resOne.url).href)
t.is(
resOne.url,
'https://www.metro.se/artikel/pr-experterna-s-f%C3%B6rs%C3%B6ker-ta-kommando-%C3%B6ver-svenskhet-i-valfilm'
'https://www.metro.se/nyheter/pr-experterna:-s-forsoker-ta-kommando-over-%22svenskhet%22-i-valfilm-fZlCYGEtZA'
)
t.is(200, resOne.statusCode)

Expand Down

0 comments on commit 4d08cc5

Please sign in to comment.