Skip to content

Commit 6a9aecc

Browse files
committed
👷 Release using GitHub Actions (#807)
1 parent 532d2a8 commit 6a9aecc

File tree

5 files changed

+107
-13
lines changed

5 files changed

+107
-13
lines changed

.github/workflows/release.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # Push events to matching v*, i.e. v1.0, v2.1.3
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v1
14+
with:
15+
node-version: 12
16+
# libgbm-dev is required by Puppeteer 3+
17+
- name: Install system dependencies
18+
run: |
19+
sudo apt-get install -y libgbm-dev
20+
- name: Install dependencies
21+
run: |
22+
npm ci
23+
npm ci --prefix packages/core
24+
- name: Lint, build and test
25+
env:
26+
ASCIIDOCTOR_CORE_VERSION: v2.0.10
27+
run: |
28+
npm run lint
29+
npm run test
30+
npm run travis --prefix packages/core
31+
publish:
32+
needs: build
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v2
36+
- uses: actions/setup-node@v1
37+
with:
38+
node-version: 12
39+
registry-url: https://registry.npmjs.org/
40+
# libgbm-dev is required by Puppeteer 3+
41+
- name: Install system dependencies
42+
run: |
43+
sudo apt-get install -y libgbm-dev
44+
# install dependencies
45+
- name: Install dependencies
46+
run: |
47+
npm ci
48+
npm ci --prefix packages/core
49+
# package and publish
50+
- name: Package and publish
51+
env:
52+
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
53+
run: |
54+
./scripts/package.sh
55+
./scripts/publish.sh
56+
./scripts/binaries.sh
57+
# create the GitHub release
58+
- name: Create release
59+
id: create_release
60+
uses: actions/create-release@v1.0.0
61+
env:
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
with:
64+
tag_name: ${{ github.ref }}
65+
release_name: ${{ github.ref }}
66+
draft: false
67+
prerelease: false
68+
# upload assets
69+
- name: Upload source code as a zip file
70+
uses: actions/upload-release-asset@v1.0.1
71+
env:
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
with:
74+
upload_url: ${{ steps.create_release.outputs.upload_url }}
75+
asset_path: packages/core/bin/asciidoctor.js.dist.zip
76+
asset_name: asciidoctor.js.dist.zip
77+
asset_content_type: application/zip
78+
- name: Upload source code as a tar.gz file
79+
uses: actions/upload-release-asset@v1.0.1
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
with:
83+
upload_url: ${{ steps.create_release.outputs.upload_url }}
84+
asset_path: packages/core/bin/asciidoctor.js.dist.tar.gz
85+
asset_name: asciidoctor.js.dist.tar.gz
86+
asset_content_type: application/tar+gzip

scripts/binaries.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# Produce macOS, Linux and Windows binaries from asciidoctor/cli
3+
4+
SCRIPT=`realpath $0`
5+
SCRIPT_PATH=`dirname ${SCRIPT}`
6+
7+
cd "$SCRIPT_PATH"
8+
cd ../packages/asciidoctor
9+
10+
# @asciidoctor/core must be published to npmjs before we can install the dependencies
11+
npm i --prefix packages/asciidoctor
12+
npm run dist

scripts/package.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
set -e
44

5+
SCRIPT=`realpath $0`
6+
SCRIPT_PATH=`dirname ${SCRIPT}`
7+
58
# Package asciidoctor/core distribution as a zip and tar.gz archive
6-
cd "$(dirname "$0")"
9+
cd "$SCRIPT_PATH"
710
cd ../packages/core
811
npm run dist
912
mkdir bin
1013
cd dist/
1114
zip -r ../bin/asciidoctor.js.dist.zip .
1215
tar -zcvf ../bin/asciidoctor.js.dist.tar.gz .
13-
14-
# Produce macOS, Linux and Windows binaries from asciidoctor/cli
15-
cd "$(dirname "$0")"
16-
cd ../packages/asciidoctor
17-
npm run dist

scripts/publish.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
set -e
55

6-
cd "$(dirname "$0")"
6+
SCRIPT=`realpath $0`
7+
SCRIPT_PATH=`dirname ${SCRIPT}`
78

9+
cd "$(dirname "$0")"
810
cd ..
911
node tasks/publish.js

tasks/publish.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
'use strict'
22
const path = require('path')
33
const fs = require('fs')
4-
const childProcess = require('child_process')
54
const { publish: npmPublish } = require('libnpmpublish')
65
const log = require('bestikk-log')
76

87
const publish = async (directory) => {
9-
const pkgName = childProcess.execSync(`npm pack`, { cwd: directory }).toString('utf-8').trim()
108
const pkg = require(path.join(directory, 'package.json'))
11-
const pkgPath = path.join(directory, pkgName)
12-
const tarball = fs.createReadStream(pkgPath)
139
if (process.env.DRY_RUN) {
14-
log.debug(`${pkg.name}@${pkg.version} - ${pkgPath}`)
10+
console.log(`${pkg.name}@${pkg.version}`)
1511
} else {
16-
return npmPublish(pkg, tarball, { token: process.env.NPM_AUTH_TOKEN })
12+
return npmPublish(directory, pkg, { token: process.env.NPM_AUTH_TOKEN })
1713
}
1814
}
1915

0 commit comments

Comments
 (0)