Skip to content

Commit 30a75c6

Browse files
authored
Merge pull request #100 from sqlcollaborative/build
Adding build scripts and changelog
2 parents d4902cd + fc58729 commit 30a75c6

File tree

5 files changed

+171
-16
lines changed

5 files changed

+171
-16
lines changed

build/Get-PRHistory.ps1

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<#
2+
.SYNOPSIS
3+
Creates a Markdown changelog file with markdown formatting.
4+
5+
Original version created by @vexx32
6+
.DESCRIPTION
7+
Uses `git log` to compare the current commit to the last tagged commit,
8+
and parses the output into CSV data. This is then processed and PR body
9+
of submitted Pull Requests are added to the output file.
10+
.PARAMETER Path
11+
The file location to save the markdown text to. The file will be
12+
overwritten if it already contains data.
13+
.PARAMETER CommitID
14+
The commit tag or hash that is used to identify the commit to
15+
compare with. By default, the last value given by `git tag`
16+
will be used.
17+
.PARAMETER HeadCommitID
18+
The commit tag or hash that represents the current version
19+
of the repository. HEAD by default.
20+
.PARAMETER ApiKey
21+
The Github API key to use when looking up commit authors'
22+
Github user names.
23+
.PARAMETER IncludeDetails
24+
Add PR body to each entry in the change log
25+
.PARAMETER Append
26+
Append changelog to the top of the existing file
27+
.EXAMPLE
28+
New-Changelog.ps1 -Path File.md -ApiKey $GHApiKey
29+
Retrieves the commits since the last tagged commit and creates a
30+
Markdown-formatted plaintext file called File.md in the current
31+
location.
32+
.NOTES
33+
The Github API limitation of 60 requests per minute is -barely-
34+
usable without authentication. Authenticated requests have a
35+
substantially higher limit on requests per minute.
36+
#>
37+
[CmdletBinding()]
38+
param(
39+
[Parameter(Mandatory, Position = 0)]
40+
[ValidateScript( { Test-Path $_ -IsValid })]
41+
[string]
42+
$Path,
43+
44+
[Parameter(Position = 1)]
45+
[ValidatePattern('[a-f0-9]{6,40}|v?(\d+\.)+\d+(-\w+\d+)?')]
46+
[string]
47+
$CommitID = (git tag | Select-Object -Last 1),
48+
49+
[Parameter(Position = 2)]
50+
[ValidatePattern('[a-f0-9]{6,40}|v?(\d+\.)+\d+(-\w+\d+)?|HEAD')]
51+
[string]
52+
$HeadCommitID = 'HEAD',
53+
54+
[Parameter()]
55+
[Alias('OauthToken')]
56+
[string]
57+
$ApiKey,
58+
59+
[Parameter()]
60+
[switch]
61+
$IncludeDetails,
62+
63+
[Parameter()]
64+
[switch]
65+
$Append
66+
)
67+
$RequestParams = @{ }
68+
if ($ApiKey) {
69+
$RequestParams = @{
70+
SessionVariable = 'AuthSession'
71+
Headers = @{ Authorization = "token $ApiKey" }
72+
}
73+
Invoke-RestMethod @RequestParams -Uri 'https://api.github.com/' | Out-String | Write-Verbose
74+
}
75+
$gitParams = @(
76+
'--no-pager'
77+
'log'
78+
'--first-parent'
79+
"$CommitID..$HeadCommitID"
80+
'--format="%H"'
81+
'--'
82+
'.'
83+
'":(exclude)*.md"'
84+
)
85+
$commits = & git @gitParams
86+
87+
$prs = @()
88+
foreach ($commit in $commits) {
89+
$result = Invoke-RestMethod @RequestParams -Uri "https://api.github.com/search/issues?q=$($commit)is%3Amerged"
90+
if ($result.total_count -gt 0) {
91+
$prs += $result.items | Sort-Object -Property score -Descending | Select-Object -First 1
92+
}
93+
}
94+
$prs = $prs | Sort-Object -Property number -Unique
95+
$mdTable = @("# Release notes for $CommitID`:")
96+
foreach ($pr in $prs) {
97+
$prData = Invoke-RestMethod @RequestParams -Uri $pr.url
98+
$mdTable += "- ### $($prData.title) (#$($prData.number)) by @$($prData.user.login)"
99+
if ($IncludeDetails -and $prData.body) {
100+
$mdTable += " ------"
101+
foreach ($line in $prData.body.Split("`n")) {
102+
$mdTable += " $line"
103+
}
104+
}
105+
}
106+
if ($Append) {
107+
if (Test-Path $Path) {
108+
$currentContent = Get-Content -Path $Path
109+
}
110+
else { $currentContent = @() }
111+
$mdTable + $currentContent | Set-Content -Path $Path
112+
}
113+
else { $mdTable | Set-Content -Path $Path }

