Skip to content

Commit

Permalink
💚 Improve version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
mokeyish committed Sep 25, 2024
1 parent d8897bf commit cfb8156
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 19 deletions.
38 changes: 25 additions & 13 deletions .github/workflows/release.yml → .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
name: Release Obsidian plugin
name: Bump Version

on:
workflow_dispatch:
inputs:
version:
description: 'version'
bump:
description: 'Bump version'
required: true
type: choice
options: [major, premajor, minor, preminor, patch, prepatch, prerelease]
default: 'patch'

env:
PLUGIN_NAME: obsidian-enhancing-export

jobs:
bump:
runs-on: ubuntu-latest
outputs:
version: ${{env.version}}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -22,15 +27,21 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
- uses: pnpm/action-setup@v4
with:
version: latest
- name: Install Dependencies
run: pnpm install
- name: Create local changes
run: |
npm run version ${{ github.event.inputs.version }}
npm run version-bump ${{ github.event.inputs.bump }}
echo "version=$(node version.mjs)" >> "$GITHUB_ENV"
- name: Commit files
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -a -m "🔖 Bump version number to ${{ github.event.inputs.version }}"
git tag -a ${{ github.event.inputs.version }} -m ""
git commit -a -m "🔖 Bump version number to $version"
git tag -a $version -m ""
- name: Push changes
uses: ad-m/github-push-action@master
with:
Expand All @@ -44,18 +55,19 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.version }}
ref: ${{ needs.bump.outputs.version }}
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
- uses: pnpm/action-setup@v4
with:
version: 9
version: latest
- name: Install Dependencies
run: pnpm install
- name: Build
id: build
run: |
pnpm install
npm run build
mkdir ${{ env.PLUGIN_NAME }}
cp dist/* ${{ env.PLUGIN_NAME }}
Expand All @@ -67,10 +79,10 @@ jobs:
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ github.event.inputs.version }}
VERSION: ${{ needs.bump.outputs.version }}
with:
tag_name: ${{ github.event.inputs.version }}
release_name: ${{ github.event.inputs.version }}
tag_name: ${{ needs.bump.outputs.version }}
release_name: ${{ needs.bump.outputs.version }}
draft: false
prerelease: false

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"dev": "vite build -w -m development",
"build": "vite build",
"version": "node version-bump.mjs",
"version-bump": "node version.mjs bump",
"version": "node version.mjs",
"lint": "eslint --ext .ts,.js src",
"lint-fix": "eslint --fix --ext .ts,.js src",
"format-check": "prettier --check \"src/**/*.ts\"",
Expand Down
42 changes: 37 additions & 5 deletions version-bump.mjs → version.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
import { readFileSync, writeFileSync } from 'fs';
import { exec } from 'child_process';
import process from 'process';
import console from 'console';
import process, { exit } from 'process';
import { parse } from 'semver';



const ReleaseTypes = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'];

let bump = 'patch';

let cmdType = 'version';

for (let arg of process.argv.slice(2)) {
arg = arg.toLowerCase();
if (arg === 'bump') {
cmdType = 'bump';
continue;
}
if (ReleaseTypes.includes(arg)) {
bump = arg;
break;
}
}


const pkg = JSON.parse(readFileSync('package.json', 'utf8'));

const version = process.argv.at(2) ?? pkg.version;

if (version != pkg.version) {
pkg.version = version;
if (cmdType === 'version') {
console.log(pkg.version);
exit();
}

let semver = parse(pkg.version);

if (semver) {
semver = semver.inc(bump);
}

if (semver?.toString() != pkg.version) {
pkg.version = semver.version;
writeFileSync('package.json', `${JSON.stringify(pkg, null, 2)}\n`);
exec('git add package.json');
}
Expand All @@ -26,4 +58,4 @@ let versions = JSON.parse(readFileSync('versions.json', 'utf8'));
versions[pkg.version] = minAppVersion;
writeFileSync('versions.json', JSON.stringify(versions, null, '\t'));

exec('git add manifest.json versions.json');
exec('git add manifest.json versions.json');

0 comments on commit cfb8156

Please sign in to comment.