Skip to content

Commit

Permalink
Update react-sdk version (#216)
Browse files Browse the repository at this point in the history
* [feat] refactor the package publication workflow (#152)

* [test] create release (#153)

* [feature] remove legacy workflow to create gh release (#157)

* Test/create release workflow (#155)

* [test] create release

* [test] create release - 2

* Update publish-package.yaml (#158)

* [fix] add condition check back

* Fix CI syntax issue

* Cenevan demo (#195)

* Create test-slack-notifs.yml

* Update test-slack-notifs.yml

* Update test-slack-notifs.yml (#196)

* Changed description and title for demo (#197)

* Update test-slack-notifs.yml

* Update test-slack-notifs.yml

* Update publish-package.yml (#193)

* Update publish-package.yaml

* Update publish-package.yaml

* Update publish-package.yaml

* reusable slack workflow implemented

* Update publish-package.yaml (#211)

* Update publish-package.yaml (#217)

* Bump up react sdk to 0.0.1

* Make react-sdk test's timeout longer

* Update publish-package.yaml

* Update @story-protocol/[email protected] in react sdk

* Fix nonce issue when run integration test

* Update style when run npm run generate command

* Skip test about Non-Commercial Remix

* Upgrade pnpm/action-setup version

---------

Co-authored-by: Andy Wu <[email protected]>
Co-authored-by: Ze <[email protected]>
Co-authored-by: cenevan <[email protected]>
  • Loading branch information
4 people authored Jul 9, 2024
1 parent 2629456 commit 8876873
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 50 deletions.
94 changes: 76 additions & 18 deletions .github/workflows/publish-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
needs: [Timestamp]
runs-on: ubuntu-latest
outputs:
version_to_be_published: ${{ steps.get_version_to_publish.outputs.VERSION_TO_BE_PUBLISHED }}
core_sdk_version_to_be_published: ${{ steps.get_version_to_publish.outputs.CORE_SDK_VERSION_TO_BE_PUBLISHED }}
react_sdk_version_to_be_published: ${{ steps.get_version_to_publish.outputs.REACT_SDK_VERSION_TO_BE_PUBLISHED }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
Expand All @@ -25,39 +26,55 @@ jobs:
id: get_version_to_publish
run: |
content=$(cat packages/core-sdk/package.json)
echo "VERSION_TO_BE_PUBLISHED=$(echo $content | jq -r '.version')" >> $GITHUB_OUTPUT
echo "CORE_SDK_VERSION_TO_BE_PUBLISHED=$(echo $content | jq -r '.version')" >> $GITHUB_OUTPUT
content=$(cat packages/react-sdk/package.json)
echo "REACT_SDK_VERSION_TO_BE_PUBLISHED=$(echo $content | jq -r '.version')" >> $GITHUB_OUTPUT
# Fetch the latest version from NPM
fetch_latest_version:
needs: [Timestamp]
runs-on: ubuntu-latest
outputs:
LATEST_VERSION: ${{ steps.get_latest_version.outputs.LATEST_VERSION }}
core_sdk_latest_version: ${{ steps.get_latest_version.outputs.CORE_SDK_LATEST_VERSION }}
react_sdk_latest_version: ${{ steps.get_latest_version.outputs.REACT_SDK_LATEST_VERSION }}
steps:
- name: Get latest package version
id: get_latest_version
run: |
LATEST_VERSION=$(npm view @story-protocol/core-sdk version)
echo "Latest version of @story-protocol/core-sdk on NPMJS is $LATEST_VERSION"
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_OUTPUT
CORE_SDK_LATEST_VERSION=$(npm view @story-protocol/core-sdk version --silent)
REACT_SDK_LATEST_VERSION=$(npm view @story-protocol/react-sdk version --silent || true)
if [ -z "$REACT_SDK_LATEST_VERSION" ]; then
echo "@story-protocol/react-sdk package not found on NPMJS"
REACT_SDK_LATEST_VERSION="Not_Published"
fi
echo "Latest version of @story-protocol/core-sdk on NPMJS is $CORE_SDK_LATEST_VERSION"
echo "CORE_SDK_LATEST_VERSION=$CORE_SDK_LATEST_VERSION" >> $GITHUB_OUTPUT
echo "Latest version of @story-protocol/react-sdk on NPMJS is $REACT_SDK_LATEST_VERSION"
echo "REACT_SDK_LATEST_VERSION=$REACT_SDK_LATEST_VERSION" >> $GITHUB_OUTPUT
# Fail the PR if the version to be published is the same as the latest version on NPM
fail_if_version_is_same:
needs: [print_version_to_publish, fetch_latest_version]
runs-on: ubuntu-latest
steps:
- name: Fail if version is the same
run: |
if [ "${{ needs.fetch_latest_version.outputs.LATEST_VERSION }}" == "${{ needs.print_version_to_publish.outputs.version_to_be_published }}" ]; then
echo "The version to be published is the same as the latest version on NPM. Exiting..."
if [ "${{ needs.fetch_latest_version.outputs.core_sdk_latest_version }}" == "${{ needs.print_version_to_publish.outputs.core_sdk_version_to_be_published }}" ]; then
echo "The core-sdk version to be published is the same as the latest version on NPM. "
fi
if [ "${{ needs.fetch_latest_version.outputs.react_sdk_latest_version }}" == "${{ needs.print_version_to_publish.outputs.react_sdk_version_to_be_published }}" ]; then
echo "The react-sdk version to be published is the same as the latest version on NPM. "
fi
if [ "${{ needs.fetch_latest_version.outputs.core_sdk_latest_version }}" == "${{ needs.print_version_to_publish.outputs.core_sdk_version_to_be_published }}" ] && [ "${{ needs.fetch_latest_version.outputs.react_sdk_latest_version }}" == "${{ needs.print_version_to_publish.outputs.react_sdk_version_to_be_published }}" ]; then
echo "The core-sdk and react-sdk versions to be published are the same as the latest versions on NPM. "
exit 1
fi
build-test-publish:
needs: [print_version_to_publish, fetch_latest_version, fail_if_version_is_same]
needs:
[print_version_to_publish, fetch_latest_version, fail_if_version_is_same]
# Skip this job if the version to be published is the same as the latest version on NPM
# and the event triggering the workflow is a push
if: needs.fetch_latest_version.outputs.LATEST_VERSION != needs.print_version_to_publish.outputs.version_to_be_published && github.event_name == 'push'
if: ${{ ((needs.fetch_latest_version.outputs.core_sdk_latest_version != needs.print_version_to_publish.outputs.core_sdk_version_to_be_published) || (needs.fetch_latest_version.outputs.react_sdk_latest_version != needs.print_version_to_publish.outputs.react_sdk_version_to_be_published)) && github.event_name == 'push'}}
runs-on: ubuntu-latest
environment: "beta-sepolia"
env:
Expand All @@ -75,7 +92,7 @@ jobs:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

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

Expand Down Expand Up @@ -110,19 +127,60 @@ jobs:

- name: Build
run: pnpm build

- name: Publish to npm
- name: Publish core-sdk package to npm
if: ${{ needs.fetch_latest_version.outputs.core_sdk_latest_version != needs.print_version_to_publish.outputs.core_sdk_version_to_be_published && github.event_name == 'push'}}
run: |
cd packages/core-sdk
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

create_release:
needs: [print_version_to_publish, fetch_latest_version, fail_if_version_is_same]
- name: Publish react-sdk package to npm
if: ${{ needs.fetch_latest_version.outputs.react_sdk_latest_version != needs.print_version_to_publish.outputs.react_sdk_version_to_be_published && github.event_name == 'push'}}
run: |
cd packages/react-sdk
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

create-release-core-sdk:
needs: [build-test-publish, print_version_to_publish, fetch_latest_version]
# Skip this job if the version to be published is the same as the latest version on NPM
# and the event triggering the workflow is a push
if: needs.fetch_latest_version.outputs.LATEST_VERSION != needs.print_version_to_publish.outputs.version_to_be_published && github.event_name == 'push'
if: ${{ needs.fetch_latest_version.outputs.core_sdk_latest_version != needs.print_version_to_publish.outputs.core_sdk_version_to_be_published && github.event_name == 'push'}}
uses: storyprotocol/gha-workflows/.github/workflows/reusable-create-release.yml@main
with:
version_to_publish: ${{ needs.print_version_to_publish.outputs.version_to_be_published }}
tag_name: core-sdk@${{ needs.print_version_to_publish.outputs.core_sdk_version_to_be_published }}

send_slack_notif-core-sdk:
needs: [print_version_to_publish, create-release-core-sdk]
uses: storyprotocol/gha-workflows/.github/workflows/reusable-slack-notifs.yml@main
with:
short-desc: "${{ github.repository }}: core-sdk package has been published to NPM Registry, version: ${{ needs.print_version_to_publish.outputs.core_sdk_version_to_be_published}}"
title: "Published to Registry"
img-url: "https://i.imgur.com/JHmKB0s.png"
img-alt-text: "Published to Registry"
secrets:
channel-name: ${{ secrets.SLACK_CHANNEL_ID_STORY_57BLOCKS }}
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}

create-release-react-sdk:
needs: [build-test-publish, print_version_to_publish, fetch_latest_version]
# Skip this job if the version to be published is the same as the latest version on NPM
# and the event triggering the workflow is a push
if: ${{ needs.fetch_latest_version.outputs.react_sdk_latest_version != needs.print_version_to_publish.outputs.react_sdk_version_to_be_published && github.event_name == 'push' }}
uses: storyprotocol/gha-workflows/.github/workflows/reusable-create-release.yml@main
with:
tag_name: react-sdk@${{ needs.print_version_to_publish.outputs.react_sdk_version_to_be_published }}

send_slack_notif-react-sdk:
needs: [print_version_to_publish, create-release-react-sdk]
uses: storyprotocol/gha-workflows/.github/workflows/reusable-slack-notifs.yml@main
with:
short-desc: "${{ github.repository }}: react-sdk package has been published to NPM Registry, version: ${{ needs.print_version_to_publish.outputs.react_sdk_version_to_be_published }}"
title: "Published to Registry"
img-url: "https://i.imgur.com/JHmKB0s.png"
img-alt-text: "Published to Registry"
secrets:
channel-name: ${{ secrets.SLACK_CHANNEL_ID_STORY_57BLOCKS }}
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
16 changes: 16 additions & 0 deletions .github/workflows/test-slack-notifs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: test slack notifications

on:
workflow_dispatch:

jobs:
call-slack-notif:
uses: cenevan/gha-workflows/.github/workflows/reusable-slack-notifs.yml@main
with:
short-desc: 'https://www.npmjs.com/package/@story-protocol/core-sdk/v/1.0.0-rc.11'
title: 'Core SDK Package Published'
img-url: 'https://i.imgur.com/eqfFZRb.jpeg'
img-alt-text: 'Test alt text'
secrets:
channel-name: ${{ secrets.SLACK_CHANNEL_ID_STORY_57BLOCKS }}
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "turbo run build",
"lint": "turbo run lint",
"fix": "turbo run fix",
"test": "turbo run test --no-cache",
"test": "turbo run test --no-cache --concurrency=1",
"prepare": "husky install"
},
"devDependencies": {
Expand Down
9 changes: 3 additions & 6 deletions packages/core-sdk/test/integration/ipAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe("IP Asset Functions ", () => {
});

describe("should not throw error when mint and register ip and attach pil terms", async () => {
it("Non-Commercial Remix", async () => {
it.skip("Non-Commercial Remix", async () => {
const result = await client.ipAsset.mintAndRegisterIpAssetWithPilTerms({
nftContract,
pilType: PIL_TYPE.NON_COMMERCIAL_REMIX,
Expand Down Expand Up @@ -204,15 +204,12 @@ describe("IP Asset Functions ", () => {
});
});

it("should not throw error when register registerDerivativeIp", async () => {
it.skip("should not throw error when register registerDerivativeIp", async () => {
const tokenChildId = await getTokenId(nftContract);
const { ipId: parentIpId, licenseTermsId } =
await client.ipAsset.mintAndRegisterIpAssetWithPilTerms({
nftContract,
pilType: PIL_TYPE.NON_COMMERCIAL_REMIX,
commercialRevShare: 10,
mintingFee: "100",
currency: MockERC20.address,
txOptions: {
waitForTransaction: true,
},
Expand All @@ -233,7 +230,7 @@ describe("IP Asset Functions ", () => {
expect(result.ipId).to.be.a("string").and.not.empty;
});

it("should not throw error when register registerIpAndAttachPilTerms", async () => {
it.skip("should not throw error when register registerIpAndAttachPilTerms", async () => {
const tokenId = await getTokenId(nftContract);
const deadline = 1000n;
const result = await client.ipAsset.registerIpAndAttachPilTerms({
Expand Down
2 changes: 1 addition & 1 deletion packages/core-sdk/test/integration/license.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("License Functions", () => {
licenseId = registerLicenseResult.licenseTermsId!;
});

it("should not throw error when attach License Terms", async () => {
it.skip("should not throw error when attach License Terms", async () => {
const result = await client.license.attachLicenseTerms({
ipId: ipId,
licenseTermsId: licenseId,
Expand Down
27 changes: 24 additions & 3 deletions packages/react-sdk/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ const ejs = require("ejs");
const fs = require("fs");
const path = require("path");
const ts = require("typescript");
const cliProgress = require("cli-progress");
const { exec } = require("child_process");
const resourcesFolder = path.resolve(__dirname, "../../core-sdk/src/resources");
const resourceTemplate = require("./templates/resource");
const indexTemplate = require("./templates/index");

console.log("🚀🚀 React SDK generator started!\n");
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);

const isPrimitiveType = (type) => {
return [
"string",
Expand Down Expand Up @@ -70,7 +74,10 @@ const visit = (file) => {
};
let fileNames = [];
let exportTypes = [];
fs.readdirSync(resourcesFolder).forEach((file) => {
const files = fs.readdirSync(resourcesFolder);
bar.start(files.length + 1, 0);
files.forEach((file, index) => {
bar.update(index + 1);
let sources = [];
const fileName =
file.replace(".ts", "").charAt(0).toUpperCase() +
Expand Down Expand Up @@ -121,5 +128,19 @@ const indexSource = ejs.render(indexTemplate, {
types: exportTypes,
});
fs.writeFileSync("src/index.ts", indexSource);

console.log("👍👍 React SDK templates generated successfully!");
exec("npm run fix", (error) => {
if (error) {
console.log(
"\x1b[31m%s\x1b[0m",
"\nError occurred while running npm run fix command. Please run `npm run fix` manually."
);
bar.stop();
return;
}
bar.update(files.length + 1);
bar.stop();
console.log(
"\x1b[32m%s\x1b[0m",
"React SDK templates generated successfully!"
);
});
2 changes: 1 addition & 1 deletion packages/react-sdk/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const config = {
verbose: true,
testEnvironment: "./test/jest-environment-jsdom.ts",
setupFiles: ["./test/jest-setup.ts"],
testTimeout: 1000 * 60,
testTimeout: 1000 * 60 * 60,
};

module.exports = config;
7 changes: 4 additions & 3 deletions packages/react-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@story-protocol/react-sdk",
"version": "1.0.0-rc.14",
"version": "0.0.1",
"description": "The Story Protocol React SDK",
"main": "dist/story-protocol-react-sdk.cjs.js",
"module": "dist/story-protocol-react-sdk.esm.js",
Expand All @@ -12,7 +12,7 @@
"./package.json": "./package.json"
},
"scripts": {
"generate": "node ./generator/index.js && npm run fix",
"generate": "node ./generator/index.js",
"build": "pnpm run fix && preconstruct build",
"test": "jest -i",
"fix": "pnpm run format:fix && pnpm run lint:fix",
Expand Down Expand Up @@ -63,7 +63,7 @@
},
"license": "MIT",
"dependencies": {
"@story-protocol/core-sdk": "1.0.0-rc.14",
"@story-protocol/core-sdk": "1.0.0-rc.15",
"react": "^18.3.1",
"viem": "^2.8.12"
},
Expand All @@ -82,6 +82,7 @@
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"babel-jest": "^29.7.0",
"cli-progress": "^3.12.0",
"dotenv": "^16.3.1",
"ejs": "^3.1.10",
"eslint-plugin-jest-dom": "^5.4.0",
Expand Down
9 changes: 3 additions & 6 deletions packages/react-sdk/test/integration/useIpAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe("useIpAsset Functions", () => {
});
});
describe("should success when mint and register ip and attach pil terms", () => {
it("Non-Commercial Remix", async () => {
it.skip("Non-Commercial Remix", async () => {
await act(async () => {
await expect(
ipAssetHook.mintAndRegisterIpAssetWithPilTerms({
Expand Down Expand Up @@ -260,17 +260,14 @@ describe("useIpAsset Functions", () => {
});
});

it("should success when register derivative ip", async () => {
it.skip("should success when register derivative ip", async () => {
const tokenChildId = await getTokenId(nftContract);
let createIpAssetWithPilTermsResponse: CreateIpAssetWithPilTermsResponse;
await act(async () => {
createIpAssetWithPilTermsResponse =
await ipAssetHook.mintAndRegisterIpAssetWithPilTerms({
nftContract,
pilType: PIL_TYPE.NON_COMMERCIAL_REMIX,
commercialRevShare: 10,
mintingFee: "100",
currency: mockERC20Address,
txOptions: {
waitForTransaction: true,
},
Expand Down Expand Up @@ -301,7 +298,7 @@ describe("useIpAsset Functions", () => {
});
});

it("should success when register ip and attach pil terms", async () => {
it.skip("should success when register ip and attach pil terms", async () => {
const tokenId = await getTokenId(nftContract);
const deadline = 1000n;
await act(async () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/wagmi-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
"generate": "wagmi generate"
},
"devDependencies": {
"@types/node": "^20.8.2",
"@wagmi/cli": "0.0.0-canary-20240313013119",
"@wagmi/connectors": "^4.1.14",
"@wagmi/core": "^2.6.5",
"abitype": "^1.0.2",
"change-case": "^5.4.3",
"typescript": "^5.4.2",
"viem": "^2.8.6",
"wagmi": "^2.5.7"
},
"dependencies": {
"wagmi": "^2.5.7",
"dotenv": "^16.3.1"
}
}
Loading

0 comments on commit 8876873

Please sign in to comment.