Skip to content

Commit

Permalink
[WIP] Add release stage to pipeline
Browse files Browse the repository at this point in the history
Work for #196

And fexes indentation in yaml

Work for #196
  • Loading branch information
atruskie committed Apr 2, 2020
1 parent 53e9efb commit db5118a
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 125 deletions.
25 changes: 20 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": "PowerShell Attach to Host Process",
"type": "PowerShell",
"request": "attach",
"runspaceId": 1,
},
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Launch (current file)",
"script": "${file}",
"args": [],
"cwd": "${file}",
"createTemporaryIntegratedConsole": true
},
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Changelog

## Unreleased

<!--manual-content-insert-here-->

**MAJOR CHANGE: Now runs on .NET Core**

They way you use AnalysisPrograms will not be the same if you are on Linux
or MaxOSX. You will no longer need to install mono, or prefix commands with
`mono`. Please see our
[installing](https://github.com/QutEcoacoustics/audio-analysis/blob/master/docs/installing.md)
documentation for more details!

<!--generated-content-insert-here-->

Expand Down
82 changes: 54 additions & 28 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ schedules:
- cron: 0 0 * * 0
displayName: Weekly Release
branches:
include: master
include:
- master


variables:
Expand Down Expand Up @@ -34,33 +35,58 @@ stages:
- template: build/azure-pipelines-build.yml
- stage: release
jobs:
displayName: Release
variables:
manualRelease: $( contains(variables['Build.SourceVersionMessage'], '[release]')
weeklyRelease: $( eq(variables['Build.Reason'],'Schedule'))
steps:
- pwsh: Write-Host "##vso[task.complete result=Canceled;]Skipping release"
# cancel the job, if
# it is not a weekly release
# and
# it is not a manual release
condition: and(ne(weeklyRelease, true), ne(manualRelease, true))
displayName: Cancel the release unless we want it to continue

# downloads to $(System.ArtifactsDirectory)
- task: DownloadBuildArtifacts@0
inputs:
buildType: current
downloadType: all
displayName: Download previous build artefacts
- job:
displayName: Release
variables:
manualRelease: $( contains(variables['Build.SourceVersionMessage'], '[release]')
weeklyRelease: $( eq(variables['Build.Reason'],'Schedule'))
steps:
- pwsh: Write-Host "##vso[task.complete result=Canceled;]Skipping release"
# cancel the job, if
# it is not a weekly release
# and
# it is not a manual release
condition: and(ne(weeklyRelease, true), ne(manualRelease, true))
displayName: Cancel the release unless we want it to continue

- pwsh: |
Get-ChildItem -recurse $(System.ArtifactsDirectory)
Get-Content $(System.ArtifactsDirectory)/AP_version_vars.txt | Write-Output
displayName: Reconstitute variables
- checkout: self
clean: true
fetchDepth: 200
lfs: false
persistCredentials: true
displayName: "Shallow cloning repo"

# downloads to $(System.ArtifactsDirectory)
- task: DownloadBuildArtifacts@0
inputs:
buildType: current
downloadType: all
displayName: Download previous build artefacts

- pwsh: ./build/
env:
GREN_GITHUB_TOKEN: $(GREN_GITHUB_TOKEN)
displayName: Generate release notes
- pwsh: |
Get-ChildItem -recurse $(System.ArtifactsDirectory)
Get-Content $(System.ArtifactsDirectory)/AP_version_vars.txt | Write-Output
displayName: Reconstitute variables
- pwsh: ./build/release_notes.ps1 v$(AP_Version) -update_changelog
displayName: Generate release notes

- pwsh: git add CHANGELOG.md; git commit -m "Update changelog for v$(AP_Version)" -m "[skip_ci]"
displayName: Commit changelog

- task: GitHubRelease@0
inputs:
action: create
tagSource: auto
tag: v$(AP_Version)
title: $(AP_ReleaseTitle)
releaseNotesSource: inputs
releaseNotes: $(AP_ReleaseMessage)
assets: |
$(Build.ArtifactsDirectory)/**/*.zip
$(Build.ArtifactsDirectory)/**/*.tar.xz
isDraft: true
isPreRelease: true



36 changes: 18 additions & 18 deletions build/azure-pipelines-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
# displayName: debug environment variables
- checkout: self
clean: false
fetchDepth: 100
fetchDepth: 200
lfs: false
persistCredentials: true
displayName: "Shallow cloning repo"
Expand Down Expand Up @@ -140,13 +140,13 @@ jobs:
displayName: Run Acoustics.Test
- task: PublishTestResults@2
inputs:
testResultFormat: VSTest
testResultFiles: '$(Agent.TempDirectory)/Acoustics.Test_Results/**/*.trx'
testRunTitle: "Acoustics.Test for ${{ platform.rid }} ${{ configuration }}"
buildConfig: ${{ configuration }}
buildPlatform: $(platformTag)
publishRunAttachments: true
inputs:
testResultFormat: VSTest
testResultFiles: '$(Agent.TempDirectory)/Acoustics.Test_Results/**/*.trx'
testRunTitle: "Acoustics.Test for ${{ platform.rid }} ${{ configuration }}"
buildConfig: ${{ configuration }}
buildPlatform: $(platformTag)
publishRunAttachments: true
condition: succeededOrFailed()
displayName: Publish Acoustics.Tests results

Expand All @@ -162,18 +162,18 @@ jobs:
--results-directory '$(Agent.TempDirectory)/AED.Test_Results'
--
RunConfiguration.DisableAppDomain=true
# run even if other tests failed
condition: succeededOrFailed()
displayName: Run AED.Test
# run even if other tests failed
condition: succeededOrFailed()
displayName: Run AED.Test
- task: PublishTestResults@2
inputs:
testResultFormat: VSTest
testResultFiles: '$(Agent.TempDirectory)/AED.Test_Results/**/*.trx'
testRunTitle: ".Test for ${{ platform.rid }} ${{ configuration }}"
buildConfig: ${{ configuration }}
buildPlatform: $(platformTag)
publishRunAttachments: true
inputs:
testResultFormat: VSTest
testResultFiles: '$(Agent.TempDirectory)/AED.Test_Results/**/*.trx'
testRunTitle: ".Test for ${{ platform.rid }} ${{ configuration }}"
buildConfig: ${{ configuration }}
buildPlatform: $(platformTag)
publishRunAttachments: true
condition: succeededOrFailed()
displayName: Publish AED.Tests results

Expand Down
45 changes: 0 additions & 45 deletions build/release.ps1

This file was deleted.

116 changes: 87 additions & 29 deletions build/release_notes.ps1
Original file line number Diff line number Diff line change
@@ -1,48 +1,106 @@
#!/usr/bin/pwsh
# Create a release message and update the changelog

# Create a release message and changelog.
# Assumes a tag has not yet been created.
param(
$tag_name
[Parameter(Position = 0, mandatory = $true)]
$tag_name,
[switch]$update_changelog
)

if ($null -eq (Get-Module PowerShellForGitHub)) {
Install-Module -Name PowerShellForGitHub -Force -Scope CurrentUser
Import-Module PowerShellForGitHub
}
$ErrorActionPreference = "Stop"
$DebugPreference = 'Continue'

function formatIssueList {
process {
#Write-debug $_.Issues.Count #+ ($_.Issues -join ","))
$issues = $_.Issues

$issue_string = if ($null -eq $issues -or $issues.Count -eq 0) {
" - "
}
else {
$issues | Join-String { "[$_](https://github.com/QutEcoacoustics/audio-analysis/issues/" + $_.TrimStart("#") + ")" } -Separator ", " -OutputPrefix " - (" -OutputSuffix ")`n "
}

Set-GitHubConfiguration -DefaultOwnerName QutEcoacoustics -DefaultRepositoryName audio-analysis -SuppressTelemetryReminder
$secureString = ($env:RELEASE_NOTES_GITHUB_TOKEN | ConvertTo-SecureString)
$cred = New-Object System.Management.Automation.PSCredential "username is ignored", $secureString
Set-GitHubAuthentication -Credential $cred

function script:exec {
[CmdletBinding()]

param(
[Parameter(Position = 0, Mandatory = 1)][scriptblock]$cmd,
[Parameter(Position = 1, Mandatory = 0)][string]$errorMessage = ("Error executing command: {0}" -f $cmd)
)
& $cmd
if ($lastexitcode -ne 0) {
throw $errorMessage
return "- " + ($_.Title -replace " - ", $issue_string)
}
}

$old_tag_name = exec { git describe --abbrev=0 --always }
#$old_tag_date = exec { git log -1 --format=%ai $old_tag_name }
Write-Output "Creating release message"
# we assumed we've already tagged before describing this release
$old_tag_name = exec { git describe --abbrev=0 --always "HEAD^" }



$commit_summary = exec { git log --no-merges --pretty=format:">>>%h %an - %s%+b" "$old_tag_name...HEAD" -- . }

# look for issue refs in commits
$commits = @()
$current;
foreach ($line in $commit_summary) {
if ($line.StartsWith(">>>")) {
if ($null -ne $current) {
$commits += $current
}

$current = [pscustomobject]@{Title = $line.Substring(3); Issues = @() }
}

$issue_refs = ($line | Select-String "#\d+" -AllMatches).Matches.Value | Where-Object { $null -ne $_ }
$current.Issues += $issue_refs

}
$commits += $current
#Write-debug ($commits | format-table | out-string)
Write-debug ($commits.Count)
# include references to issues
$commit_list = $commits | formatIssueList | Join-String -Separator "`n"

# get any notes from the change log
$changelog_path = "$PSScriptRoot/../CHANGELOG.md"
$changelog = Get-Content $changelog_path -Raw
# find notes and insertion point
$changelog_regex = "<!--manual-content-insert-here-->([\s\S]*)<!--generated-content-insert-here-->(\s)"
if (-not ($changelog -match $changelog_regex)) {
throw "Changelog does not have insertion tokens"
}

$notes = [string]::IsNullOrWhiteSpace($Matches[1]) ? $null : "### Notes`n`n" + $Matches[1].Trim()

$release_title = "Ecoacoustics Audio Analysis Software $tag_name"
$changelog_title = "## $release_title $(Get-Date -Format 'yyyy-MM-dd')"
$compare_message = "[Compare $old_tag_name...$tag_name](https://github.com/QutBioacoustics/audio-analysis/compare/$old_tag_name...$tag_name)"

$release_message = @"
Version $tag_name
$notes
### Details
$compare_message
$commit_list
"@

$changelog_changes = "$changelog_title`n`n$release_message"
if ($update_changelog) {
$replace = "<!--manual-content-insert-here-->`n`n`n`n<!--generated-con
tent-insert-here-->`n`n$changelog_changes"
$changelog -replace $changelog_regex, $replace | Out-File $changelog_path -Encoding utf8NoBOM
}
else {
Write-Debug "Changelog changes:`n$changelog_changes"
}


# $env:ApReleaseMessage = $release_message
# $env:ApReleaseTitle = $release_title

Write-Debug "Release message:`n$release_title`n$release_message"

# list all issues and PRs


Write-Debug "commit count: $($commits.Count)"

# list all commits
# link author
# cite issues
Write-Output "##vso[task.setvariable variable=AP_ReleaseTitle]$release_title"
Write-Output "##vso[task.setvariable variable=AP_ReleaseMessage]$release_message"

0 comments on commit db5118a

Please sign in to comment.