-
Notifications
You must be signed in to change notification settings - Fork 5
114 lines (111 loc) · 4.44 KB
/
release.yml
File metadata and controls
114 lines (111 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"
permissions:
contents: write
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Check Changelog
shell: pwsh
run: |
$version = $env:GITHUB_REF.Replace('refs/tags/', '')
$changelog = Get-Content -Path CHANGELOG.md
$foundVersion = $false
foreach ($line in $changelog) {
if ($line -match "^## $version$") {
$foundVersion = $true
continue
}
if ($foundVersion -and $line -match "^## ") {
break
}
}
if ($foundVersion) {
Write-Output "SUCCESS: Locating release in the changelog for version '$version'."
} else {
Write-Error "FAILED: Locating release in the changelog for version '$version'."
exit 1
}
- name: Create Release Branch
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$version = $env:GITHUB_REF.Replace('refs/tags/', '')
$releaseBranch = "release/$version"
$git = Get-Command git | Select-Object -ExpandProperty Definition
& $git config --global user.name "github-actions[bot]"
& $git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
& $git checkout -b $releaseBranch
& $git push origin $releaseBranch
if ($LASTEXITCODE -ne 0) {
Write-Error "FAILED: Creating release branch '$releaseBranch'."
} else {
Write-Output "SUCCESS: Creating release branch '$releaseBranch'."
}
- name: Rebase Main Branch
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$version = $env:GITHUB_REF.Replace('refs/tags/', '')
$releaseBranch = "release/$version"
$git = Get-Command git | Select-Object -ExpandProperty Definition
& $git config --global user.name "github-actions[bot]"
& $git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
& $git checkout $releaseBranch
& $git pull origin $releaseBranch
& $git checkout main
& $git pull origin main
& $git rebase $releaseBranch
& $git push origin main
if ($LASTEXITCODE -ne 0) {
Write-Error "FAILED: Rebasing main branch from release branch '$releaseBranch'."
} else {
Write-Output "SUCCESS: Rebasing main branch from release branch '$releaseBranch'."
}
- name: Install GitHub CLI
run: |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
- name: Create Release
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$version = $env:GITHUB_REF.Replace('refs/tags/', '')
$changelog = Get-Content -Path CHANGELOG.md
$releaseNotes = $null
$foundVersion = $false
foreach ($line in $changelog) {
if ($line -match "^## $version$") {
$foundVersion = $true
continue
}
if ($foundVersion -and $line -match "^## ") {
break
}
if ($foundVersion) {
$releaseNotes += $line + "`n"
}
}
$gh = Get-Command gh | Select-Object -ExpandProperty Definition
& $gh release create $version --title "$version" --notes "$releaseNotes" --target "release/$version"
if ($LASTEXITCODE -ne 0) {
Write-Error "FAILED: Creating GitHub release '$version'."
} else {
Write-Output "SUCCESS: Creating GitHub release '$version'."
}