Skip to content
This repository has been archived by the owner on Jul 25, 2019. It is now read-only.

Commit

Permalink
chore: adds GitHub actions (#52)
Browse files Browse the repository at this point in the history
* chore: adds github actions
  • Loading branch information
ayusharma authored Apr 12, 2019
1 parent 6506641 commit f930acd
Show file tree
Hide file tree
Showing 7 changed files with 1,915 additions and 1,705 deletions.
50 changes: 0 additions & 50 deletions .circleci/config.yml

This file was deleted.

100 changes: 100 additions & 0 deletions .github/main.workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
workflow "build and test" {
resolves = [
"lint",
"coverage",
]
on = "push"
}

action "branch-filter" {
uses = "actions/bin/filter@master"
args = "branch"
}

action "install" {
needs = ["branch-filter"]
uses = "docker://node:10"
args = "yarn install --frozen-lockfile"
}

action "build" {
uses = "docker://node:10"
needs = ["install"]
args = "yarn run build"
}

action "lint" {
uses = "docker://node:10"
needs = ["install"]
args = "yarn run lint"
}

action "test" {
uses = "docker://node:10"
needs = ["build"]
args = "yarn run test"
}

action "coverage" {
uses = "docker://node:10"
needs = ["test"]
args = "yarn run coverage"
}

workflow "release" {
resolves = [
"github-release",
"release:lint",
]
on = "push"
}

action "release:tag-filter" {
uses = "actions/bin/filter@master"
args = "tag v*"
}

action "release:install" {
uses = "docker://node:10"
needs = ["release:tag-filter"]
args = "yarn install --frozen-lockfile"
}

action "release:build" {
uses = "docker://node:10"
needs = ["release:install"]
args = "yarn run build"
}

action "release:lint" {
uses = "docker://node:10"
needs = ["release:install"]
args = "yarn run lint"
}

action "release:test" {
uses = "docker://node:10"
needs = ["release:build"]
args = "yarn run test"
}

action "release:publish" {
needs = ["release:test"]
uses = "docker://node:10"
args = "sh scripts/publish.sh"
secrets = [
"REGISTRY_AUTH_TOKEN",
]
env = {
REGISTRY_URL = "registry.npmjs.org"
}
}

action "github-release" {
needs = ["release:publish"]
uses = "docker://node:10"
args = "sh scripts/github-release.sh"
secrets = [
"GITHUB_TOKEN",
]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"devDependencies": {
"@commitlint/cli": "7.5.2",
"@commitlint/config-conventional": "7.5.0",
"@octokit/rest": "16.23.2",
"@types/bcryptjs": "2.4.2",
"@types/http-errors": "1.6.1",
"@types/jest": "24.0.11",
Expand All @@ -51,6 +52,7 @@
"eslint-config-prettier": "4.1.0",
"eslint-plugin-jest": "22.4.1",
"eslint-plugin-prettier": "3.0.1",
"get-stdin": "6.0.0",
"husky": "0.14.3",
"in-publish": "2.0.0",
"jest": "24.5.0",
Expand Down
8 changes: 8 additions & 0 deletions scripts/github-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Get the last tag from GitHub
lastTag=$(git describe --tags $(git rev-list --tags --max-count=1))

changelog=$(git show $GITHUB_SHA --unified=0 CHANGELOG.md | tail +12 | sed -e 's/^\+//')

echo "$changelog"

echo "$changelog" | node scripts/trigger-release.js $lastTag
13 changes: 13 additions & 0 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Get the last tag from GitHub
lastTag=$(git describe --tags $(git rev-list --tags --max-count=1))

# Print it to the console for verification
echo "Bumping version to new tag: ${lastTag}"

# creating .npmrc
echo "//$REGISTRY_URL/:_authToken=$REGISTRY_AUTH_TOKEN" > .npmrc

# Publish to NPM
npm publish --registry https://$REGISTRY_URL/
27 changes: 27 additions & 0 deletions scripts/trigger-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const [, , /* node */ /* file */ tag] = process.argv;

const getStdin = require('get-stdin');
const Octokit = require('@octokit/rest');
const octokit = new Octokit({
auth: `token ${process.env.GITHUB_TOKEN}`
});

const [repoOwner, repoName] = process.env.GITHUB_REPOSITORY.split('/');

getStdin()
.then(changelog =>
octokit.repos.createRelease({
owner: repoOwner,
repo: repoName,
tag_name: tag,
body: changelog,
draft: true
})
)
.catch(err => {
// eslint-disable-next-line no-console
console.error(err);
process.exit(1);
});
Loading

0 comments on commit f930acd

Please sign in to comment.