Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
Loading