Skip to content

Commit

Permalink
chore: support release any package as experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed May 4, 2023
1 parent 6f5a503 commit d6bc65f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/version-pr/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const core = require("@actions/core")
try {
const packageJSONPath = path.join(
process.cwd(),
"packages/next-auth/package.json"
`packages/${process.env.PACKAGE_PATH || "next-auth"}/package.json`
)
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, "utf8"))

const sha8 = process.env.GITHUB_SHA.substring(0, 8)
const prNumber = process.env.PR_NUMBER
const prNumber = process.env.PR_NUMBER || "manual"

const packageVersion = `0.0.0-pr.${prNumber}.${sha8}`
packageJSON.version = packageVersion
Expand Down
33 changes: 27 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ on:
- next
- 3.x
pull_request:
# TODO: Support latest releases
workflow_dispatch:
inputs:
name:
type: choice
description: Package name (npm)
options:
- "@auth/nextjs"
- "@auth/core"
- "next-auth"
# TODO: Infer from package name
path:
type: choice
description: Directory name (packages/*)
options:
- "frameworks-nextjs"
- "core"
- "next-auth"

jobs:
test:
Expand Down Expand Up @@ -86,7 +104,7 @@ jobs:
name: Publish PR
runs-on: ubuntu-latest
needs: test
if: ${{ github.event_name == 'pull_request' }}
if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
environment: Preview
steps:
- name: Init
Expand All @@ -103,22 +121,25 @@ jobs:
uses: ./.github/version-pr
id: determine-version
env:
PACKAGE_PATH: ${{ github.event.inputs.path }}
PR_NUMBER: ${{ github.event.number }}
- name: Publish to npm
run: |
cd packages/core
cd $PACKAGE_PATH
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
pnpm publish --no-git-checks --access public --tag experimental
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
PACKAGE_PATH: ${{ github.event.inputs.path }}
- name: Comment version on PR
if: ${{ github.event_name == 'pull_request'}}
uses: NejcZdovc/comment-pr@v2
with:
message:
"🎉 Experimental release [published 📦️ on npm](https://npmjs.com/package/@auth/core/v/${{ env.VERSION }})!\n \
```sh\npnpm add @auth/core@${{ env.VERSION }}\n```\n \
```sh\nyarn add @auth/core@${{ env.VERSION }}\n```\n \
```sh\nnpm i @auth/core@${{ env.VERSION }}\n```"
"🎉 Experimental release [published 📦️ on npm](https://npmjs.com/package/${{ github.event.inputs.name }}/v/${{ env.VERSION }})!\n \
```sh\npnpm add ${{ github.event.inputs.name }}@${{ env.VERSION }}\n```\n \
```sh\nyarn add ${{ github.event.inputs.name }}@${{ env.VERSION }}\n```\n \
```sh\nnpm i ${{ github.event.inputs.name }}@${{ env.VERSION }}\n```"
env:
VERSION: ${{ steps.determine-version.outputs.version }}
GITHUB_TOKEN: ${{ secrets.GH_PAT }}

1 comment on commit d6bc65f

@vercel
Copy link

@vercel vercel bot commented on d6bc65f May 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.