Skip to content

Commit

Permalink
build: add ci and release workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
lgou2w committed Jun 5, 2021
1 parent 106d624 commit 646c905
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
push:
branches: [ master ]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2

- name: Setup Node.js environment ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: 6.4.0
run_install: true

- name: ESLint check
run: pnpm lint

- name: Build
run: pnpm build
126 changes: 126 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Release

on:
push:
tags:
- "**"

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2

- name: Setup Node.js environment ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: 6.4.0
run_install: true

- name: ESLint check
run: pnpm lint

- name: Build
run: pnpm build

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12
registry-url: https://registry.npmjs.org/

- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: 6.4.0
run_install: true

- name: Publish to NPM
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.TOKEN_NPM_PUBLISH }}

publish-github:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12
registry-url: https://npm.pkg.github.com/
scope: '@l2studio'

- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: 6.4.0
run_install: true

- run: echo registry=https://npm.pkg.github.com/l2studio >> .npmrc
- name: Publish to GitHub
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.TOKEN_GITHUB_PUBLISH }}

release:
needs: [build, publish-npm, publish-github]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
# Fetch all history
fetch-depth: 0

- name: Generate Changelog
id: changelog
shell: bash
env:
CURRENT: ${{ github.ref }}
# Special thanks to this post on Stack Overflow regarding change set between two tags:
# https://stackoverflow.com/questions/12082981
# Do note that actions/checkout will enter detach mode by default, so you won't have
# access to HEAD ref. Use GitHub-Action-supplied `github.ref` instead.
# Special thanks to this issue ticket regarding escaping newline:
# https://github.com/actions/create-release/issues/25
# We use Bash parameter expansion to do find-and-replace.
# https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
# Also we cannot use git rev-list because it always prepend "commit <hash>"
# See https://stackoverflow.com/questions/36927089/
run: |
current_tag=${CURRENT/refs\/tags\//}
last_tag=`git describe --tags --abbrev=0 "$current_tag"^ 2>/dev/null || echo`
if [ $last_tag ]; then
changelog=`git log --pretty="format:%H: %s" ${last_tag}..$current_tag`
else
changelog=`git log --pretty="format:%H: %s"`
fi
changelog="${changelog//'%'/'%25'}"
changelog="${changelog//$'\n'/' %0A'}"
echo "::set-output name=value::Change set since ${last_tag:-the beginning}: %0A%0A$changelog"
- name: GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB_PUBLISH }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
body: |
${{ steps.changelog.outputs.value }}

0 comments on commit 646c905

Please sign in to comment.