Skip to content

Commit bb81912

Browse files
authored
ci: adding publish action (#40)
1 parent fa97e3f commit bb81912

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Publish Package on Version Change
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
jobs:
8+
publish-if-version-changed:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Check if the package version has changed
17+
id: version_check
18+
uses: EndBug/version-check@v2
19+
with:
20+
# Check the version in the root package.json file
21+
diff-search: true
22+
file-name: package.json
23+
24+
- name: If the version has changed, continue with the following steps
25+
if: steps.version_check.outputs.changed == 'true'
26+
run: echo "The version has changed to ${{ steps.version_check.outputs.version }}. Proceeding to publish."
27+
28+
- name: Setup node
29+
if: steps.version_check.outputs.changed == 'true'
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: '20.18.1'
33+
cache: 'npm'
34+
registry-url: https://registry.npmjs.org
35+
36+
- name: Update the version in example/package.json
37+
if: steps.version_check.outputs.changed == 'true'
38+
run: |
39+
NEW_VERSION=${{ steps.version_check.outputs.version }}
40+
jq --arg v "$NEW_VERSION" '.dependencies."@vouched.id/vouched-react-native" = $v' example/package.json > example/package.json.tmp && mv example/package.json.tmp example/package.json
41+
42+
- name: Install dependencies
43+
if: steps.version_check.outputs.changed == 'true'
44+
run: npm ci
45+
46+
- name: Configure Git
47+
if: steps.version_check.outputs.changed == 'true'
48+
run: |
49+
git config --global user.name 'github-actions[bot]'
50+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
51+
52+
- name: Confirm the version change in example/package.json
53+
if: steps.version_check.outputs.changed == 'true'
54+
run: |
55+
git add example/package.json
56+
git commit -m "chore: update the version in example to ${{ steps.version_check.outputs.version }} [skip ci]"
57+
git push
58+
59+
- name: Create a Git tag with the new version
60+
if: steps.version_check.outputs.changed == 'true'
61+
run: |
62+
git tag -a "v${{ steps.version_check.outputs.version }}" -m "Release v${{ steps.version_check.outputs.version }}"
63+
git push origin --tags
64+
65+
- name: Publish to NPM
66+
if: steps.version_check.outputs.changed == 'true'
67+
run: npm publish
68+
env:
69+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
"description": "Vouched React Native SDK",
66
"main": "index.js",
77
"license": "Apache-2.0",
8+
"files": [
9+
"android",
10+
"ios",
11+
"src",
12+
"index.js",
13+
"README.md",
14+
"vouched-react-native.podspec"
15+
],
816
"repository": {
917
"type": "git",
1018
"url": "git+https://github.com/vouched/vouched-react-native.git"

0 commit comments

Comments
 (0)