Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PolarGoose committed Oct 11, 2020
0 parents commit 57df114
Show file tree
Hide file tree
Showing 21 changed files with 1,045 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
77 changes: 77 additions & 0 deletions .github/workflows/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
Function Info($msg) {
Write-Host -ForegroundColor DarkGreen "`nINFO: $msg`n"
}

Function Error($msg) {
Write-Host `n`n
Write-Error $msg
exit 1
}

Function CheckReturnCodeOfPreviousCommand($msg) {
if(-Not $?) {
Error "${msg}. Error code: $LastExitCode"
}
}

Function CreateZipArchive($file, $archiveFullName) {
Info "Create zip archive: `n '$archiveFullName' from file `n '$file'"
Compress-Archive -Force -Path $file -DestinationPath $archiveFullName
}

Function CopyFile($file, $dstFolder) {
Info "Copy `n '$file' to `n '$dstFolder'"
New-Item -Force -ItemType "directory" $dstFolder > $null
Copy-Item -Force -Path $file -Destination $dstFolder > $null
}

Function GetInformationalVersion() {
$gitCommand = Get-Command -ErrorAction Stop -Name git

$tag = & $gitCommand describe --exact-match --tags HEAD
if(-Not $?) {
Info "The commit is not tagged. Use 'v0.0.0-dev' as a version instead"
$tag = "v0.0.0-dev"
}

$commitHash = & $gitCommand rev-parse --short HEAD
CheckReturnCodeOfPreviousCommand "Failed to get git commit hash"

return "$($tag.Substring(1))~$commitHash"
}

Function ExtractVersion($informationalVersion) {
if($informationalVersion -match "^([0-9]+\.[0-9]+\.[0-9])\.*") {
return $Matches[1]
}
Error "Failed to extract version from '$informationalVersion'"
}

Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"

$root = Resolve-Path "$PSScriptRoot/../.."
$projectName = "CoffeeBean"
$publishDir = "$root/Build/Publish"
$slnFile = "$root/$projectName.sln"
$msbuild = Get-Command "C:\Program Files (x86)\Microsoft Visual Studio\2019\*\MSBuild\Current\Bin\MSBuild.exe"
$informationalVersion = GetInformationalVersion
$version = ExtractVersion $informationalVersion

Info "Build project using MSBuild"
& $msbuild `
/property:Version=$version `
/property:InformationalVersion=$informationalVersion `
/property:DebugType=None `
/property:Configuration=Release `
/property:Platform=x86 `
$slnFile
CheckReturnCodeOfPreviousCommand "Failed to build the project"

CopyFile $root/Build/Release/${projectName}.exe $publishDir
CreateZipArchive $publishDir/${projectName}.exe $publishDir/${projectName}

if ($LastExitCode -ne 0) {
Error "LastExitCode is $LastExitCode at the end of the script. Should be 0"
}
15 changes: 15 additions & 0 deletions .github/workflows/continuous-integration-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on: push

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2.3.3
- run: .github/workflows/build.ps1
- uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: true
files: Build/Publish/*.zip
Loading

0 comments on commit 57df114

Please sign in to comment.