Merge pull request #348 from storyprotocol/dev #235
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish to npm, Tag and create GH Release | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
permissions: | |
contents: write | |
actions: write | |
jobs: | |
timestamp: | |
uses: storyprotocol/gha-workflows/.github/workflows/reusable-timestamp.yml@main | |
print_version_to_publish: | |
needs: [timestamp] | |
runs-on: ubuntu-latest | |
outputs: | |
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 | |
- name: Get version to publish | |
id: get_version_to_publish | |
run: | | |
content=$(cat packages/core-sdk/package.json) | |
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, print_version_to_publish] | |
runs-on: ubuntu-latest | |
outputs: | |
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: | | |
CORE_SDK_LATEST_VERSION=$(npm view @story-protocol/core-sdk version --silent) | |
REACT_SDK_LATEST_VERSION=$(npm view @story-protocol/react-sdk version --silent) | |
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 | |
outputs: | |
IS_PUBLISH_CORE_SDK: ${{ steps.check_publish_condition.outputs.IS_PUBLISH_CORE_SDK }} | |
IS_PUBLISH_REACT_SDK: ${{ steps.check_publish_condition.outputs.IS_PUBLISH_REACT_SDK }} | |
steps: | |
- name: check publish condition | |
id: check_publish_condition | |
run: | | |
CORE_SDK_LATEST_VERSION="${{ needs.fetch_latest_version.outputs.CORE_SDK_LATEST_VERSION }}" | |
CORE_SDK_VERSION_TO_BE_PUBLISHED="${{ needs.print_version_to_publish.outputs.CORE_SDK_VERSION_TO_BE_PUBLISHED }}" | |
REACT_SDK_LATEST_VERSION="${{ needs.fetch_latest_version.outputs.REACT_SDK_LATEST_VERSION }}" | |
REACT_SDK_VERSION_TO_BE_PUBLISHED="${{ needs.print_version_to_publish.outputs.REACT_SDK_VERSION_TO_BE_PUBLISHED }}" | |
IS_PUBLISH_CORE_SDK=false | |
IS_PUBLISH_REACT_SDK=false | |
if [ "$CORE_SDK_LATEST_VERSION" == "$CORE_SDK_VERSION_TO_BE_PUBLISHED" ]; then | |
echo "The @story-protocol/core-sdk version to be published is the same as the latest version on NPM." | |
else | |
IS_PUBLISH_CORE_SDK=true | |
fi | |
if [ "$REACT_SDK_LATEST_VERSION" == "$REACT_SDK_VERSION_TO_BE_PUBLISHED" ]; then | |
echo "The @story-protocol/react-sdk version to be published is the same as the latest version on NPM." | |
else | |
IS_PUBLISH_REACT_SDK=true | |
fi | |
if [ "$CORE_SDK_LATEST_VERSION" == "$CORE_SDK_VERSION_TO_BE_PUBLISHED" ] && [ "$REACT_SDK_LATEST_VERSION" == "$REACT_SDK_VERSION_TO_BE_PUBLISHED" ]; then | |
echo "The @story-protocol/core-sdk and @story-protocol/react-sdk versions to be published are the same as the latest versions on NPM." | |
exit 1 | |
fi | |
echo "IS_PUBLISH_CORE_SDK=$IS_PUBLISH_CORE_SDK" >> $GITHUB_OUTPUT | |
echo "IS_PUBLISH_REACT_SDK=$IS_PUBLISH_REACT_SDK" >> $GITHUB_OUTPUT | |
fetch_last_tag: | |
needs: [fail_if_version_is_same] | |
if: ${{ (needs.fail_if_version_is_same.outputs.IS_PUBLISH_CORE_SDK == 'true' || needs.fail_if_version_is_same.outputs.IS_PUBLISH_REACT_SDK == 'true') && github.event_name == 'push' }} | |
runs-on: ubuntu-latest | |
outputs: | |
CORE_SDK_LATEST_TAG: ${{ steps.get_last_tag.outputs.CORE_SDK_LATEST_TAG }} | |
REACT_SDK_LATEST_TAG: ${{ steps.get_last_tag.outputs.REACT_SDK_LATEST_TAG }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- name: Get last tag | |
id: get_last_tag | |
run: | | |
git fetch --tags | |
CORE_SDK_LATEST_TAG=$(git tag --sort=creatordate | grep -E "@story-protocol/core-sdk|core-sdk" | tail -n1) | |
REACT_SDK_LATEST_TAG=$(git tag --sort=creatordate | grep -E "@story-protocol/react-sdk|react-sdk" | tail -n1) | |
echo "CORE_SDK_LATEST_TAG=$CORE_SDK_LATEST_TAG" >> $GITHUB_OUTPUT | |
echo "REACT_SDK_LATEST_TAG=$REACT_SDK_LATEST_TAG" >> $GITHUB_OUTPUT | |
echo "Last tag for @story-protocol/core-sdk is $CORE_SDK_LATEST_TAG" | |
echo "Last tag for @story-protocol/react-sdk is $REACT_SDK_LATEST_TAG" | |
build-test-publish: | |
needs: [fail_if_version_is_same, fetch_last_tag] | |
# Skip this job if the core-sdk and react-sdk don't need to be published | |
# and the event triggering the workflow is a push | |
if: ${{ (needs.fail_if_version_is_same.outputs.is_publish_core_sdk == 'true' || needs.fail_if_version_is_same.outputs.is_publish_react_sdk == 'true') && github.event_name == 'push' }} | |
runs-on: ubuntu-latest | |
environment: "beta-sepolia" | |
env: | |
WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }} | |
TEST_WALLET_ADDRESS: ${{ secrets.TEST_WALLET_ADDRESS }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.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: Install dependencies | |
run: pnpm install | |
- name: Build | |
run: pnpm build | |
- name: Publish core-sdk package to npm | |
if: ${{ github.event_name == 'push' && needs.fail_if_version_is_same.outputs.IS_PUBLISH_CORE_SDK == 'true'}} | |
run: | | |
cd packages/core-sdk | |
npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Publish react-sdk package to npm | |
if: ${{ github.event_name == 'push' && needs.fail_if_version_is_same.outputs.IS_PUBLISH_REACT_SDK == 'true'}} | |
run: | | |
cd packages/react-sdk | |
npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
create-release-core-sdk: | |
needs: | |
[ | |
build-test-publish, | |
fetch_last_tag, | |
fail_if_version_is_same, | |
print_version_to_publish, | |
] | |
# Skip this job if core-sdk doesn't need to be published | |
# and the event triggering the workflow is a push | |
if: ${{ github.event_name == 'push' && needs.fail_if_version_is_same.outputs.IS_PUBLISH_CORE_SDK == 'true'}} | |
uses: ./.github/workflows/create-release.yml | |
with: | |
tag_name: "@story-protocol/core-sdk@${{ needs.print_version_to_publish.outputs.core_sdk_version_to_be_published }}" | |
is_core_sdk: true | |
last_tag: ${{ needs.fetch_last_tag.outputs.CORE_SDK_LATEST_TAG }} | |
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 }}: @story-protocol/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, | |
fail_if_version_is_same, | |
fetch_last_tag, | |
] | |
# Skip this job if react-sdk doesn't need to be published | |
# and the event triggering the workflow is a push | |
if: ${{ github.event_name == 'push' && needs.fail_if_version_is_same.outputs.IS_PUBLISH_REACT_SDK == 'true'}} | |
uses: ./.github/workflows/create-release.yml | |
with: | |
tag_name: "@story-protocol/react-sdk@${{ needs.print_version_to_publish.outputs.react_sdk_version_to_be_published }}" | |
is_core_sdk: false | |
last_tag: ${{ needs.fetch_last_tag.outputs.REACT_SDK_LATEST_TAG }} | |
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 }}: @story-protocol/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 }} |