Skip to content

Commit

Permalink
refactor: refactor code with the coding standard of Golang (#6)
Browse files Browse the repository at this point in the history
* style: change resources files

* style: modify .gitignore

* style: change resources files

* feat: modify GitHub Actions configs

* docs: add GitHub Actions badge to README.md

* feat: modify GitHub Actions configs

* docs: add dev CI badge to README.md

Co-authored-by: JyCyunMe <[email protected]>
  • Loading branch information
JyCyunMe and JyCyun committed May 29, 2021
1 parent 0abd8fd commit c8bc537
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 37 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/github_build_dev_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ jobs:
echo "BUILD_PATH=$BUILD_PATH" >> $env:GITHUB_ENV
$BUILD_VERSION=cat .\versioninfo.json | jq -r '.StringFileInfo.ProductVersion'
echo "BUILD_VERSION=$BUILD_VERSION" >> $env:GITHUB_ENV
echo "Build Version: $BUILD_VERSION"
$GIT_TAG="$BUILD_VERSION$(${env:GIT_BRANCH} -ne 'release' ? '-pre' : '')"
echo "Build Version: v$BUILD_VERSION"
$GIT_TAG="v$BUILD_VERSION$(${env:GIT_BRANCH} -ne 'release' ? '-pre' : '')"
echo "GIT_TAG=$GIT_TAG" >> $env:GITHUB_ENV
echo "Current Tag: $GIT_TAG"
Expand All @@ -81,6 +81,8 @@ jobs:
run: |
go version
go env
go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
go generate -x
mkdir -p .\build
# 运行Golang测试
Expand Down Expand Up @@ -112,8 +114,8 @@ jobs:
run: |
cd $env:BUILD_PATH
mkdir -p .\publish
$BUILD_X64_FILENAME="Clash.Mini_${env:GIT_BRANCH}_${env:BUILD_VERSION}_${env:SHORT_SHA}_x64.exe"
$BUILD_X86_FILENAME="Clash.Mini_${env:GIT_BRANCH}_${env:BUILD_VERSION}_${env:SHORT_SHA}_x86.exe"
$BUILD_X64_FILENAME="Clash.Mini_${env:GIT_BRANCH}_v${env:BUILD_VERSION}_${env:SHORT_SHA}_x64.exe"
$BUILD_X86_FILENAME="Clash.Mini_${env:GIT_BRANCH}_v${env:BUILD_VERSION}_${env:SHORT_SHA}_x86.exe"
echo "BUILD_X64_FILENAME=$BUILD_X64_FILENAME" >> $env:GITHUB_ENV
echo "BUILD_X86_FILENAME=$BUILD_X86_FILENAME" >> $env:GITHUB_ENV
cp .\Clash.Mini_dev_*.exe .\publish\
Expand Down
65 changes: 56 additions & 9 deletions .github/workflows/github_build_release_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,61 @@ jobs:
echo "BUILD_PATH=$BUILD_PATH" >> $env:GITHUB_ENV
$BUILD_VERSION=cat .\versioninfo.json | jq -r '.StringFileInfo.ProductVersion'
echo "BUILD_VERSION=$BUILD_VERSION" >> $env:GITHUB_ENV
echo "Build Version: $BUILD_VERSION"
$GIT_TAG="$BUILD_VERSION$(${env:GIT_BRANCH} -ne 'release' ? '-pre' : '')"
echo "Build Version: v$BUILD_VERSION"
$GIT_TAG="v$BUILD_VERSION$(${env:GIT_BRANCH} -ne 'release' ? '-pre' : '')"
echo "GIT_TAG=$GIT_TAG" >> $env:GITHUB_ENV
echo "Current Tag: $GIT_TAG"
# # 构建前检查
# - name: Check on Failures ❌
# if: success()
# shell: pwsh
# run: |
# 构建前检查
- name: Check on Failures ❌
if: success()
shell: pwsh
run: |
$NOT_PASSED=0
echo "Build Version: v${env:BUILD_VERSION}`nCurrent Tag: ${env:GIT_TAG}`nLatest Tag: ${env:GIT_TAG_LATEST}`n"
if (!(${env:GIT_TAG} -match ${env:VERSION_REGEXP}) -or ${env:GIT_TAG} -eq '') {
$NOT_PASSED=1
echo "Cannot get the version information."
}
if ($NOT_PASSED -eq 0) {
$INTERNAL_VERSION_REGEXP='^(\d+\.\d+\.\d+)(\.\d+)?$'
$fileVersion=cat .\versioninfo.json | jq -r '.FixedFileInfo.FileVersion'
$fileVersion=(echo $fileVersion | jq -r '.Major, .Minor, .Patch, .Build') -join '.'
$fileVersion=[regex]::Match($fileVersion, $INTERNAL_VERSION_REGEXP)
if (!$fileVersion.success) {
$NOT_PASSED=-1
} else {
$fileVersion=$fileVersion.Groups[1].Value
}
if ($NOT_PASSED -eq 0) {
$productVersion=cat .\versioninfo.json | jq -r '.FixedFileInfo.ProductVersion'
$productVersion=(echo $productVersion | jq -r '.Major, .Minor, .Patch, .Build') -join '.'
$productVersion=[regex]::Match($productVersion, $INTERNAL_VERSION_REGEXP)
if (!$productVersion.success) {
$NOT_PASSED=-1
} else {
$productVersion=$productVersion.Groups[1].Value
}
}
}
if (($NOT_PASSED -eq 0) -and (($productVersion -ne $fileVersion) -or (${env:BUILD_VERSION} -ne $productVersion))) {
$NOT_PASSED=1
echo "The version information has some differences.`nPlease check `"versioninfo.json`""
}
if (($NOT_PASSED -eq 0) -and ((${env:GIT_TAG_LATEST} -ne '' -and ${env:GIT_TAG}.replace('-pre', '') -lt ${env:GIT_TAG_LATEST}.replace('-pre', '') -or
(${env:GIT_TAG}.replace('-pre', '') -eq ${env:GIT_TAG_LATEST}.replace('-pre', '') -and (${env:GIT_TAG}.contains('-pre') -or !${env:GIT_TAG_LATEST}.contains('-pre')))))) {
$NOT_PASSED=1
echo "A newer or the current version already exists."
}
if ($NOT_PASSED -ge 0) {
echo "Check the version information is not passed."
echo "This build has been aborted."
exit 1
}
# 配置Golang环境
- name: Setup Go Environment 📍
Expand All @@ -85,6 +130,8 @@ jobs:
run: |
go version
go env
go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
go generate -x
mkdir -p .\build
# 运行Golang测试
Expand Down Expand Up @@ -117,8 +164,8 @@ jobs:
run: |
cd $env:BUILD_PATH
mkdir -p .\publish
$BUILD_X64_FILENAME="Clash.Mini_${env:GIT_BRANCH}_${env:BUILD_VERSION}_x64.exe"
$BUILD_X86_FILENAME="Clash.Mini_${env:GIT_BRANCH}_${env:BUILD_VERSION}_x86.exe"
$BUILD_X64_FILENAME="Clash.Mini_${env:GIT_BRANCH}_v${env:BUILD_VERSION}_x64.exe"
$BUILD_X86_FILENAME="Clash.Mini_${env:GIT_BRANCH}_v${env:BUILD_VERSION}_x86.exe"
echo "BUILD_X64_FILENAME=$BUILD_X64_FILENAME" >> $env:GITHUB_ENV
echo "BUILD_X86_FILENAME=$BUILD_X86_FILENAME" >> $env:GITHUB_ENV
cp .\Clash.Mini_*.exe .\publish\
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Project files
resource_amd64.syso
resource_386.syso

### Go template
# Binaries for programs and plugins
*.exe
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
</a>
![Issues](https://img.shields.io/github/issues/Clash-Mini/Clash.Mini?color=orange&style=flat-square)
![RunTime](https://img.shields.io/static/v1?label=runtime&message=GO&color=blue&style=flat-square)
<br>
[![Build Release Windows](https://github.com/Clash-Mini/Clash.Mini/actions/workflows/github_build_release_windows.yml/badge.svg)](https://github.com/Clash-Mini/Clash.Mini/actions/workflows/github_build_release_windows.yml)
[![Build Dev Windows](https://github.com/Clash-Mini/Clash.Mini/actions/workflows/github_build_dev_windows.yml/badge.svg)](https://github.com/Clash-Mini/Clash.Mini/actions/workflows/github_build_dev_windows.yml)

</div>

Expand Down
2 changes: 1 addition & 1 deletion RELEASELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### **v0.1.2-pre**

Release on *2021-05-29 20:30*
Release on *2021-05-29 23:30*

**Features**

Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//go:generate goversioninfo -icon=resource/Clash.Mini.ico -manifest=resource/goversioninfo_amd64.exe.manifest -o resource_amd64.syso
//go:generate goversioninfo -icon=resource/Clash.Mini.ico -manifest=resource/goversioninfo_386.exe.manifest -o resource_386.syso
//go:generate goversioninfo -manifest=./resource/Clash.Mini_x64.exe.manifest -64 -o ./resource_amd64.syso
//go:generate goversioninfo -manifest=./resource/Clash.Mini_x86.exe.manifest -o ./resource_386.syso

//GOOS=windows GOARCH=amd64 go build -ldflags "-H=windowsgui -s -w" -o Clash.Mini_x64.exe
//GOOS=windows GOARCH=386 go build -ldflags "-H=windowsgui -s -w" -o Clash.Mini_x86.exe
//GOOS=windows GOARCH=amd64 go build -ldflags "-H=windowsgui -s -w" -o ./Clash.Mini_x64.exe
//GOOS=windows GOARCH=386 go build -ldflags "-H=windowsgui -s -w" -o ./Clash.Mini_x86.exe
package main

import (
Expand Down
File renamed without changes.
File renamed without changes.
Binary file removed resource_386.syso
Binary file not shown.
Binary file removed resource_amd64.syso
Binary file not shown.
38 changes: 19 additions & 19 deletions versioninfo.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"FixedFileInfo": {
"FileVersion": {
"Major": 0,
"Minor": 0,
"Patch": 1,
"Build": 0
"Major": 0,
"Minor": 1,
"Patch": 2,
"Build": 0
},
"ProductVersion": {
"Major": 0,
"Minor": 0,
"Patch": 1,
"Build": 0
"Major": 0,
"Minor": 1,
"Patch": 2,
"Build": 0
},
"FileFlagsMask": "3f",
"FileFlags ": "00",
Expand All @@ -20,24 +20,24 @@
},
"StringFileInfo": {
"Comments": "",
"CompanyName": "",
"CompanyName": "Maze",
"FileDescription": "Clash.Mini",
"FileVersion": "",
"InternalName": "",
"InternalName": "Clash.Mini",
"LegalCopyright": "Copyright © Maze",
"LegalTrademarks": "",
"OriginalFilename": "Clash.Mini.exe",
"PrivateBuild": "",
"ProductName": "Clash.Mini",
"ProductVersion": "v0.1.1",
"ProductVersion": "0.1.2",
"SpecialBuild": ""
},
"VarFileInfo": {
"Translation": {
"LangID": "0409",
"CharsetID": "04B0"
}
},
"IconPath": "",
"ManifestPath": ""
"VarFileInfo": {
"Translation": {
"LangID": "0804",
"CharsetID": "04B0"
}
},
"IconPath": "./resource/Clash.Mini.ico",
"ManifestPath": ""
}

0 comments on commit c8bc537

Please sign in to comment.