Skip to content

Commit 036a033

Browse files
authored
update workflow (#964)
1 parent 48f5a8f commit 036a033

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

.github/workflows/release.yml

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

0 commit comments

Comments
 (0)