From bd6ca73abfed722458ca2b5b45d53e49c624c514 Mon Sep 17 00:00:00 2001 From: anserwaseem Date: Sat, 22 Feb 2025 19:17:16 +0500 Subject: [PATCH] configure release pipeline --- .github/workflows/release.yml | 55 ++++++++++++++++++++++++++++++++++ electron-builder.yml | 3 +- package.json | 6 +++- scripts/bump-version.ts | 56 +++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 scripts/bump-version.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..90093a4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,55 @@ +name: Release +on: + push: + branches: + - 60-configure-release-pipeline + +jobs: + release: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [macos-latest, windows-latest] + + steps: + - name: Check out Git repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + + - name: Install dependencies + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SUPABASE_URL: ${{ vars.SUPABASE_URL }} + SUPABASE_ANON_KEY: ${{ vars.SUPABASE_ANON_KEY }} + run: npm i + + - name: Bump version + if: matrix.os == 'macos-latest' + run: | + git config --global user.name 'GitHub Actions' + git config --global user.email 'actions@github.com' + npm run version:bump + npm install --package-lock-only + cd release/app && npm install --package-lock-only && cd ../.. + git add package.json package-lock.json release/app/package.json release/app/package-lock.json + git commit -m "chore: bump version [skip ci]" + git tag "v$(node -p "require('./package.json').version")" + git push --follow-tags + + - name: Build and release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SUPABASE_URL: ${{ vars.SUPABASE_URL }} + SUPABASE_ANON_KEY: ${{ vars.SUPABASE_ANON_KEY }} + run: | + npm run package + npm run release diff --git a/electron-builder.yml b/electron-builder.yml index 4a672cc..6d1836c 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -43,7 +43,7 @@ directories: app: release/app buildResources: assets output: release/build -extraResources: # copy the file or directory with matching names directly into the app’s resources directory (Contents/Resources for MacOS, resources for Linux and Windows) +extraResources: # copy the file or directory with matching names directly into the app's resources directory (Contents/Resources for MacOS, resources for Linux and Windows) - ./assets/** - from: './release/app/database.db' to: 'database.db' @@ -54,3 +54,4 @@ publish: provider: github owner: anserwaseem repo: easy-accounting + releaseType: release diff --git a/package.json b/package.json index c744e1d..9495fc7 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,11 @@ "start:renderer": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack serve --config ./.erb/configs/webpack.config.renderer.dev.ts", "test": "ELECTRON_RUN_AS_NODE=true ./node_modules/.bin/electron ./node_modules/.bin/jest --watchAll=false", "lint": "eslint .", - "prepare": "husky" + "prepare": "husky", + "version:bump": "ts-node scripts/bump-version.ts", + "version:bump:minor": "ts-node scripts/bump-version.ts minor", + "version:bump:major": "ts-node scripts/bump-version.ts major", + "prerelease": "npm run version:bump && git add package.json release/app/package.json" }, "lint-staged": { "*.{js,jsx,ts,tsx}": [ diff --git a/scripts/bump-version.ts b/scripts/bump-version.ts new file mode 100644 index 0000000..f9df0b6 --- /dev/null +++ b/scripts/bump-version.ts @@ -0,0 +1,56 @@ +import fs from 'fs'; +import path from 'path'; + +type BumpType = 'major' | 'minor' | 'patch'; + +// get bump type from command line args +const bumpType = (process.argv[2] as BumpType) || 'patch'; + +// paths to package.json files +const rootPackageJsonPath = path.join(__dirname, '../package.json'); +const releasePackageJsonPath = path.join( + __dirname, + '../release/app/package.json', +); + +// read package.json files +const rootPackageJson = JSON.parse( + fs.readFileSync(rootPackageJsonPath, 'utf8'), +); +const releasePackageJson = JSON.parse( + fs.readFileSync(releasePackageJsonPath, 'utf8'), +); + +// parse current version +const [major, minor, patch] = rootPackageJson.version.split('.').map(Number); + +// calculate new version +let newVersion: string; +switch (bumpType) { + case 'major': + newVersion = `${major + 1}.0.0`; + break; + case 'minor': + newVersion = `${major}.${minor + 1}.0`; + break; + case 'patch': + default: + newVersion = `${major}.${minor}.${patch + 1}`; + break; +} + +// update versions in both package.json files +rootPackageJson.version = newVersion; +releasePackageJson.version = newVersion; + +// write updated package.json files +fs.writeFileSync( + rootPackageJsonPath, + `${JSON.stringify(rootPackageJson, null, 2)}\n`, +); +fs.writeFileSync( + releasePackageJsonPath, + `${JSON.stringify(releasePackageJson, null, 2)}\n`, +); + +console.log(`Version bumped to ${newVersion}`);