Skip to content

Commit c612e2c

Browse files
ci: allow sdk staging version publication from feature branches
1 parent b38d56a commit c612e2c

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

.github/workflows/sdk-publish-npm.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ permissions:
1515

1616
jobs:
1717
set-staging-version:
18-
# Only run for manual dispatch on main branch
19-
if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' }}
18+
# Only run for manual dispatch
19+
# when running from main branch, sets dist-tag to "nightly"
20+
if: ${{ github.event_name == 'workflow_dispatch' }}
2021
runs-on: ubuntu-latest
2122
steps:
2223
- name: Checkout code
@@ -26,19 +27,27 @@ jobs:
2627
- name: Set publish version
2728
id: set-staging-version
2829
run: |
30+
BRANCH=$(echo "${{ github.ref_name }}" | sed 's|/|-|g')
31+
COMMIT_SHA="${{ github.sha }}"
2932
CURRENT_VERSION=$(npm pkg get version | tr -d '"')
30-
NIGHTLY_VERSION="${CURRENT_VERSION}-nightly-${GITHUB_SHA::7}"
31-
echo "VERSION=${NIGHTLY_VERSION}" >> $GITHUB_OUTPUT
33+
STAGING_VERSION="${CURRENT_VERSION}-${BRANCH}-${COMMIT_SHA::7}"
34+
echo "VERSION=${STAGING_VERSION}" | tee -a $GITHUB_OUTPUT
35+
if [ "${BRANCH}" = "main" ]; then
36+
echo "DIST_TAG=nightly" | tee -a $GITHUB_OUTPUT
37+
else
38+
echo "DIST_TAG=${BRANCH}" | tee -a $GITHUB_OUTPUT
39+
fi
3240
outputs:
3341
VERSION: ${{ steps.set-staging-version.outputs.VERSION }}
42+
DIST_TAG: ${{ steps.set-staging-version.outputs.DIST_TAG }}
3443

3544
publish-npm-staging:
36-
# Only run for manual dispatch on main branch
37-
if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' }}
45+
# Only run for manual dispatch
46+
if: ${{ github.event_name == 'workflow_dispatch' }}
3847
uses: ./.github/workflows/reusable-sdk-npm.yml
3948
needs: set-staging-version
4049
with:
41-
tag: ${{ github.event.inputs.tag }}
50+
tag: ${{ needs.set-staging-version.outputs.DIST_TAG }}
4251
version: ${{ needs.set-staging-version.outputs.VERSION }}
4352

4453
publish-npm-latest:

0 commit comments

Comments
 (0)