Skip to content

Commit

Permalink
Update workflow (#279)
Browse files Browse the repository at this point in the history
* Delete useless workflow

* Update workflow according to new branch strategy
  • Loading branch information
bonnie57 authored and allenchuang committed Oct 9, 2024
1 parent 6f0d6ee commit 27831ef
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 101 deletions.
93 changes: 0 additions & 93 deletions .github/workflows/build-and-test.yaml

This file was deleted.

11 changes: 6 additions & 5 deletions .github/workflows/pr-external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@ on:
types: [opened, synchronize]
branches:
- dev
- dev_v1.1

jobs:
Timestamp_PR_CREATED:
uses: storyprotocol/gha-workflows/.github/workflows/reusable-timestamp.yml@main

authorize:
if: github.event.pull_request.head.repo.full_name != github.repository
needs: [ Timestamp_PR_CREATED ]
environment: 'external'
needs: [Timestamp_PR_CREATED]
environment: "external"
runs-on: ubuntu-latest
steps:
- run: true

Timestamp_PR_APPROVED:
needs: [ authorize ]
needs: [authorize]
uses: storyprotocol/gha-workflows/.github/workflows/reusable-timestamp.yml@main

build_and_test:
needs: [ authorize, Timestamp_PR_APPROVED ]
needs: [authorize, Timestamp_PR_APPROVED]
uses: storyprotocol/gha-workflows/.github/workflows/reusable-build-test-workflow.yml@main
with:
sha: ${{ github.event.pull_request.head.sha }}
ENVIRONMENT: 'beta-sepolia'
ENVIRONMENT: "beta-sepolia"
secrets:
RPC_PROVIDER_URL: ${{ secrets.RPC_PROVIDER_URL }}
WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }}
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/pr-internal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ on:
branches:
- main
- dev
- v1.1
- dev_v1.1

pull_request:
branches:
- main
- dev
- v1.1
- dev_v1.1

jobs:

Timestamp:
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
uses: storyprotocol/gha-workflows/.github/workflows/reusable-timestamp.yml@main

build_and_test:
needs: [Timestamp]
uses: storyprotocol/gha-workflows/.github/workflows/reusable-build-test-workflow.yml@main
with:
sha: ${{ github.event.pull_request.head.sha }}
ENVIRONMENT: 'beta-sepolia'
ENVIRONMENT: "beta-sepolia"
secrets:
RPC_PROVIDER_URL: ${{ secrets.RPC_PROVIDER_URL }}
WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }}
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/publish-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- main
- v1.1
pull_request:
branches:
- main
- v1.1

jobs:
Timestamp:
Expand All @@ -30,6 +32,21 @@ jobs:
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]
Expand All @@ -51,6 +68,29 @@ jobs:
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]
Expand Down

0 comments on commit 27831ef

Please sign in to comment.