Skip to content

Commit

Permalink
馃懛 Release using GitHub Actions (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Apr 27, 2020
1 parent 532d2a8 commit c9a1041
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 13 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Release

on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v2.1.3

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
# libgbm-dev is required by Puppeteer 3+
- name: Install system dependencies
run: |
sudo apt-get install -y libgbm-dev
- name: Install dependencies
run: |
npm ci
npm ci --prefix packages/core
- name: Lint, build and test
env:
ASCIIDOCTOR_CORE_VERSION: v2.0.10
run: |
npm run lint
npm run test
npm run travis --prefix packages/core
publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
# libgbm-dev is required by Puppeteer 3+
- name: Install system dependencies
run: |
sudo apt-get install -y libgbm-dev
# install dependencies
- name: Install dependencies
run: |
npm ci
npm ci --prefix packages/core
# package and publish
- name: Package and publish
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
./scripts/package.sh
./scripts/publish.sh
./scripts/binaries.sh
# create the GitHub release
- name: Create release
id: create_release
uses: actions/create-release@v1.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
# upload assets
- name: Upload source code as a zip file
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: packages/core/bin/asciidoctor.js.dist.zip
asset_name: asciidoctor.js.dist.zip
asset_content_type: application/zip
- name: Upload source code as a tar.gz file
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: packages/core/bin/asciidoctor.js.dist.tar.gz
asset_name: asciidoctor.js.dist.tar.gz
asset_content_type: application/tar+gzip
12 changes: 12 additions & 0 deletions scripts/binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# Produce macOS, Linux and Windows binaries from asciidoctor/cli

SCRIPT=`realpath $0`
SCRIPT_PATH=`dirname ${SCRIPT}`

cd "$SCRIPT_PATH"
cd ../packages/asciidoctor

# @asciidoctor/core must be published to npmjs before we can install the dependencies
npm i --prefix packages/asciidoctor
npm run dist
10 changes: 4 additions & 6 deletions scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

set -e

SCRIPT=`realpath $0`
SCRIPT_PATH=`dirname ${SCRIPT}`

# Package asciidoctor/core distribution as a zip and tar.gz archive
cd "$(dirname "$0")"
cd "$SCRIPT_PATH"
cd ../packages/core
npm run dist
mkdir bin
cd dist/
zip -r ../bin/asciidoctor.js.dist.zip .
tar -zcvf ../bin/asciidoctor.js.dist.tar.gz .

# Produce macOS, Linux and Windows binaries from asciidoctor/cli
cd "$(dirname "$0")"
cd ../packages/asciidoctor
npm run dist
4 changes: 3 additions & 1 deletion scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

set -e

cd "$(dirname "$0")"
SCRIPT=`realpath $0`
SCRIPT_PATH=`dirname ${SCRIPT}`

cd "$(dirname "$0")"
cd ..
node tasks/publish.js
8 changes: 2 additions & 6 deletions tasks/publish.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
'use strict'
const path = require('path')
const fs = require('fs')
const childProcess = require('child_process')
const { publish: npmPublish } = require('libnpmpublish')
const log = require('bestikk-log')

const publish = async (directory) => {
const pkgName = childProcess.execSync(`npm pack`, { cwd: directory }).toString('utf-8').trim()
const pkg = require(path.join(directory, 'package.json'))
const pkgPath = path.join(directory, pkgName)
const tarball = fs.createReadStream(pkgPath)
if (process.env.DRY_RUN) {
log.debug(`${pkg.name}@${pkg.version} - ${pkgPath}`)
console.log(`${pkg.name}@${pkg.version}`)
} else {
return npmPublish(pkg, tarball, { token: process.env.NPM_AUTH_TOKEN })
return npmPublish(directory, pkg, { token: process.env.NPM_AUTH_TOKEN, access: 'public' })
}
}

Expand Down

0 comments on commit c9a1041

Please sign in to comment.