From e2d46e68d99c50d382fa2b38a78c5ec0c77d1bc4 Mon Sep 17 00:00:00 2001 From: hotwater Date: Fri, 19 Jan 2024 19:42:26 +0200 Subject: [PATCH] ci: add manual release workflow --- .github/actions/version-pr/action.yml | 8 +++ .github/actions/version-pr/index.js | 20 +++++++ .github/workflows/manual-release.yml | 60 +++++++++++++++++++ .../account/wallet/create-sub-account.ts | 2 +- 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 .github/actions/version-pr/action.yml create mode 100644 .github/actions/version-pr/index.js create mode 100644 .github/workflows/manual-release.yml diff --git a/.github/actions/version-pr/action.yml b/.github/actions/version-pr/action.yml new file mode 100644 index 00000000..3669b8f4 --- /dev/null +++ b/.github/actions/version-pr/action.yml @@ -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" \ No newline at end of file diff --git a/.github/actions/version-pr/index.js b/.github/actions/version-pr/index.js new file mode 100644 index 00000000..cbeff4c3 --- /dev/null +++ b/.github/actions/version-pr/index.js @@ -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) +} diff --git a/.github/workflows/manual-release.yml b/.github/workflows/manual-release.yml new file mode 100644 index 00000000..e00987aa --- /dev/null +++ b/.github/workflows/manual-release.yml @@ -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 }} \ No newline at end of file diff --git a/packages/core/src/actions/account/wallet/create-sub-account.ts b/packages/core/src/actions/account/wallet/create-sub-account.ts index a974f11b..9e0b5a26 100644 --- a/packages/core/src/actions/account/wallet/create-sub-account.ts +++ b/packages/core/src/actions/account/wallet/create-sub-account.ts @@ -15,5 +15,5 @@ export async function createSubAccount( sender, apiUrl, ) - managerClient.createSubAccount(...rest) + return managerClient.createSubAccount(...rest) }