Skip to content

Commit

Permalink
[feat] refactor the package publication workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyBoWu committed Apr 25, 2024
1 parent fd92005 commit 1315d49
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 72 deletions.
124 changes: 53 additions & 71 deletions .github/workflows/publish-package.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
name: Publish to npm, Tag and GH Release
name: Publish to npm, Tag and create GH Release

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
# Add timestamp
print_timestamp:
runs-on: ubuntu-latest
steps:
- name: Generate timestamp
run: |
echo "TIMESTAMP=$(TZ='America/Los_Angeles' date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV

- name: Print timestamp
run: |
echo "Execution time (Pacific Time Zone) $TIMESTAMP"
Timestamp:
uses: storyprotocol/gha-workflows/.github/workflows/reusable-timestamp.yml@main

print_version_to_publish:
needs: [print_timestamp]
needs: [ Timestamp ]
runs-on: ubuntu-latest
outputs:
version_to_be_published: ${{ steps.get_version_to_publish.outputs.VERSION_TO_BE_PUBLISHED }}
Expand All @@ -35,7 +30,7 @@ jobs:
# Fetch the latest version from NPM
fetch_latest_version:
needs: [print_timestamp]
needs: [ Timestamp ]
runs-on: ubuntu-latest
steps:
- name: Get latest package version
Expand All @@ -45,69 +40,56 @@ jobs:
# TO-DO: check if pushed version is greater than the latest version on NPM

build-test-publish:
needs: [print_version_to_publish, fetch_latest_version]
runs-on: ubuntu-latest
environment: 'beta-sepolia'
env:
RPC_PROVIDER_URL: ${{ secrets.RPC_PROVIDER_URL }}
WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }}
TEST_WALLET_ADDRESS: ${{ secrets.TEST_WALLET_ADDRESS }}
SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.SEPOLIA_RPC_PROVIDER_URL }}
SEPOLIA_WALLET_PRIVATE_KEY: ${{ secrets.SEPOLIA_WALLET_PRIVATE_KEY }}
SEPOLIA_TEST_WALLET_ADDRESS: ${{ secrets.SEPOLIA_TEST_WALLET_ADDRESS }}
STORY_TEST_NET_RPC_PROVIDER_URL: ${{ secrets.STORY_TEST_NET_RPC_PROVIDER_URL }}
STORY_TEST_NET_WALLET_PRIVATE_KEY: ${{ secrets.STORY_TEST_NET_WALLET_PRIVATE_KEY }}
STORY_TEST_NET_TEST_WALLET_ADDRESS: ${{ secrets.STORY_TEST_NET_TEST_WALLET_ADDRESS }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
# build-test-publish:
# # skip this job per PR trigger
# if: github.event_name == 'push'
# needs: [print_version_to_publish, fetch_latest_version]
# runs-on: ubuntu-latest
# environment: 'beta-sepolia'
# env:
# RPC_PROVIDER_URL: ${{ secrets.RPC_PROVIDER_URL }}
# WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }}
# TEST_WALLET_ADDRESS: ${{ secrets.TEST_WALLET_ADDRESS }}
# SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.SEPOLIA_RPC_PROVIDER_URL }}
# SEPOLIA_WALLET_PRIVATE_KEY: ${{ secrets.SEPOLIA_WALLET_PRIVATE_KEY }}
# SEPOLIA_TEST_WALLET_ADDRESS: ${{ secrets.SEPOLIA_TEST_WALLET_ADDRESS }}
# STORY_TEST_NET_RPC_PROVIDER_URL: ${{ secrets.STORY_TEST_NET_RPC_PROVIDER_URL }}
# STORY_TEST_NET_WALLET_PRIVATE_KEY: ${{ secrets.STORY_TEST_NET_WALLET_PRIVATE_KEY }}
# STORY_TEST_NET_TEST_WALLET_ADDRESS: ${{ secrets.STORY_TEST_NET_TEST_WALLET_ADDRESS }}
# steps:
# - name: Checkout
# uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- uses: pnpm/action-setup@d882d12c64e032187b2edb46d3a0d003b7a43598 # v2.4.0
with:
version: 8.8.0
# - uses: pnpm/action-setup@d882d12c64e032187b2edb46d3a0d003b7a43598 # v2.4.0
# with:
# version: 8.8.0

- name: Setup Node.js environment
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
with:
node-version: 20.0.0
cache: pnpm
registry-url: https://registry.npmjs.org/
# - name: Setup Node.js environment
# uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
# with:
# node-version: 20.0.0
# cache: pnpm
# registry-url: https://registry.npmjs.org/

- name: Install dependencies
run: pnpm install
# - name: Install dependencies
# run: pnpm install

- name: Build
run: pnpm build
# - name: Build
# run: pnpm build

- name: Test
run: pnpm test
# - name: Test
# run: pnpm test

- name: Publish to npm
run: |
cd packages/core-sdk
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# - name: Publish to npm
# run: |
# cd packages/core-sdk
# npm publish
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Tag and Push
run: |
VERSION=${{ needs.print_version_to_publish.outputs.version_to_be_published }}
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git tag -a v$VERSION -m "Release v$VERSION"
git push origin v$VERSION
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
create_release:
needs: [print_version_to_publish, fetch_latest_version]
uses: storyprotocol/gha-workflows/.github/workflows/reusable-create-release.yml@feat/refactor_reusable_create_release_2
with:
version_to_publish: ${{ needs.print_version_to_publish.outputs.version_to_be_published }}

- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.print_version_to_publish.outputs.version_to_be_published }}
release_name: Release v${{ needs.print_version_to_publish.outputs.version_to_be_published }}
body: Release of version v${{ needs.print_version_to_publish.outputs.version_to_be_published }}
draft: false
prerelease: false
2 changes: 1 addition & 1 deletion packages/core-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@story-protocol/core-sdk",
"version": "1.0.0-rc.6",
"version": "1.0.0-rc.8",
"description": "Story Protocol Core SDK",
"main": "dist/story-protocol-core-sdk.cjs.js",
"module": "dist/story-protocol-core-sdk.esm.js",
Expand Down

0 comments on commit 1315d49

Please sign in to comment.