Skip to content

Commit

Permalink
adding GH Actions for publishing client and common packages
Browse files Browse the repository at this point in the history
  • Loading branch information
cristidas committed Apr 4, 2024
1 parent bb19df1 commit f82d9c1
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/publish-client-package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish Client Package

on:
workflow_call:
inputs:
npm_access_token:
required: true
type: secret
version_changed:
required: true
type: boolean

jobs:
publish-client-package:
if: ${{ inputs.version_changed }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
corepack: true

- name: Install pnpm
run: corepack enable && corepack prepare pnpm@latest --activate

- name: Install dependencies with pnpm
run: pnpm i
working-directory: sdk/sdk-client

- name: Publish package with pnpm
run: pnpm bundle:npm
working-directory: sdk/sdk-client
env:
NPM_ACCESS_TOKEN: ${{ inputs.npm_access_token }}
36 changes: 36 additions & 0 deletions .github/workflows/publish-common-package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish Common Package

on:
workflow_call:
inputs:
npm_access_token:
required: true
type: secret
version_changed:
required: true
type: boolean

jobs:
publish-common-package:
if: ${{ inputs.version_changed }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
corepack: true

- name: Install pnpm
run: corepack enable && corepack prepare pnpm@latest --activate

- name: Install dependencies with pnpm
run: pnpm i
working-directory: sdk/sdk-common/bundle

- name: Publish package with pnpm
run: pnpm bundle:npm
working-directory: sdk/sdk-common/bundle
env:
NPM_ACCESS_TOKEN: ${{ inputs.npm_access_token }}
72 changes: 72 additions & 0 deletions .github/workflows/publish-packages-manually.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Publish Packages

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: false

on:
workflow_dispatch:
inputs:
branch:
description: 'Branch name'
required: true
type: choice
options:
- 'main'
- 'dev'
publish_option:
description: 'Select package(s) to publish'
required: true
type: choice
options:
- 'common'
- 'client'
- 'all'

jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
common_changed: ${{ steps.common-version-check.outputs.changed }}
client_changed: ${{ steps.client-version-check.outputs.changed }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
ref: ${{ github.event.inputs.branch || github.ref_name }}
- id: common-version-check
run: |
if git diff HEAD^ HEAD -- sdk/sdk-common/package.json | grep '"version":'; then
echo "::set-output name=changed::true"
else
echo "::set-output name=changed::false"
fi
- id: client-version-check
run: |
if git diff HEAD^ HEAD -- sdk/sdk-client/package.json | grep '"version":'; then
echo "::set-output name=changed::true"
else
echo "::set-output name=changed::false"
fi
publish-common:
needs: prepare
if: >-
(needs.prepare.outputs.common_changed == 'true') &&
((github.event.inputs.publish_option == 'common') || (github.event.inputs.publish_option == 'all'))
uses: ./.github/workflows/publish-common-package.yaml
with:
npm_access_token: ${{ secrets.NPM_ACCESS_TOKEN }}
version_changed: ${{ needs.prepare.outputs.common_changed }}

publish-client:
needs: prepare
if: >-
(needs.prepare.outputs.client_changed == 'true') &&
((github.event.inputs.publish_option == 'client') || (github.event.inputs.publish_option == 'all'))
uses: ./.github/workflows/publish-client-package.yaml
with:
npm_access_token: ${{ secrets.NPM_ACCESS_TOKEN }}
version_changed: ${{ needs.prepare.outputs.client_changed }}
56 changes: 56 additions & 0 deletions .github/workflows/publish-packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Publish Packages

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: false

on:
push:
branches:
- main
paths:
- 'sdk/sdk-common/package.json'
- 'sdk/sdk-client/package.json'

jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
common_changed: ${{ steps.common-version-check.outputs.changed }}
client_changed: ${{ steps.client-version-check.outputs.changed }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- id: common-version-check
run: |
if git diff HEAD^ HEAD -- sdk/sdk-common/package.json | grep '"version":'; then
echo "::set-output name=changed::true"
else
echo "::set-output name=changed::false"
fi
- id: client-version-check
run: |
if git diff HEAD^ HEAD -- sdk/sdk-client/package.json | grep '"version":'; then
echo "::set-output name=changed::true"
else
echo "::set-output name=changed::false"
fi
publish-common:
needs: prepare
if: ${{ needs.prepare.outputs.common_changed == 'true' }}
uses: ./.github/workflows/publish-common-package.yaml
with:
npm_access_token: ${{ secrets.NPM_ACCESS_TOKEN }}
version_changed: ${{ needs.prepare.outputs.common_changed }}

publish-client:
needs: prepare
if: ${{ needs.prepare.outputs.client_changed == 'true' }}
uses: ./.github/workflows/publish-client-package.yaml
with:
npm_access_token: ${{ secrets.NPM_ACCESS_TOKEN }}
version_changed: ${{ needs.prepare.outputs.client_changed }}

0 comments on commit f82d9c1

Please sign in to comment.