build/bump_version.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Param (
2+
$Path = '.\dbops.psd1'
3+
)
4+
$moduleFile = Invoke-Command -ScriptBlock ([scriptblock]::Create((Get-Content $Path -Raw)))
5+
$version = [Version]$moduleFile.ModuleVersion
6+
$regEx = "^([\s]*ModuleVersion[\s]*\=[\s]*)\'(" + [regex]::Escape($version) + ")\'[\s]*`$"
7+
Write-Host "Current build $version"
8+
9+
$magicPhrase = "Bumping up version"
10+
$commitMessage = git log -1 --pretty=%B
11+
$publishedVersion = Find-Module dbops -ErrorAction Stop | Select-Object -ExpandProperty Version
12+
13+
if ($version -le $publishedVersion -and $commitMessage -notlike "$magicPhrase*") {
14+
# increase version and push back to git
15+
[string]$newVersion = [Version]::new($publishedVersion.Major, $publishedVersion.Minor, ($publishedVersion.Build + 1))
16+
$content = Get-Content $Path
17+
$content | Foreach-Object { $_ -replace $regEx, "`$1'$newVersion'" } | Out-File $Path -Force -Encoding utf8
18+
$newModuleFile = Invoke-Command -ScriptBlock ([scriptblock]::Create((Get-Content $Path -Raw)))
19+
Write-Host "New build $($newModuleFile.ModuleVersion)"
20+
git config --global user.email "[email protected]"
21+
git config --global user.name "nvarscar"
22+
git add .\dbops.psd1
23+
git commit -m "$magicPhrase`: $newVersion"
24+
git push origin HEAD:master 2>&1 > $null
25+
git push origin HEAD:development 2>&1 > $null
26+
}
27+
else {
28+
# trigger the release pipeline
29+
Write-Host "##vso[build.addbuildtag]Release"
30+
}

docs/changelog.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Release notes for v0.5.8:
2+
- ### Adding prescripts and postscripts (#91) by @nvarscar
3+
------
4+
Two new parameters:
5+
- PreScriptPath
6+
- PostScriptPath
7+
8+
And one new function:
9+
Update-DBOPackage that will allow to modify some of the package parameters once it's created.
10+
- ### Adding return as text switch to Invoke-DBOQuery (#92) by @nvarscar
11+
- ### Adding nuget package downloader (#93) by @nvarscar
12+
- ### Fixing Set and Reset-DBODefaultSetting on Linux (#94) by @nvarscar
13+
------
14+
scope for linux was chosen incorrectly. Now it's chosen dynamically based on OS.
15+
- ### Re-introducing Oracle tests (#97) by @nvarscar
16+
------
17+
Switching to "/" as a batch separator - this is a breaking change.
18+
Tests have been updated to support that change.
19+
20+
- ### Renaming Install-DBOSqlScript to Install-DBOScript (#98) by @nvarscar
21+
- ### Flexible nuget package versioning (#99) by @nvarscar
22+
------
23+
Requirements now allow Minimum/Maximum Versions where appropriate, as well as it's possible to target a specific .net framework

docs/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,8 @@ Get-DBOPackageArtifact -Path myPackage.zip -Repository \\data\repo | Install-DBO
168168

169169
## Contacts
170170
Submitting issues - [GitHub issues](https://github.com/sqlcollaborative/dbops/issues)
171-
SQLCommunity Slack: https://sqlcommunity.slack.com #devops or @nvarscar
171+
172+
SQL Community Slack: https://sqlcommunity.slack.com
173+
174+
- #dbops channel
175+
- @nvarscar

tests/etc/bump_version.ps1

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)