From e4822ac7cb0595481e9578f5665d43fe20a54dba Mon Sep 17 00:00:00 2001 From: Gerhard Tan Date: Sat, 17 Feb 2024 20:44:38 +0800 Subject: [PATCH] Upload the build output of pull requests (#122) * Upload the build output of pull requests * Fix incorrect commit sha --- .github/workflows/tests.yml | 22 ++++++++++++++++++++++ iconize.go | 6 +++--- installer/build.bat | 2 +- resource.go | 9 +++++---- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2367eb16..10a0e654 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,10 +25,32 @@ jobs: run: | for /f "usebackq delims=" %%i in (`vswhere.exe -latest -property installationPath`) do echo %%i\VC\Auxiliary\Build>>%GITHUB_PATH% + - name: Add commit hash to version number + shell: powershell + if: github.event_name == 'pull_request' + env: + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + $versionFile = ".\pkg\version\version.go" + $rev = [UInt16]("0x" + $env:HEAD_SHA.Substring(0, 4)) + $version = (findstr /r "Number.*=.*[0-9.]*" $versionFile | Select-Object -First 1 | ConvertFrom-StringData).Get_Item("Number") + $newVersion = $version.Substring(0, $version.Length - 1) + ".$rev" + '"' + (Get-Content $versionFile).Replace($version, $newVersion) | Set-Content $versionFile + - name: Build shell: cmd run: build.bat + - name: Upload + uses: actions/upload-artifact@v4 + if: github.event_name == 'pull_request' + with: + name: build + path: | + bin/*.exe + bin/*.zip + retention-days: 5 + test: name: Go runs-on: windows-latest diff --git a/iconize.go b/iconize.go index 845924de..f3d34c14 100644 --- a/iconize.go +++ b/iconize.go @@ -6,7 +6,6 @@ package main import ( "flag" - "log" "os" "os/exec" "path/filepath" @@ -25,7 +24,8 @@ func init() { func main() { files, err := os.ReadDir(dir) if err != nil { - log.Fatal(err) + println(err.Error()) + os.Exit(1) } for _, f := range files { if f.IsDir() { @@ -40,7 +40,7 @@ func main() { res, err := exec.Command(".deps/convert.exe", "-background", "none", path, "-define", "icon:auto-resize=256,192,128,96,64,48,40,32,24,20,16", "-compress", "zip", output).CombinedOutput() if err != nil { - log.Fatalf("Failed to convert icon: %s", string(res)) + println(err.Error(), string(res)) } } } diff --git a/installer/build.bat b/installer/build.bat index 12260300..cf5e39e9 100644 --- a/installer/build.bat +++ b/installer/build.bat @@ -43,7 +43,7 @@ if "%WIX%"=="" ( "%WindowsSdkVerBinPath%x86\MsiTran" -g %MSI_FILE% !WIX_LANG_MSI! %PLAT_DIR%\!LANG_CODE! || goto :error "%WindowsSdkVerBinPath%x86\MsiDb" -d %MSI_FILE% -r %PLAT_DIR%\!LANG_CODE! || goto :error ) - windres -DARCH=%ARCH% -DVERSION_ARRAY=%VERSION:.=,%,0 -DVERSION_STR=%VERSION% -DMSI_FILE=%MSI_FILE:\=\\% -i setup\resource.rc -o %PLAT_DIR%\rsrc.o -O coff -c 65001 -F !RES%ARCH%! || goto :error + windres -DARCH=%ARCH% -DVERSION_ARRAY=%VERSION:.=,% -DVERSION_STR=%VERSION% -DMSI_FILE=%MSI_FILE:\=\\% -i setup\resource.rc -o %PLAT_DIR%\rsrc.o -O coff -c 65001 -F !RES%ARCH%! || goto :error cl /Fe..\bin\frpmgr-%VERSION%-setup-%ARCH%.exe /Fo%PLAT_DIR%\setup.obj /utf-8 setup\setup.c /link /subsystem:windows %PLAT_DIR%\rsrc.o shlwapi.lib msi.lib user32.lib advapi32.lib goto :eof diff --git a/resource.go b/resource.go index cb2dd296..593e979b 100644 --- a/resource.go +++ b/resource.go @@ -6,7 +6,7 @@ package main import ( "fmt" - "log" + "os" "os/exec" "path/filepath" "strings" @@ -15,14 +15,15 @@ import ( ) var ( - versionArray = strings.ReplaceAll(version.Number, ".", ",") + ",0" + versionArray = strings.ReplaceAll(version.Number, ".", ",") archMap = map[string]string{"amd64": "pe-x86-64", "386": "pe-i386"} ) func main() { rcFiles, err := filepath.Glob("cmd/*/*.rc") if err != nil { - log.Fatal(err) + println(err.Error()) + os.Exit(1) } for _, rc := range rcFiles { for goArch, resArch := range archMap { @@ -30,7 +31,7 @@ func main() { res, err := exec.Command("windres", "-DVERSION_ARRAY="+versionArray, "-DVERSION_STR="+version.Number, "-i", rc, "-o", output, "-O", "coff", "-c", "65001", "-F", resArch).CombinedOutput() if err != nil { - log.Fatalf("Failed to compile resource: %s", string(res)) + println(err.Error(), string(res)) } } }