Skip to content

Commit 9092e54

Browse files
ci(publish): add GitHub package publication workflow
1 parent df8134e commit 9092e54

4 files changed

Lines changed: 58 additions & 1 deletion

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Publish GitHub Package
2+
3+
on:
4+
release:
5+
types: [released]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
publish-github:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v6
16+
with:
17+
ref: 'release'
18+
- uses: actions/setup-node@v6
19+
with:
20+
node-version: '23.x'
21+
- name: Build and Publish Package
22+
uses: borales/actions-yarn@v5
23+
with:
24+
cmd: run publish:github
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/publish.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
runs-on: ubuntu-latest
4040
steps:
4141
- uses: actions/checkout@v6
42+
with:
43+
ref: 'release'
4244
- uses: actions/setup-node@v6
4345
with:
4446
node-version: '23.x'

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
"docs:test": "yarn workspace docusaurus start",
3232
"lint": "eslint .",
3333
"build": "rimraf -- ./out/ ./typings/ && tsc --project tsconfig.build.json && ts-node ./scripts/release-prep.ts",
34-
"publish": "yarn build && cd out && npm login && npm publish"
34+
"build:github": "rimraf -- ./out/ ./typings/ && tsc --project tsconfig.build.json && ts-node ./scripts/release-prep-github.ts",
35+
"publish": "yarn build && cd out && npm login && npm publish",
36+
"publish:github": "yarn build:github && cd out && npm publish"
3537
},
3638
"nyc": {
3739
"include": "src"

scripts/release-prep-github.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import fs from 'fs'
2+
3+
// This file is used by build system to build a clean npm package with the compiled js files in the root of the package.
4+
// It will not be included in the npm package.
5+
6+
const source = fs.readFileSync(__dirname + '/../package.json').toString('utf-8')
7+
const sourceObj = JSON.parse(source)
8+
9+
sourceObj.scripts = {}
10+
delete sourceObj.nyc
11+
delete sourceObj.workspaces
12+
delete sourceObj.resolutions
13+
delete sourceObj.engines
14+
delete sourceObj.packageManager
15+
16+
sourceObj.main = 'index.js'
17+
sourceObj.types = 'declarations/index.d.ts'
18+
19+
fs.writeFileSync(__dirname + '/../out/package.json', Buffer.from(JSON.stringify(sourceObj, null, 2), 'utf-8'))
20+
fs.writeFileSync(__dirname + '/../out/version.txt', Buffer.from(sourceObj.version, 'utf-8'))
21+
fs.writeFileSync(__dirname + '/../out/.npmrc', Buffer.from('//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}\n', 'utf-8')) // uses an environment variable
22+
23+
fs.cpSync(__dirname + '/../typings', __dirname + '/../out/declarations', { recursive: true })
24+
fs.copyFileSync(__dirname + '/../LICENSE', __dirname + '/../out/LICENSE')
25+
fs.copyFileSync(__dirname + '/../README.md', __dirname + '/../out/README.md')
26+
fs.copyFileSync(__dirname + '/../SECURITY.md', __dirname + '/../out/SECURITY.md')
27+
fs.copyFileSync(__dirname + '/../CHANGELOG.md', __dirname + '/../out/CHANGELOG.md')

0 commit comments

Comments
 (0)