From 71a3e45a4b3596447115c4f07e3ed8d291520cba Mon Sep 17 00:00:00 2001 From: He Hang Date: Thu, 2 Nov 2023 16:56:06 +0800 Subject: [PATCH] Version for web --- .github/workflows/web.yml | 9 --------- web/zip.ts | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index eb2d1df..6421489 100644 --- a/.github/workflows/web.yml +++ b/.github/workflows/web.yml @@ -44,15 +44,6 @@ jobs: cd .. copy windows\bin\Release\net472\Musiche.exe web\dist\Musiche.exe copy windows\bin\Publish\net6.0-windows\Musiche.exe web\dist\Musiche.net6.exe - $versionMatch = (Get-Content -Path windows\Musiche.csproj | Select-String -Pattern '(.*?)').Matches - if ($versionMatch.Count -eq 0) { - $version = "2.0.0" - } else { - $version = $versionMatch[0].Groups[1].Value - } - $commitHash = git rev-parse --short HEAD - $combinedVersion = "$version-$commitHash" - $combinedVersion | Out-File -FilePath web\dist\version - name: Upload artifact uses: actions/upload-pages-artifact@v1 with: diff --git a/web/zip.ts b/web/zip.ts index c1e7279..efdb416 100644 --- a/web/zip.ts +++ b/web/zip.ts @@ -1,6 +1,25 @@ import path from 'path'; import fs from 'fs'; import JSZip from 'jszip'; +import { execSync } from 'child_process'; + +function buildVersion(output: string = null) { + if (!output) output = path.resolve('dist'); + const csProj = path.resolve('../windows/Musiche.csproj'); + const text = fs.existsSync(csProj) + ? fs.readFileSync(csProj, { + encoding: 'utf8' + }) + : ''; + const regex = /(.*)<\/Version>/; + const match = regex.exec(text); + const version = (match && match[1]) || '2.0.0'; + const outFile = path.resolve(output, 'version'); + const commitHash = execSync('git rev-parse --short HEAD', { + encoding: 'utf8' + }); + fs.writeFileSync(outFile, `${version}-${commitHash}`); +} export const ZipPlugin = function ( fileName: string = 'web', @@ -53,6 +72,7 @@ export const ZipPlugin = function ( name: 'vite-plugin-auto-zip', apply: 'build', closeBundle() { + buildVersion(); makeZip(); } };