Skip to content

Commit

Permalink
ci: add publish
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee committed Dec 31, 2023
1 parent f25ead7 commit 2d06565
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/package.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";

const { readFileSync, writeFileSync } = require("fs");

const pk = JSON.parse(readFileSync("package.json"));
pk.name = pk.name.startsWith("@") ? pk.name : `${process.env.SCOPE}/${pk.name}`;
writeFileSync("package.json", JSON.stringify(pk, null, 2));
console.log(pk.name);
60 changes: 60 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: publish

on:
workflow_dispatch:
inputs:
version:
description: "the package version you want to bump"
required: true
default: "keep current"
type: choice
options:
- "keep current"

push:
tags:
- "v*.*.*"

jobs:
publish-npm:
permissions:
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
registry-url: https://registry.npmjs.org/
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

publish-ghp:
runs-on: ubuntu-latest
env:
SCOPE: "@${{github.repository_owner}}"
permissions:
contents: read
packages: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
registry-url: "https://npm.pkg.github.com/"
# Defaults to the user or organization that owns the workflow file
scope: ${{env.SCOPE}}
token: ${{secrets.GITHUB_TOKEN}}
always-auth: true

- run: |
node .github/workflows/package.cjs
- run: npm publish --registry=https://npm.pkg.github.com
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

0 comments on commit 2d06565

Please sign in to comment.