Skip to content

Commit 4ee9132

Browse files
authored
Merge pull request #2 from github/add-ci
add ci
2 parents 53fd5d9 + dc140ce commit 4ee9132

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

.github/setup/action.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Setup project
2+
description: Sets up the repo code, Node.js, and npm dependencies
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Set up Node.js
8+
uses: actions/setup-node@v2
9+
with:
10+
node-version: '16.x'
11+
cache: npm
12+
registry-url: https://registry.npmjs.org
13+
- name: Install npm dependencies
14+
run: npm ci
15+
shell: bash

.github/workflows/nodejs.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Node CI
2+
3+
on: [push, pull_request]
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
- name: Use Node.js 16.x
10+
uses: actions/setup-node@v1
11+
with:
12+
node-version: 16.x
13+
- name: npm install, build, and test
14+
run: |
15+
npm install
16+
npm run build
17+
npm test
18+
env:
19+
CI: true

.github/workflows/release.yml

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Release and publish
2+
3+
# Inspired by https://github.com/MylesBorins/node-osc/blob/959b9c83972a67390a351d333b23db3972ca7b46/.github/workflows/bump-version.yml and
4+
# https://github.com/MylesBorins/node-osc/blob/74b563c83736a04c4a37acbff9d7bb1f01a00f57/.github/workflows/create-release.yml
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: Semver descriptor for new version ("major", "minor", or "patch")
11+
type: choice
12+
options: ["major", "minor", "patch"]
13+
required: true
14+
15+
jobs:
16+
bump-version:
17+
name: Bump package version
18+
runs-on: ubuntu-latest
19+
outputs:
20+
new-tag: ${{ steps.new-tag.outputs.new-tag }}
21+
steps:
22+
- name: Checkout ref
23+
uses: actions/checkout@v2
24+
- name: Preparation
25+
uses: ./.github/actions/setup
26+
- name: Perform last-minute tests
27+
run: npm test
28+
- name: Configure Git
29+
run: |
30+
git config user.name "GitHub Actions"
31+
git config user.email "[email protected]"
32+
- name: Bump package version
33+
run: npm version ${{ github.event.inputs.version }}
34+
- name: Push back to GitHub
35+
run: git push origin main --follow-tags
36+
- name: Set output to new version
37+
id: new-tag
38+
run: |
39+
version=$(jq -r .version < package.json)
40+
echo "::set-output name=new-tag::v$version"
41+
create-release:
42+
name: Create GitHub release
43+
runs-on: ubuntu-latest
44+
needs: bump-version
45+
steps:
46+
- name: Checkout ref
47+
uses: actions/checkout@v2
48+
with:
49+
ref: ${{ needs.bump-version.outputs.new-tag }}
50+
- name: Preparation
51+
uses: ./.github/actions/setup
52+
- name: Create release
53+
uses: actions/github-script@v5
54+
with:
55+
github-token: ${{ secrets.GITHUB_TOKEN }}
56+
script: |
57+
await github.request(`POST /repos/${{ github.repository }}/releases`, {
58+
tag_name: "${{ needs.bump-version.outputs.new-tag }}",
59+
generate_release_notes: true
60+
})
61+
publish:
62+
name: Publish
63+
runs-on: ubuntu-latest
64+
needs: [bump-version, create-release]
65+
steps:
66+
- name: Checkout ref
67+
uses: actions/checkout@v2
68+
with:
69+
ref: ${{ needs.bump-version.outputs.new-tag }}
70+
- name: Preparation
71+
uses: ./.github/actions/setup
72+
- name: Setup npm registry
73+
uses: actions/setup-node@v2
74+
with:
75+
registry-url: 'https://registry.npmjs.org'
76+
- name: Publish to npm
77+
run: npm publish
78+
env:
79+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
80+
- name: Setup GHPR
81+
uses: actions/setup-node@v2
82+
with:
83+
registry-url: 'https://npm.pkg.github.com'
84+
- name: Publish to GHPR
85+
run: npm publish
86+
env:
87+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)