Skip to content

Commit

Permalink
ci: add manual release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dalechyn committed Jan 19, 2024
1 parent 134e3b7 commit e2d46e6
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .github/actions/version-pr/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: "Determine version"
description: "Determines npm package version based on PR number and commit SHA"
outputs:
version:
description: "npm package version"
runs:
using: "node20"
main: "index.js"
20 changes: 20 additions & 0 deletions .github/actions/version-pr/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = require('fs')
const path = require('path')
const core = require('@actions/core')

try {
const packageJSONPath = path.join(
process.cwd(),
`packages/${process.env.PACKAGE_PATH || 'react'}/package.json`,
)
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf8'))

const sha8 = process.env.GITHUB_SHA.substring(0, 8)
const prefix = '0.0.0-'
const packageVersion = `${prefix}manual.${sha8}`
packageJSON.version = packageVersion
core.setOutput('version', packageVersion)
fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON))
} catch (error) {
core.setFailed(error.message)
}
60 changes: 60 additions & 0 deletions .github/workflows/manual-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Manual Release

on:
push:
branches:
- mainline
pull_request:
# TODO: Support latest releases
workflow_dispatch:
inputs:
name:
type: choice
description: Package name (npm)
options:
- "@abstract-money/core"
- "@abstract-money/cli"
- "@abstract-money/react"
# TODO: Infer from package name
path:
type: choice
description: Directory name (packages/*)
options:
- "core"
- "cli"
- "react"
env:
FORCE_COLOR: true

jobs:
release-manual:
name: Publish manually
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' }}
steps:
- uses: actions/checkout@v4
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0
submodules: true

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Determine version
uses: ./.github/actions/version-pr
id: determine-version
env:
PACKAGE_PATH: ${{ github.event.inputs.path }}
- name: Publish to npm
run: |
pnpm build
cd packages/$PACKAGE_PATH
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
pnpm publish --no-git-checks --access public --tag experimental
echo "🎉 Experimental release published 📦️ on npm: https://npmjs.com/package/${{ github.event.inputs.name }}/v/${{ env.VERSION }}"
echo "Install via: pnpm add ${{ github.event.inputs.name }}@${{ env.VERSION }}"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
PACKAGE_PATH: ${{ github.event.inputs.path }}
VERSION: ${{ steps.determine-version.outputs.version }}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export async function createSubAccount(
sender,
apiUrl,
)
managerClient.createSubAccount(...rest)
return managerClient.createSubAccount(...rest)
}

0 comments on commit e2d46e6

Please sign in to comment.