Skip to content

Commit

Permalink
Version for web
Browse files Browse the repository at this point in the history
  • Loading branch information
HeHang0 committed Nov 2, 2023
1 parent 23f3f2e commit 71a3e45
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<Versaion>(.*?)</Version>').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:
Expand Down
20 changes: 20 additions & 0 deletions web/zip.ts
Original file line number Diff line number Diff line change
@@ -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>(.*)<\/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',
Expand Down Expand Up @@ -53,6 +72,7 @@ export const ZipPlugin = function (
name: 'vite-plugin-auto-zip',
apply: 'build',
closeBundle() {
buildVersion();
makeZip();
}
};
Expand Down

0 comments on commit 71a3e45

Please sign in to comment.