From cd32a8b86d9d1ccfc4d2f6e2498b3228cc2f1ce0 Mon Sep 17 00:00:00 2001 From: Romain Batigne Date: Fri, 26 Jul 2024 19:04:05 +0200 Subject: [PATCH] feat: autorelease with github actions --- .github/workflows/release.yml | 29 ++++++++++++++++++++++ .gitignore | 1 + index.js | 2 +- package-lock.json | 2 +- package.json | 15 ++++++------ release.config.js | 46 +++++++++++++++++++++++++++++++++++ release.sh | 10 ++++++++ 7 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 release.config.js create mode 100644 release.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..27128af --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: Release + +on: + push: + branches: [master] + +jobs: + release: + name: Release + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: 18.x + - name: Install pkg globally + run: npm install -g pkg + - name: Install dependencies + run: npx ci + - name: Install semantic-release extra plugins + run: npm install -D semantic-release@22.0.12 @semantic-release/exec @semantic-release/changelog @semantic-release/git @semantic-release/github + - name: Release + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + run: npx semantic-release + diff --git a/.gitignore b/.gitignore index ac65806..225a551 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ TODO.md /musicbee-navidrome-sync.exe /dist/ +/.dist/ /MusicBee_Export.csv /navidrome.db /backups/ diff --git a/index.js b/index.js index 46a6e0b..800930f 100644 --- a/index.js +++ b/index.js @@ -51,7 +51,7 @@ program program .name('musicbee-navidrome-sync') .description( - 'MusicBee to Navidrome Sync (MBNDS) : Tools to sync MusicBee DB to Navidrome DB\nhttps://github.com/rombat/musicbee-navidrome-sync' + `MusicBee to Navidrome Sync (MBNDS) : Tools to sync MusicBee DB to Navidrome DB (v${packageJson.version})\nhttps://github.com/rombat/musicbee-navidrome-sync` ) .version(packageJson.version, '-v, --version', 'output the current version'); diff --git a/package-lock.json b/package-lock.json index 858a171..22edb78 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "prettier": "^3.3.3" }, "engines": { - "node": ">=16.0.0" + "node": ">=18.0.0" } }, "node_modules/@gar/promisify": { diff --git a/package.json b/package.json index ce82340..2c61baf 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "fullSync": "node index.js fullSync", "albumsSync": "node index.js albumsSync", "artistsSync": "node index.js artistsSync", - "build": "pkg ." + "build": "sh ./release.sh" }, "author": "rombat", "license": "GNU GPL V3.0", @@ -22,9 +22,13 @@ "sequelize": "^6.37.3", "sqlite3": "^5.1.7" }, + "devDependencies": { + "prettier": "^3.3.3" + }, "engines": { - "node": ">=16.0.0" + "node": ">=18.0.0" }, + "private": true, "bin": "index.js", "pkg": { "assets": [ @@ -32,11 +36,6 @@ ], "targets": [ "node18-win-x64" - ], - "outputPath": "dist", - "outputName": "musicbee-navidrome-sync" - }, - "devDependencies": { - "prettier": "^3.3.3" + ] } } diff --git a/release.config.js b/release.config.js new file mode 100644 index 0000000..4e4c3ca --- /dev/null +++ b/release.config.js @@ -0,0 +1,46 @@ +module.exports = { + branches: ['master'], + plugins: [ + '@semantic-release/commit-analyzer', + { + preset: 'eslint', + releaseRules: [ + { scope: 'no-release', release: false }, + { type: 'chore', release: 'patch' }, + { type: '', release: 'patch' } + ] + }, + [ + '@semantic-release/release-notes-generator', + { + changelogTitle: 'MBNDS CHANGELOG' + } + ], + '@semantic-release/changelog', + [ + '@semantic-release/npm', + { + npmPublish: false + } + ], + [ + '@semantic-release/exec', + { + publishCmd: 'npm run build ${nextRelease.version}' + } + ], + [ + '@semantic-release/github', + { + assets: [{ path: '.dist/musicbee-navidrome-sync_${nextRelease.version}.exe', label: 'MBNDS v${nextRelease.version}' }] + } + ], + [ + '@semantic-release/git', + { + message: 'chore(release): set `package.json` to ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}', + assets: ['package.json', 'CHANGELOG.md'] + } + ] + ] +}; diff --git a/release.sh b/release.sh new file mode 100644 index 0000000..dfde59f --- /dev/null +++ b/release.sh @@ -0,0 +1,10 @@ +set -e +VERSION=${1:-$(node -p "require('./package.json').version")} + +rm -rf .dist +mkdir -p .dist +cp -r index.js package*.json lib .dist +cd .dist +npm install --omit=dev + +pkg -c package.json index.js -o musicbee-navidrome-sync_${VERSION}.exe