Skip to content

Origin/dev bpolania pr 2 #216

Origin/dev bpolania pr 2

Origin/dev bpolania pr 2 #216

name: Publish to npm, Tag and create GH Release
on:
push:
branches:
- main
- v1.1
pull_request:
branches:
- main
- v1.1
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
extract_branch_name:
needs: [Timestamp]
runs-on: ubuntu-latest
outputs:
branch_name: ${{ steps.extract_branch_name.outputs.branch_name }}
steps:
- name: Extract branch name
id: extract_branch_name
run: |
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
else
echo "BRANCH_NAME=${GITHUB_HEAD_REF}" >> $GITHUB_OUTPUT
fi
# Fetch the latest version from NPM
fetch_latest_version:
needs: [Timestamp]
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 || 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
check_if_version_is_valid_for_branch:
needs: [extract_branch_name, print_version_to_publish]
runs-on: ubuntu-latest
steps:
- name: Check if version is valid for branch
id: check_if_version_is_valid_for_branch
run: |
BRANCH_NAME="${{ needs.extract_branch_name.outputs.branch_name }}"
SDK_VERSION="${{ needs.print_version_to_publish.outputs.core_sdk_version_to_be_published }}"
REACT_SDK_VERSION="${{ needs.print_version_to_publish.outputs.react_sdk_version_to_be_published }}"
if [[ "$BRANCH_NAME" == "v1.1" || "$BRANCH_NAME" == "dev_v1.1" ]]; then
if ! [[ "$SDK_VERSION" =~ ^1\.1 ]] && ! [[ "$REACT_SDK_VERSION" =~ ^1\.1 ]]; then
echo "Error: Invalid version @story-protocol/core-sdk@$SDK_VERSION or @story-protocol/react-sdk@$REACT_SDK_VERSION for branch 'v1.1', only versions starting with '1.1' are allowed in v1.1 branch"
exit 1
fi
elif [[ "$BRANCH_NAME" == "main" || "$BRANCH_NAME" == "dev" ]]; then
if ! [[ "$SDK_VERSION" =~ ^1\.2 ]] && ! [[ "$REACT_SDK_VERSION" =~ ^1\.2 ]]; then
echo "Error: Invalid version @story-protocol/core-sdk@$SDK_VERSION or @story-protocol/react-sdk@$REACT_SDK_VERSION for branch 'main', only versions starting with '1.2' are allowed in main branch"
exit 1
fi
fi
# 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.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]
# 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.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:
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 }}
TEST_SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.TEST_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@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 Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Install dependencies
run: pnpm install
- name: Fix
run: pnpm fix
- name: Run Anvil
id: run_anvil
run: anvil --fork-url ${SEPOLIA_RPC_PROVIDER_URL} --silent &
- name: Check on Run Anvil
if: steps.run_anvil.outcome != 'success'
run: exit 1
- name: Test
run: pnpm test
- name: Build
run: pnpm build
- 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 }}
- 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.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:
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 }}