Skip to content
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

ci(publish): add publish workflow #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
59 changes: 59 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: publish

on:
workflow_call:
push:
branches:
- master
paths:
- package.json

env:
CI: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v3
- uses: actions/checkout@v3
- run: npm install
- run: npm test

publish-npm:
needs: [ build ]
runs-on: ubuntu-latest
environment: npm
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: true
- uses: actions/setup-node@v3
with:
registry-url: https://registry.npmjs.org/
- name: publish to NPM
run: npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

publish-gpr:
needs: [ build ]
runs-on: ubuntu-latest
environment: ghpm
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions/setup-node@v3
with:
registry-url: https://npm.pkg.github.com/
scope: "@nodertc"
- name: rename package with @nodertc scope
run: node .npm/prepend-scope.cjs @nodertc
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 16 additions & 0 deletions .npm/prepend-scope.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!node
function usage () {
console.log(`${process.argv[1]} <scope>`)
process.exit(1)
}
const scope = process.argv[2]; if (!scope) usage()
const fs = require('fs')
const pkg = JSON.parse(fs.readFileSync('./package.json'))
const checkExistsRe = new RegExp(`^${scope}/`, 'g')
// console.log(`name: ${pkg.name}, scope: ${scope}, re: ${checkExistsRe}`)
if (checkExistsRe.test(pkg.name)) {
console.error(`already scoped to ${scope}`)
process.exit(1)
}
pkg.name = `${scope}/${pkg.name}`
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2))