Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pack built standalone binaries #90

Merged
merged 6 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 23 additions & 37 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ references:
cmd:
- /bin/sh

on-tagged-version: &on-tagged-version
filters:
branches:
ignore: /.*/
tags:
only: /^v.*/

base: &base
docker:
- image: circleci/node:10.15.3-browsers
Expand All @@ -40,7 +33,7 @@ references:

- run:
name: Prettier formatting
command: yarn format:check
command: yarn check:format

- run:
name: TypeScript type checking
Expand Down Expand Up @@ -98,45 +91,38 @@ jobs:
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker push marpteam/marp-cli:latest

standalone-build:
release:
<<: *base
steps:
- checkout

- run:
name: Create release on GitHub
command: curl https://raw.githubusercontent.com/marp-team/marp/master/github-release.js | node

- restore_cache:
keys:
- dependencies-{{ .Environment.CI_CACHE_KEY }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "yarn.lock" }}-{{ .Branch }}
- dependencies-{{ .Environment.CI_CACHE_KEY }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "yarn.lock" }}-
- dependencies-{{ .Environment.CI_CACHE_KEY }}-{{ .Environment.CIRCLE_JOB }}-

- run: yarn install
- run: yarn build:standalone

- persist_to_workspace:
root: ./bin
paths:
- '*'

- store_artifacts:
path: ./bin
destination: bin
- run:
name: Build and create standalone binaries
command: yarn build:standalone

github-release:
<<: *base
steps:
- checkout
- run:
name: Create packages
command: yarn standalone:pack

- attach_workspace:
at: ./bin
- store_artifacts:
path: ./dist
destination: dist

