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