Skip to content

Commit

Permalink
updated version
Browse files Browse the repository at this point in the history
  • Loading branch information
shivankacker committed Mar 28, 2024
1 parent 47394fd commit 6284010
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Publish Package to npmjs
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
39 changes: 39 additions & 0 deletions .github/workflows/update-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Update Version

on:
push:
branches:
- master

jobs:
update-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '17'

- name: Increment version
id: increment-version
run: |
npm run ver-sync increment
- name: Commit and push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Update version"
git push
#- name: Merge development -> staging
# uses: devmasx/merge-branch@master
# with:
# type: now
# from_branch: production
# target_branch: master
# github_token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"scripts": {
"prepack": "yarn build",
"build": "rollup -c",
"dev": "rollup -c -w"
"dev": "rollup -c -w",
"ver-sync": "node scripts/sync-versions.js"
},
"devDependencies": {
"@babel/core": "^7.22.9",
Expand Down
25 changes: 25 additions & 0 deletions scripts/sync-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import packageJson from "../package.json" assert { type: "json" };
import fs from "fs";

// check if --increment flag is set
const increment = process.argv.includes("increment");

// read version and versionCode from package.json
let version = packageJson.version;

if (increment) {
console.log("=== Incrementing version ===");
// increment version
const versionParts = version.split(".");
const lastVersionPart = versionParts.pop();
versionParts.push(parseInt(lastVersionPart) + 1);
version = versionParts.join(".");

// update package.json
packageJson.version = version;

// write package.json
fs.writeFileSync("package.json", JSON.stringify(packageJson, null, 2));
}

console.log("=== Version updated to " + version + " ===");

0 comments on commit 6284010

Please sign in to comment.