- run:
name: Create release and upload binaries on GitHub
command: |
RELEASE_ID=$(curl -sS https://raw.githubusercontent.com/marp-team/marp/master/github-release.js | node) && \
ENDPOINT="https://uploads.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/releases/${RELEASE_ID}/assets" && \
curl -sS --data-binary @"bin/marp-cli-linux" -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${GITHUB_TOKEN}" -H "Content-Type: application/octet-stream" ${ENDPOINT}?name=marp-${CIRCLE_TAG}-linux && \
curl -sS --data-binary @"bin/marp-cli-macos" -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${GITHUB_TOKEN}" -H "Content-Type: application/octet-stream" ${ENDPOINT}?name=marp-${CIRCLE_TAG}-mac && \
curl -sS --data-binary @"bin/marp-cli-win.exe" -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${GITHUB_TOKEN}" -H "Content-Type: application/octet-stream" ${ENDPOINT}?name=marp-${CIRCLE_TAG}-win.exe
name: Upload created packages to the asset of GitHub release
command: yarn standalone:pack:upload

workflows:
version: 2
Expand All @@ -151,10 +137,10 @@ workflows:
filters:
branches:
only: master
- standalone-build:
<<: *on-tagged-version
- github-release:
<<: *on-tagged-version
- release:
context: github-release
requires:
- standalone-build
filters:
branches:
ignore: /.*/
tags:
only: /^v.*/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Change

- Pack built standalone binaries ([#90](https://github.com/marp-team/marp-cli/pull/90))

## v0.9.0 - 2019-05-07

### Added
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,25 @@
"build": "yarn -s clean && rollup -c",
"build:standalone": "run-s build standalone",
"check:audit": "yarn audit",
"check:format": "yarn -s format -c",
"check:ts": "tsc --noEmit",
"clean": "rimraf lib",
"format": "prettier \"**/*.{css,js,json,md,scss,ts,yaml,yml}\"",
"format:check": "yarn -s format -c",
"format:write": "yarn -s format --write",
"lint:ts": "tslint \"{src,test}/**/*.ts\"",
"lint:css": "stylelint \"src/**/*.{css,scss}\"",
"prepack": "npm-run-all --parallel check:* format:check lint:* test:coverage --sequential build",
"prepack": "npm-run-all --parallel check:* lint:* test:coverage --sequential build",
"preversion": "run-p check:* format:check lint:* test:coverage",
"standalone": "rimraf bin && pkg --out-path ./bin .",
"standalone:pack": "node ./scripts/pack.js",
"standalone:pack:upload": "node ./scripts/upload.js",
"test": "jest",
"test:coverage": "jest --coverage",
"version": "node version.js && git add -A CHANGELOG.md",
"version": "curl https://raw.githubusercontent.com/marp-team/marp/master/version.js | node && git add -A CHANGELOG.md",
"watch": "rollup -w -c"
},
"devDependencies": {
"@octokit/rest": "^16.25.3",
"@types/cheerio": "^0.22.11",
"@types/cosmiconfig": "^5.0.3",
"@types/express": "^4.16.1",
Expand Down Expand Up @@ -92,13 +95,15 @@
"stylelint-config-standard": "^18.3.0",
"stylelint-scss": "^3.6.1",
"supertest": "^4.0.2",
"tar-stream": "^2.0.1",
"ts-jest": "24.0.2",
"ts-keycode-enum": "^1.0.6",
"tslib": "^1.9.3",
"tslint": "^5.16.0",
"tslint-config-airbnb": "^5.11.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.4.5"
"typescript": "^3.4.5",
"zip-stream": "^2.0.1"
},
"dependencies": {
"@marp-team/marp-core": "^0.9.0",
Expand Down
56 changes: 56 additions & 0 deletions scripts/pack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Pack built standalone binaries for release. */

const fs = require('fs')
const path = require('path')
const rimraf = require('rimraf')
const tar = require('tar-stream')
const ZipStream = require('zip-stream')
const zlib = require('zlib')
const { version } = require('../package.json')

const bin = path.resolve(__dirname, '../bin')
const binaryName = 'marp'
const dist = path.resolve(__dirname, '../dist')
const prefix = `marp-cli-v${version}`

const packToTarGz = binary => {
const pack = tar.pack()

pack.entry({ name: binaryName, mode: 0755 }, binary)
pack.finalize()

return pack.pipe(zlib.createGzip())
}

// Clean up dist directory
rimraf.sync(dist)
fs.mkdirSync(dist)

// Create package for Linux (.tar.gz)
fs.readFile(path.resolve(bin, 'marp-cli-linux'), (err, buffer) => {
if (err) throw err

packToTarGz(buffer).pipe(
fs.createWriteStream(path.resolve(dist, `${prefix}-linux.tar.gz`))
)
})

// Create package for macOS (.tar.gz)
fs.readFile(path.resolve(bin, 'marp-cli-macos'), (err, buffer) => {
if (err) throw err

packToTarGz(buffer).pipe(
fs.createWriteStream(path.resolve(dist, `${prefix}-mac.tar.gz`))
)
})

// Create package for Windows (.zip)
fs.readFile(path.resolve(bin, 'marp-cli-win.exe'), (err, buffer) => {
if (err) throw err

const pack = new ZipStream()

pack.entry(buffer, { name: `${binaryName}.exe` })
pack.finalize()
pack.pipe(fs.createWriteStream(path.resolve(dist, `${prefix}-win.zip`)))
})
45 changes: 45 additions & 0 deletions scripts/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Upload packed binaries to GitHub Release. */

const Octokit = require('@octokit/rest')
const fs = require('fs')
const path = require('path')
const { promisify } = require('util')
const { version } = require('../package.json')

const dist = path.resolve(__dirname, '../dist')
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
})

const repo = { owner: 'marp-team', repo: 'marp-cli' }
const tag = `v${version}`

;(async () => {
// Get release from version tag
const { data } = await octokit.repos.getReleaseByTag({ ...repo, tag })

// Upload assets
for (const fn of await promisify(fs.readdir)(dist)) {
const file = path.resolve(dist, fn)
const stat = await promisify(fs.stat)(file)

if (stat.isFile) {
console.info(`Uploading ${fn} to ${tag} release...`)

await octokit.repos.uploadReleaseAsset({
file: fs.createReadStream(file),
headers: {
'content-type': (() => {
if (fn.endsWith('.tar.gz')) return 'application/gzip'
if (fn.endsWith('.zip')) return 'application/zip'

return 'application/octet-stream'
})(),
'content-length': stat.size,
},
name: fn,
url: data.upload_url,
})
}
}
})()
14 changes: 0 additions & 14 deletions version.js

This file was deleted.

Loading