Skip to content

Add Release and publish action #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Setup project
description: Sets up the repo code, Node.js, and npm dependencies

runs:
using: composite
steps:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: npm
registry-url: https://registry.npmjs.org
- name: Install npm dependencies
run: npm ci
shell: bash
24 changes: 0 additions & 24 deletions .github/workflows/publish.yml

This file was deleted.

85 changes: 85 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Release and publish

# Inspired by https://github.com/MylesBorins/node-osc/blob/959b9c83972a67390a351d333b23db3972ca7b46/.github/workflows/bump-version.yml and
# https://github.com/MylesBorins/node-osc/blob/74b563c83736a04c4a37acbff9d7bb1f01a00f57/.github/workflows/create-release.yml

on:
workflow_dispatch:
inputs:
version:
description: Semver descriptor for new version ("major", "minor", or "patch")
required: true

jobs:
bump-version:
name: Bump package version
runs-on: ubuntu-latest
outputs:
new-tag: ${{ steps.new-tag.outputs.new-tag }}
steps:
- name: Checkout ref
uses: actions/checkout@v2
- name: Preparation
uses: ./.github/actions/setup
- name: Perform last-minute tests
run: npm test
- name: Configure Git
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
- name: Bump package version
run: npm version ${{ github.event.inputs.version }}
- name: Push back to GitHub
run: git push origin main --follow-tags
- name: Set output to new version
id: new-tag
run: |
version=$(jq -r .version < package.json)
echo "::set-output name=new-tag::v$version"
create-release:
name: Create GitHub release
runs-on: ubuntu-latest
needs: bump-version
steps:
- name: Checkout ref
uses: actions/checkout@v2
with:
ref: ${{ needs.bump-version.outputs.new-tag }}
- name: Preparation
uses: ./.github/actions/setup
- name: Create release
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.request(`POST /repos/${{ github.repository }}/releases`, {
tag_name: "${{ needs.bump-version.outputs.new-tag }}",
generate_release_notes: true
})
publish:
name: Publish
runs-on: ubuntu-latest
needs: [bump-version, create-release]
steps:
- name: Checkout ref
uses: actions/checkout@v3
with:
ref: ${{ needs.bump-version.outputs.new-tag }}
- name: Preparation
uses: ./.github/actions/setup
- name: Setup npm registry
uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org'
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Setup GHPR
uses: actions/setup-node@v2
with:
registry-url: 'https://npm.pkg.github.com'
- name: Publish to GHPR
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}