From c9a10414172c10ee985b844e6cc7c625137b9493 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Mon, 27 Apr 2020 19:27:58 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Release=20using=20GitHub=20Actio?= =?UTF-8?q?ns=20(#807)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 86 +++++++++++++++++++++++++++++++++++ scripts/binaries.sh | 12 +++++ scripts/package.sh | 10 ++-- scripts/publish.sh | 4 +- tasks/publish.js | 8 +--- 5 files changed, 107 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 scripts/binaries.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..52ef33e4b --- /dev/null +++ b/.github/workflows/release.yml @@ -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 diff --git a/scripts/binaries.sh b/scripts/binaries.sh new file mode 100644 index 000000000..f35d5227e --- /dev/null +++ b/scripts/binaries.sh @@ -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 diff --git a/scripts/package.sh b/scripts/package.sh index 666498991..ba0f3ecaf 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -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 diff --git a/scripts/publish.sh b/scripts/publish.sh index 95ab69e49..ae5363402 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -3,7 +3,9 @@ set -e -cd "$(dirname "$0")" +SCRIPT=`realpath $0` +SCRIPT_PATH=`dirname ${SCRIPT}` +cd "$(dirname "$0")" cd .. node tasks/publish.js diff --git a/tasks/publish.js b/tasks/publish.js index 58e9e0b1d..0748872c1 100644 --- a/tasks/publish.js +++ b/tasks/publish.js @@ -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' }) } }