-
Notifications
You must be signed in to change notification settings - Fork 28
64 lines (56 loc) · 2.12 KB
/
publish.yml
File metadata and controls
64 lines (56 loc) · 2.12 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
name: Publish to npm
on:
workflow_run:
workflows: ["Library"]
types:
- completed
branches:
- master
jobs:
publish:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup
uses: ./.github/actions/setup
- name: Setup Node.js for npm publish
uses: actions/setup-node@v4
with:
node-version: '20.9.0'
registry-url: 'https://registry.npmjs.org'
- name: Check if version already published
id: version-check
run: |
LOCAL_VERSION=$(node -p "require('./package.json').version")
echo "local_version=$LOCAL_VERSION" >> "$GITHUB_OUTPUT"
if npm view react-native-klarna-inapp-sdk@"$LOCAL_VERSION" version 2>/dev/null; then
echo "Version $LOCAL_VERSION already exists on npm. Skipping publish."
echo "should_publish=false" >> "$GITHUB_OUTPUT"
else
echo "Version $LOCAL_VERSION not found on npm. Will publish."
echo "should_publish=true" >> "$GITHUB_OUTPUT"
fi
- name: Publish to npm
if: steps.version-check.outputs.should_publish == 'true'
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub release
if: steps.version-check.outputs.should_publish == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version-check.outputs.local_version }}
name: ${{ steps.version-check.outputs.local_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
run: |
if [ "${{ steps.version-check.outputs.should_publish }}" == "true" ]; then
echo "### Published v${{ steps.version-check.outputs.local_version }} to npm" >> "$GITHUB_STEP_SUMMARY"
else
echo "### Skipped publish - v${{ steps.version-check.outputs.local_version }} already exists on npm" >> "$GITHUB_STEP_SUMMARY"
fi