Skip to content

Commit 73eb583

Browse files
.github/workflows/release.yml -> Simplified publish jobs
.github/workflows/release.yml -> Added GitHub Package Registry publish .github/workflows/release.yml -> Removed redundant steps
1 parent 90ef0d7 commit 73eb583

File tree

2 files changed

+101
-73
lines changed

2 files changed

+101
-73
lines changed

.github/workflows/common_publish.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Common Publish Steps
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
registry-url:
7+
required: true
8+
type: string
9+
node-auth-token:
10+
required: true
11+
type: string
12+
browserstack-username:
13+
required: true
14+
type: string
15+
browserstack-access-key:
16+
required: true
17+
type: string
18+
19+
jobs:
20+
common-publish:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout branch
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: 16
30+
registry-url: ${{ inputs.registry-url }}
31+
always-auth: true
32+
env:
33+
NODE_AUTH_TOKEN: ${{ inputs.node-auth-token }}
34+
35+
- name: Install dependencies
36+
run: npm install
37+
38+
- id: latest-release
39+
name: Export latest release git tag
40+
run: |
41+
echo "latest-release-tag=$(curl -qsSL \
42+
-H "Accept: application/vnd.github+json" \
43+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
44+
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest" \
45+
| jq -r .tag_name)" >> $GITHUB_OUTPUT
46+
47+
- id: npm-tag
48+
name: Determine NPM tag
49+
env:
50+
GITHUB_RELEASE_TAG: ${{ github.event.release.tag_name }}
51+
run: |
52+
VERSION=$(jq -r '.version' package.json)
53+
LATEST_RELEASE_TAG="${{ steps.latest-release.outputs['latest-release-tag']}}"
54+
55+
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
56+
RELEASE_TAG=${GITHUB_REF#refs/tags/}
57+
else
58+
RELEASE_TAG=$GITHUB_RELEASE_TAG
59+
fi
60+
61+
if [[ $RELEASE_TAG == $LATEST_RELEASE_TAG ]]; then
62+
echo "npm-tag=latest" >> "$GITHUB_OUTPUT"
63+
elif [[ "$VERSION" == *"-beta"* ]]; then
64+
echo "npm-tag=beta" >> "$GITHUB_OUTPUT"
65+
elif [[ "$VERSION" == *"-alpha"* ]]; then
66+
echo "npm-tag=alpha" >> "$GITHUB_OUTPUT"
67+
elif [[ "$VERSION" == *"-rc"* ]]; then
68+
echo "npm-tag=rc" >> "$GITHUB_OUTPUT"
69+
else
70+
echo "npm-tag=v$(echo $VERSION | awk -F. '{print $1}')-latest" >> "$GITHUB_OUTPUT"
71+
fi
72+
73+
- id: release
74+
name: Test, build and publish
75+
env:
76+
BROWSERSTACK_USERNAME: ${{ inputs.browserstack-username }}
77+
BROWSERSTACK_ACCESS_KEY: ${{ inputs.browserstack-access-key }}
78+
NODE_AUTH_TOKEN: ${{ inputs.node-auth-token }}
79+
run: |
80+
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
81+
DRY_RUN="--dry-run"
82+
fi
83+
npm publish --tag=${{ steps.npm-tag.outputs['npm-tag'] }} --registry=${{ inputs.registry-url }} $DRY_RUN

.github/workflows/release.yml

+18-73
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,25 @@
1-
name: Publish SDK to NPM
1+
name: Publish SDK to NPM and GPR
22

33
on:
44
release:
5-
types: [published, edited]
5+
types: [published]
66
workflow_dispatch: {}
77

88
jobs:
9-
publish:
9+
publish_to_npm:
1010
name: Publish to NPM
11-
runs-on: ubuntu-latest
12-
if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.draft }}
13-
steps:
14-
- name: Checkout branch
15-
uses: actions/checkout@v4
16-
17-
- name: Setup Node
18-
uses: actions/setup-node@v3
19-
with:
20-
node-version: 16
21-
registry-url: "https://registry.npmjs.org/"
22-
always-auth: "true"
23-
env:
24-
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
25-
26-
- name: Install dependencies
27-
run: npm install
28-
29-
- id: latest-release
30-
name: Export latest release git tag
31-
run: |
32-
echo "latest-release-tag=$(curl -qsSL \
33-
-H "Accept: application/vnd.github+json" \
34-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
35-
"${{ github.api_url }}/repos/${{ github.repository }}/releases/latest" \
36-
| jq -r .tag_name)" >> $GITHUB_OUTPUT
37-
38-
- id: npm-tag
39-
name: Determine NPM tag
40-
run: |
41-
VERSION=$(jq -r '.version' package.json)
42-
LATEST_RELEASE_TAG="${{ steps.latest-release.outputs['latest-release-tag']}}"
43-
44-
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
45-
GITHUB_REF=${{ github.ref }}
46-
RELEASE_TAG=${GITHUB_REF#refs/tags/}
47-
else
48-
RELEASE_TAG="${{ github.event.release.tag_name }}"
49-
fi
50-
51-
if [[ $RELEASE_TAG == $LATEST_RELEASE_TAG ]]; then
52-
echo "npm-tag=latest" >> "$GITHUB_OUTPUT"
53-
elif [[ "$VERSION" == *"-beta"* ]]; then
54-
echo "npm-tag=beta" >> "$GITHUB_OUTPUT"
55-
elif [[ "$VERSION" == *"-alpha"* ]]; then
56-
echo "npm-tag=alpha" >> "$GITHUB_OUTPUT"
57-
elif [[ "$VERSION" == *"-rc"* ]]; then
58-
echo "npm-tag=rc" >> "$GITHUB_OUTPUT"
59-
else
60-
echo "npm-tag=v$(echo $VERSION | awk -F. '{print $1}')-latest" >> "$GITHUB_OUTPUT"
61-
fi
62-
63-
- id: release
64-
name: Test, build and publish to npm
65-
env:
66-
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
67-
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
68-
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
69-
run: |
70-
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
71-
DRY_RUN="--dry-run"
72-
fi
73-
npm publish --tag=${{ steps.npm-tag.outputs['npm-tag'] }} $DRY_RUN
74-
75-
# - name: Report results to Jellyfish
76-
# uses: optimizely/jellyfish-deployment-reporter-action@main
77-
# if: ${{ always() && github.event_name == 'release' && (steps.release.outcome == 'success' || steps.release.outcome == 'failure') }}
78-
# with:
79-
# jellyfish_api_token: ${{ secrets.JELLYFISH_API_TOKEN }}
80-
# is_successful: ${{ steps.release.outcome == 'success' }}
11+
uses: ./.github/workflows/common_publish.yml
12+
with:
13+
registry-url: 'https://registry.npmjs.org/'
14+
node-auth-token: ${{ secrets.NPM_PUBLISH_TOKEN }}
15+
browserstack-username: ${{ secrets.BROWSERSTACK_USERNAME }}
16+
browserstack-access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
17+
18+
publish_to_gpr:
19+
name: Publish to GitHub Package Registry
20+
uses: ./.github/workflows/common-publish.yml
21+
with:
22+
registry-url: 'https://npm.pkg.github.com/'
23+
node-auth-token: ${{ secrets.GITHUB_TOKEN }}
24+
browserstack-username: ${{ secrets.BROWSERSTACK_USERNAME }}
25+
browserstack-access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}

0 commit comments

Comments
 (0)