Skip to content

Commit e694f39

Browse files
Refactored to use common-publish.yml for NPM and GPR.
Removed repetitive steps like setup and checkout. Added common parameters for secret tokens and registry URLs.
1 parent c17fe50 commit e694f39

File tree

2 files changed

+95
-128
lines changed

2 files changed

+95
-128
lines changed

.github/workflows/common-publish.yml

Lines changed: 83 additions & 0 deletions
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 ${{ inputs.node-auth-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

Lines changed: 12 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -8,134 +8,18 @@ on:
88
jobs:
99
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
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 }}
1617

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-
env:
41-
GITHUB_RELEASE_TAG: ${{ github.event.release.tag_name }}
42-
run: |
43-
VERSION=$(jq -r '.version' package.json)
44-
LATEST_RELEASE_TAG="${{ steps.latest-release.outputs['latest-release-tag']}}"
45-
46-
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
47-
RELEASE_TAG=${GITHUB_REF#refs/tags/}
48-
else
49-
RELEASE_TAG=$GITHUB_RELEASE_TAG
50-
fi
51-
52-
if [[ $RELEASE_TAG == $LATEST_RELEASE_TAG ]]; then
53-
echo "npm-tag=latest" >> "$GITHUB_OUTPUT"
54-
elif [[ "$VERSION" == *"-beta"* ]]; then
55-
echo "npm-tag=beta" >> "$GITHUB_OUTPUT"
56-
elif [[ "$VERSION" == *"-alpha"* ]]; then
57-
echo "npm-tag=alpha" >> "$GITHUB_OUTPUT"
58-
elif [[ "$VERSION" == *"-rc"* ]]; then
59-
echo "npm-tag=rc" >> "$GITHUB_OUTPUT"
60-
else
61-
echo "npm-tag=v$(echo $VERSION | awk -F. '{print $1}')-latest" >> "$GITHUB_OUTPUT"
62-
fi
63-
64-
- id: release
65-
name: Test, build and publish to npm
66-
env:
67-
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
68-
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
69-
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
70-
run: |
71-
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
72-
DRY_RUN="--dry-run"
73-
fi
74-
npm publish --tag=${{ steps.npm-tag.outputs['npm-tag'] }} $DRY_RUN
75-
7618
publish_to_gpr:
7719
name: Publish to GitHub Package Registry
78-
runs-on: ubuntu-latest
79-
if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.draft }}
80-
steps:
81-
- name: Checkout branch
82-
uses: actions/checkout@v4
83-
84-
- name: Setup Node.js for GPR
85-
uses: actions/setup-node@v3
86-
with:
87-
node-version: 16
88-
registry-url: 'https://npm.pkg.github.com/'
89-
always-auth: true
90-
env:
91-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92-
93-
- name: Install dependencies
94-
run: npm install
95-
96-
- id: latest-release
97-
name: Export latest release git tag
98-
run: |
99-
echo "latest-release-tag=$(curl -qsSL \
100-
-H "Accept: application/vnd.github+json" \
101-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
102-
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest" \
103-
| jq -r .tag_name)" >> $GITHUB_OUTPUT
104-
105-
- id: npm-tag
106-
name: Determine NPM tag
107-
env:
108-
GITHUB_RELEASE_TAG: ${{ github.event.release.tag_name }}
109-
run: |
110-
VERSION=$(jq -r '.version' package.json)
111-
LATEST_RELEASE_TAG="${{ steps.latest-release.outputs['latest-release-tag']}}"
112-
113-
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
114-
RELEASE_TAG=${GITHUB_REF#refs/tags/}
115-
else
116-
RELEASE_TAG=$GITHUB_RELEASE_TAG
117-
fi
118-
119-
if [[ $RELEASE_TAG == $LATEST_RELEASE_TAG ]]; then
120-
echo "npm-tag=latest" >> "$GITHUB_OUTPUT"
121-
elif [[ "$VERSION" == *"-beta"* ]]; then
122-
echo "npm-tag=beta" >> "$GITHUB_OUTPUT"
123-
elif [[ "$VERSION" == *"-alpha"* ]]; then
124-
echo "npm-tag=alpha" >> "$GITHUB_OUTPUT"
125-
elif [[ "$VERSION" == *"-rc"* ]]; then
126-
echo "npm-tag=rc" >> "$GITHUB_OUTPUT"
127-
else
128-
echo "npm-tag=v$(echo $VERSION | awk -F. '{print $1}')-latest" >> "$GITHUB_OUTPUT"
129-
fi
130-
131-
- id: release
132-
name: Test, build and publish to gpr
133-
env:
134-
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
135-
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
136-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
137-
run: |
138-
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
139-
DRY_RUN="--dry-run"
140-
fi
141-
npm publish --tag=${{ steps.npm-tag.outputs['npm-tag'] }} --registry=https://npm.pkg.github.com/ $DRY_RUN
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)