Skip to content

Commit

Permalink
Update build process
Browse files Browse the repository at this point in the history
  • Loading branch information
r15ch13 committed May 6, 2019
1 parent abe1ec5 commit 027ec49
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
packages/
packages/
build/
dist/
28 changes: 28 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "{build}-{branch}"
image: Visual Studio 2017

init:
- ps: '(Get-ChildItem -Path "Env:").Where({ $_.Name -match "^(?:BH|CI(?:_|$)|APPVEYOR)" })'
install:
- ps: .\install.ps1
build_script:
- ps: .\build.ps1
after_build:
- ps: .\release.ps1
- on:
APPVEYOR_REPO_TAG: true

artifacts:
- path: 'dist\*'
name: release

deploy:
description: '$(GITHUB_RELEASE_NOTES)'
provider: GitHub
auth_token:
secure: ethbC0/KQirXVxmOh234Bk0DxeBVAPqqi1ZklZtPCtTeAY8kK/b1MUlK05v3N1GO
artifact: 'release'
draft: false
prerelease: false
on:
APPVEYOR_REPO_TAG: true
43 changes: 25 additions & 18 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
Param([Switch]$Fast)
Push-Location $psscriptroot
. "$psscriptroot\..\..\lib\install.ps1"
Push-Location $PSScriptRoot

if(!$Fast) {
Write-Host "Install dependencies ..."
Invoke-Expression "$psscriptroot\install.ps1"
}
# Prepare
$build = "$PSScriptRoot\build"
$dist = "$PSScriptRoot\dist"
$src = "$PSScriptRoot\src"
New-Item -ItemType Directory -Path $build -ErrorAction SilentlyContinue | Out-Null
New-Item -ItemType Directory -Path $dist -ErrorAction SilentlyContinue | Out-Null
Remove-Item "$build\*" -Recurse -Force | Out-Null
Remove-Item "$dist\*" -Recurse -Force | Out-Null

$output = "$psscriptroot\bin"
if(!$Fast) {
Get-ChildItem "$psscriptroot\packages\Newtonsoft.*\lib\net45\*.dll" -File | ForEach-Object { Copy-Item $_ $output }
}
# Build
Copy-Item "$PSScriptRoot\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll" $build
Copy-Item "$PSScriptRoot\packages\Newtonsoft.Json.Schema\lib\net45\Newtonsoft.Json.Schema.dll" $build
Write-Output 'Compiling Scoop.Validator.cs ...'
& "$psscriptroot\packages\Microsoft.Net.Compilers\tools\csc.exe" /deterministic /platform:anycpu /nologo /optimize /target:library /reference:"$output\Newtonsoft.Json.dll","$output\Newtonsoft.Json.Schema.dll" /out:"$output\Scoop.Validator.dll" Scoop.Validator.cs
& "$PSScriptRoot\packages\Microsoft.Net.Compilers\tools\csc.exe" /deterministic /platform:anycpu /nologo /optimize /target:library /reference:"$build\Newtonsoft.Json.dll","$build\Newtonsoft.Json.Schema.dll" /out:"$build\Scoop.Validator.dll" "$src\Scoop.Validator.cs"
Write-Output 'Compiling validator.cs ...'
& "$psscriptroot\packages\Microsoft.Net.Compilers\tools\csc.exe" /deterministic /platform:anycpu /nologo /optimize /target:exe /reference:"$output\Scoop.Validator.dll","$output\Newtonsoft.Json.dll","$output\Newtonsoft.Json.Schema.dll" /out:"$output\validator.exe" validator.cs
& "$PSScriptRoot\packages\Microsoft.Net.Compilers\tools\csc.exe" /deterministic /platform:anycpu /nologo /optimize /target:exe /reference:"$build\Scoop.Validator.dll","$build\Newtonsoft.Json.dll","$build\Newtonsoft.Json.Schema.dll" /out:"$build\validator.exe" "$src\validator.cs"

# Checksums
Write-Output 'Computing checksums ...'
Remove-Item "$psscriptroot\bin\checksum.sha256" -ErrorAction Ignore
Remove-Item "$psscriptroot\bin\checksum.sha512" -ErrorAction Ignore
Get-ChildItem "$psscriptroot\bin\*" -Include *.exe,*.dll | ForEach-Object {
"$(compute_hash $_ 'sha256') *$($_.Name)" | Out-File "$psscriptroot\bin\checksum.sha256" -Append -Encoding oem
"$(compute_hash $_ 'sha512') *$($_.Name)" | Out-File "$psscriptroot\bin\checksum.sha512" -Append -Encoding oem
Get-ChildItem "$build\*" -Include *.exe,*.dll -Recurse | ForEach-Object {
$checksum = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash.ToLower()
"$checksum *$($_.FullName.Replace($build, '').TrimStart('\'))" | Tee-Object -FilePath "$build\checksums.sha256" -Append
}

# Package
7z a "$dist\validator.zip" "$build\*"
Get-ChildItem "$dist\*" | ForEach-Object {
$checksum = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash.ToLower()
"$checksum *$($_.Name)" | Tee-Object -FilePath "$dist\$($_.Name).sha256" -Append
}
Pop-Location
35 changes: 35 additions & 0 deletions release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if(!$env:APPVEYOR_REPO_TAG) {
return
}

Write-Output 'Generating release notes ...'
#region GitHub release notes
$previousRelease = (Invoke-RestMethod -Uri "https://api.github.com/repos/$env:APPVEYOR_REPO_NAME/releases/latest?access_token=$env:GITHUB_ACCESS_TOKEN" -Verbose)
Write-Host "Previous Release: $($previousRelease.name) ($($previousRelease.target_commitish))"
$compare = (Invoke-RestMethod -Uri "https://api.github.com/repos/$env:APPVEYOR_REPO_NAME/compare/$($previousRelease.target_commitish)...$env:APPVEYOR_REPO_COMMIT`?access_token=$env:GITHUB_ACCESS_TOKEN" -Verbose)
$releaseNotes = "## Release Notes`n#### Version [$env:APPVEYOR_REPO_TAG_NAME](https://github.com/$env:APPVEYOR_REPO_NAME/tree/$env:APPVEYOR_REPO_TAG_NAME)`n"

if($null -ne $compare.commits -and $compare.commits.Length -gt 0) {
$releaseNotes += "`nCommit | Description`n--- | ---`n"
$contributions = @{}
$compare.commits | Sort-Object -Property @{Expression={$_.commit.author.date};} -Descending | ForEach-Object {
$commitMessage = $_.commit.message.Replace("`r`n"," ").Replace("`n"," ");
if ($commitMessage.ToLower().StartsWith('merge') -or
$commitMessage.ToLower().StartsWith('merging') -or
$commitMessage.ToLower().StartsWith('private')) {
continue
}
$releaseNotes += "[``$($_.sha.Substring(0, 7))``](https://github.com/$env:APPVEYOR_REPO_NAME/tree/$($_.sha)) | $commitMessage`n"
$contributions.$($_.author.login)++
}
$releaseNotes += "`nContributor | Commits`n--- | ---`n"
$contributions.GetEnumerator() | Sort-Object -Property @{Expression={$_.Value}} -Descending | ForEach-Object {
$releaseNotes += "@$($_.Name) | $($_.Value)`n"
}
} else {
$releaseNotes += "There are no new items for this release."
}

$env:GITHUB_RELEASE_NOTES = $releaseNotes
Write-Output $releaseNotes
#endregion

0 comments on commit 027ec49

Please sign in to comment.