-
Notifications
You must be signed in to change notification settings - Fork 17
207 lines (173 loc) · 7.2 KB
/
Copy pathrelease.yml
File metadata and controls
207 lines (173 loc) · 7.2 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
name: Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
version:
description: "Release version. Leave empty to use DreamShader.uplugin VersionName."
required: false
type: string
prerelease:
description: "Mark the GitHub Release as a pre-release."
required: false
default: false
type: boolean
permissions:
contents: write
jobs:
release:
name: Package and publish
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve release version
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$Descriptor = Get-Content -Raw -Path 'DreamShader.uplugin' | ConvertFrom-Json
$PluginVersion = [string]$Descriptor.VersionName
if ([string]::IsNullOrWhiteSpace($PluginVersion)) {
throw 'DreamShader.uplugin VersionName is empty.'
}
$InputVersion = '${{ github.event.inputs.version }}'.Trim()
$Version = if ([string]::IsNullOrWhiteSpace($InputVersion)) { $PluginVersion } else { $InputVersion.TrimStart('v') }
$TagName = "v$Version"
if ('${{ github.ref_type }}' -eq 'tag') {
$PushedTag = '${{ github.ref_name }}'
$PushedVersion = $PushedTag.TrimStart('v')
if ($PushedVersion -ne $PluginVersion) {
throw "Tag '$PushedTag' does not match DreamShader.uplugin VersionName '$PluginVersion'."
}
$Version = $PluginVersion
$TagName = $PushedTag
}
if ($Version -ne $PluginVersion) {
throw "Requested release version '$Version' does not match DreamShader.uplugin VersionName '$PluginVersion'."
}
"DREAMSHADER_VERSION=$Version" | Out-File -FilePath $env:GITHUB_ENV -Append
"DREAMSHADER_TAG=$TagName" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Package plugin
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$Version = $env:DREAMSHADER_VERSION
$StageRoot = Join-Path $env:RUNNER_TEMP 'DreamShaderRelease'
$PluginRoot = Join-Path $StageRoot 'DreamShader'
$ArtifactRoot = Join-Path $env:GITHUB_WORKSPACE 'artifacts'
$ZipPath = Join-Path $ArtifactRoot "DreamShader-$Version.zip"
Remove-Item -LiteralPath $StageRoot -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -LiteralPath $ArtifactRoot -Recurse -Force -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path $PluginRoot -Force | Out-Null
New-Item -ItemType Directory -Path $ArtifactRoot -Force | Out-Null
$Items = @(
'Source',
'Resources',
'Library',
'Docs',
'DreamShader.uplugin',
'README.md',
'CHANGELOG.md',
'LICENSE'
)
foreach ($Item in $Items) {
if (!(Test-Path -LiteralPath $Item)) {
continue
}
Copy-Item -LiteralPath $Item -Destination $PluginRoot -Recurse -Force
}
Compress-Archive -Path $PluginRoot -DestinationPath $ZipPath -Force
"DREAMSHADER_ZIP=$ZipPath" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Download latest VSCode extension release assets
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$ErrorActionPreference = 'Stop'
$ExtensionArtifactRoot = Join-Path $env:GITHUB_WORKSPACE 'artifacts\vscode-extension'
Remove-Item -LiteralPath $ExtensionArtifactRoot -Recurse -Force -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path $ExtensionArtifactRoot -Force | Out-Null
gh release download `
--repo TypeDreamMoon/dreamshader-language-support `
--pattern '*' `
--dir $ExtensionArtifactRoot
$DownloadedAssets = Get-ChildItem -LiteralPath $ExtensionArtifactRoot -File | Sort-Object Name
if ($DownloadedAssets.Count -eq 0) {
throw 'No assets were downloaded from TypeDreamMoon/dreamshader-language-support latest release.'
}
Write-Host "Downloaded VSCode extension release assets:"
foreach ($Asset in $DownloadedAssets) {
Write-Host " - $($Asset.Name)"
}
"DREAMSHADER_VSCODE_ASSET_DIR=$ExtensionArtifactRoot" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Build release notes
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$Version = $env:DREAMSHADER_VERSION
$NotesPath = Join-Path $env:RUNNER_TEMP 'DreamShaderReleaseNotes.md'
$Lines = Get-Content -Path 'CHANGELOG.md'
$StartIndex = -1
for ($Index = 0; $Index -lt $Lines.Count; ++$Index) {
if ($Lines[$Index] -match "^##\s+$([regex]::Escape($Version))\b") {
$StartIndex = $Index + 1
break
}
}
if ($StartIndex -ge 0) {
$EndIndex = $Lines.Count
for ($Index = $StartIndex; $Index -lt $Lines.Count; ++$Index) {
if ($Lines[$Index] -match '^##\s+') {
$EndIndex = $Index
break
}
}
$Body = ($Lines[$StartIndex..($EndIndex - 1)] -join "`n").Trim()
} else {
$Body = "DreamShader $Version release."
}
"# DreamShader $Version`n`n$Body" | Set-Content -Path $NotesPath -Encoding UTF8
"DREAMSHADER_NOTES=$NotesPath" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Publish GitHub Release
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$ErrorActionPreference = 'Stop'
$TagName = $env:DREAMSHADER_TAG
$Title = "DreamShader $env:DREAMSHADER_VERSION"
$ZipPath = $env:DREAMSHADER_ZIP
$NotesPath = $env:DREAMSHADER_NOTES
$IsPrerelease = '${{ github.event.inputs.prerelease }}' -eq 'true'
$ReleaseAssets = @($ZipPath)
$VSCodeAssetDir = $env:DREAMSHADER_VSCODE_ASSET_DIR
if (![string]::IsNullOrWhiteSpace($VSCodeAssetDir) -and (Test-Path -LiteralPath $VSCodeAssetDir)) {
$VSCodeAssets = @(Get-ChildItem -LiteralPath $VSCodeAssetDir -File | Sort-Object Name | ForEach-Object { $_.FullName })
$ReleaseAssets += $VSCodeAssets
}
$ReleaseArgs = @(
$TagName
) + $ReleaseAssets + @(
'--title', $Title,
'--notes-file', $NotesPath
)
if ($IsPrerelease) {
$ReleaseArgs += '--prerelease'
}
gh release view $TagName *> $null
if ($LASTEXITCODE -eq 0) {
gh release upload $TagName @ReleaseAssets --clobber
gh release edit $TagName --title $Title --notes-file $NotesPath
if ($IsPrerelease) {
gh release edit $TagName --prerelease
}
} else {
if ('${{ github.ref_type }}' -ne 'tag') {
$ReleaseArgs += @('--target', '${{ github.sha }}')
}
gh release create @ReleaseArgs
}