Skip to content

Commit 2816b60

Browse files
ci: enable publishing npm staging version from feature branch (#532)
1 parent b0c8af0 commit 2816b60

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

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

Lines changed: 15 additions & 6 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 run 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
@@ -27,15 +28,23 @@ jobs:
2728
id: set-staging-version
2829
working-directory: packages/dataprotector-deserializer
2930
run: |
31+
BRANCH=$(echo "${{ github.ref_name }}" | sed 's|/|-|g')
32+
COMMIT_SHA="${{ github.sha }}"
3033
CURRENT_VERSION=$(npm pkg get version | tr -d '"')
31-
NIGHTLY_VERSION="${CURRENT_VERSION}-nightly-${GITHUB_SHA::7}"
32-
echo "VERSION=${NIGHTLY_VERSION}" >> $GITHUB_OUTPUT
34+
STAGING_VERSION="${CURRENT_VERSION}-${BRANCH}-${COMMIT_SHA::7}"
35+
echo "VERSION=${STAGING_VERSION}" | tee -a $GITHUB_OUTPUT
36+
if [ "${BRANCH}" = "main" ]; then
37+
echo "DIST_TAG=nightly" | tee -a $GITHUB_OUTPUT
38+
else
39+
echo "DIST_TAG=${BRANCH}" | tee -a $GITHUB_OUTPUT
40+
fi
3341
outputs:
3442
VERSION: ${{ steps.set-staging-version.outputs.VERSION }}
43+
DIST_TAG: ${{ steps.set-staging-version.outputs.DIST_TAG }}
3544

3645
publish-npm-staging:
3746
# Only run for manual dispatch on main branch
38-
if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' }}
47+
if: ${{ github.event_name == 'workflow_dispatch' }}
3948
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/[email protected]
4049
needs: set-staging-version
4150
with:
@@ -44,7 +53,7 @@ jobs:
4453
node-version: '20'
4554
environment: 'staging'
4655
working-directory: packages/dataprotector-deserializer
47-
tag: 'nightly'
56+
tag: ${{ needs.set-staging-version.outputs.DIST_TAG }}
4857
version: ${{ needs.set-staging-version.outputs.VERSION }}
4958

5059
publish-npm-latest:

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

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

1515
jobs:
1616
set-staging-version:
17-
# Only run for manual dispatch on main branch
18-
if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' }}
17+
# Only run for manual dispatch
18+
# when run from main branch, sets dist-tag to "nightly"
19+
if: ${{ github.event_name == 'workflow_dispatch' }}
1920
runs-on: ubuntu-latest
2021
steps:
2122
- name: Checkout code
@@ -26,15 +27,23 @@ jobs:
2627
id: set-staging-version
2728
working-directory: packages/sdk
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: iExecBlockchainComputing/github-actions-workflows/.github/workflows/[email protected]
3948
needs: set-staging-version
4049
with:
@@ -43,7 +52,7 @@ jobs:
4352
node-version: '20'
4453
environment: 'staging'
4554
working-directory: packages/sdk
46-
tag: 'nightly'
55+
tag: ${{ needs.set-staging-version.outputs.DIST_TAG }}
4756
version: ${{ needs.set-staging-version.outputs.VERSION }}
4857
install-command: |
4958
npm ci

0 commit comments

Comments
 (0)