-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yaml
259 lines (217 loc) · 9.55 KB
/
action.yaml
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
name: 'UPM Release (XRTK)'
description: 'An atomic GitHub action to publish UPM (unity package manager) packages.'
inputs:
upm-username:
description: 'The user name doing the publishing.'
required: true
default: ''
upm-email:
description: 'The email address of the user doing the publishing.'
required: true
default: ''
upm-auth-token:
description: 'Auth Token for NPM/UPM server.'
required: true
default: ''
github-token:
description: 'A Github actions token.'
required: true
default: ''
github-username:
description: 'A username to sign the commits to in your repository. Defaults to the name of the person or app that initiated the workflow.'
required: false
default: '${{ github.actor }}'
upm-server-address:
description: 'The url of the upm/npm server. (Defaults to NPM registry)'
required: false
default: 'https://registry.npmjs.org'
package-root:
description: 'The project package root directory. (Defaults to **/Packages/)'
required: false
default: '**/Packages/com.*'
preview:
description: 'Is this package in preview?'
required: false
default: 'false'
upm-branch:
description: 'The branch to use for the UPM release. (Defaults to upm)'
required: false
default: 'upm'
runs:
using: "composite"
steps:
- uses: actions/checkout@v4
if: ${{ github.ref != 'refs/heads/upm' && github.base_ref != 'upm' }}
with:
token: ${{ inputs.github-token }}
ref: ${{ inputs.upm-branch }}
fetch-depth: 0
- uses: actions/[email protected]
with:
registry-url: '${{ inputs.upm-server-address }}'
always-auth: true
check-latest: true
- name: upm publish dry run
if: ${{ github.ref == 'refs/heads/main' || github.base_ref == 'main' || github.ref == 'refs/heads/upm' || github.base_ref == 'upm' }}
run: |
# upm publish dry run
npm whoami
$exit = 0
if ($LASTEXITCODE -gt 0) {
$exit = $LASTEXITCODE
}
$packageDir = Get-Item -Path "${{ inputs.package-root }}" | Select-Object -ExpandProperty FullName
Write-Host "Package Directory: $packageDir"
cd $packageDir
Write-Host "::group::test publish to registry"
npm publish --dry-run
Write-Host "::endgroup::"
$exit = 0
if ($LASTEXITCODE -gt 0) {
$exit = $LASTEXITCODE
}
exit $exit
working-directory: ${{ github.workspace }}
shell: pwsh
env:
NODE_AUTH_TOKEN: ${{ inputs.upm-auth-token }}
- id: validate-version
name: Validate Package Version
run: |
# validate version
$branch = '${{ inputs.upm-branch }}'
if ([string]::IsNullOrEmpty($branch)) {
Write-Error "Failed to determine the branch to use for pushing the release."
exit 1
}
Write-Host "::debug::Release Branch: $branch"
$isPreview = '${{ github.base_ref == 'main' || inputs.preview == 'true' }}'
$packageDir = Get-Item -Path "${{ inputs.package-root }}" | Select-Object -ExpandProperty FullName
$packageFile = (Resolve-Path "$packageDir/package.json" | Where-Object { $_.Path -notmatch'.meta' }).ToString()
if ( -not (Test-Path -Path $packageFile) ) {
Write-Error "Failed to find a valid project manifest at `"$packageFile`""
exit 1
}
$packageInfo = (Get-Content $packageFile -Raw) | ConvertFrom-Json
Write-Host "Detected Project Version:" $packageInfo.version
$env:GIT_REDIRECT_STDERR = '2>&1'
git fetch --all --tags
$lastRelease = $(git describe --tags $(git rev-list --tags --max-count=1))
if ($lastRelease -match "fatal") {
Write-Error $lastRelease
exit 1
}
$packageSemVer = [System.Management.Automation.SemanticVersion]$packageInfo.version
$lastReleaseSemVer = [System.Management.Automation.SemanticVersion]$lastRelease
if ([string]::IsNullOrEmpty($lastRelease)) {
Write-Host "New Release needed $packageSemVer"
} else {
Write-Host "Last Release $lastReleaseSemVer"
}
if ($packageSemVer -le $lastReleaseSemVer) {
$packageSemVer = $lastReleaseSemVer
}
if ($isPreview -eq 'true') {
if (($lastReleaseSemVer.PreReleaseLabel -match '(?<preview>\d+)') -or ($packageSemVer.PreReleaseLabel -match '(?<preview>\d+)')) {
$preview = ([int]$Matches.preview) + 1
} else {
$packageSemVer = [System.Management.Automation.SemanticVersion]::New($packageSemVer.Major, $packageSemVer.Minor, $packageSemVer.Patch + 1)
$preview = 1
}
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($packageSemVer.Major, $packageSemVer.Minor, $packageSemVer.Patch, "preview.$preview")
Write-Host Preview build calculated: $newPackageSemVer
$packageInfo.version = $newPackageSemVer.ToString()
} else {
if (($lastReleaseSemVer.PreReleaseLabel -match '(?<preview>\d+)') -and
($lastReleaseSemVer.Patch -eq $packageSemVer.Patch)) {
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($packageSemVer.Major, $packageSemVer.Minor, $packageSemVer.Patch)
} else {
$newPackageSemVer = [System.Management.Automation.SemanticVersion]::New($packageSemVer.Major, $packageSemVer.Minor, $packageSemVer.Patch + 1)
}
Write-Host Release build calculated: $newPackageSemVer
if ($newPackageSemVer -gt $packageSemVer) {
$packageSemVer = $newPackageSemVer
Write-Host $packageInfo.version -> $packageSemVer.ToString()
$packageInfo.version = $packageSemVer.ToString()
}
Write-Host Updating Assembly Versions $lastRelease -> $packageInfo.version
$updatedFiles = @()
Get-ChildItem -Path "$packageDir/com.xrtk*/**/*AssemblyInfo.cs" -Recurse | ForEach-Object -Process {
Get-ChildItem -Path $_ -File | ForEach-Object -Process {
$fileContent = Get-Content $($_.FullName) -Raw
# update assembly version
$assemblyVersionRegex = "\[assembly: AssemblyVersion\(""(.*)""\)\]"
if ($fileContent -match $assemblyVersionRegex) {
$assemblyVersion = [System.Management.Automation.SemanticVersion]::New($packageSemVer.Major, $packageSemVer.Minor, $packageSemVer.Patch)
$newAssemblyVersion = "[assembly: AssemblyVersion(""$assemblyVersion"")]"
$fileContent -replace $assemblyVersionRegex, $newAssemblyVersion | Set-Content $($_.FullName) -NoNewline
echo Updated $_.FullName
$updatedFiles += $_.FullName
}
}
}
}
$version = $packageInfo.version
"VERSION=$version" >> $env:GITHUB_ENV
$packageInfo | ConvertTo-Json | Set-Content $packageFile
Write-Host "::debug::set git config"
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "GitHub Actions"
Write-Host "::debug::check current status"
git status
Write-Host "::debug::checkout $branch"
git checkout $branch
Write-Host "::debug::pull latest changes"
git pull
Write-Host "::debug::add package.json"
git add $packageFile
foreach ($file in $updatedFiles) {
git add $file
}
Write-Host "::debug::check current status"
git status
Write-Host "::debug::check branch"
git branch
Write-Host "::debug::commit version changes"
git commit -m "[skip ci] $version"
Write-Host "::debug::push version changes"
git push https://${{ inputs.github-token }}@github.com/${{ github.repository }}.git $branch --force
$exit = 0
if ($LASTEXITCODE -gt 0) {
$exit = $LASTEXITCODE
}
git status
exit $exit
shell: pwsh
working-directory: ${{ github.workspace }}
- uses: RageAgainstThePixel/[email protected]
if: ${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main') && env.VERSION != '' }}
with:
package-root: ${{ inputs.package-root }}
- name: upm publish
if: ${{ (github.ref == 'refs/heads/main' || github.base_ref == 'main' || github.ref == 'refs/heads/upm' || github.base_ref == 'upm') && env.VERSION != '' }}
run: |
# upm publish
$packageDir = Get-Item -Path "${{ inputs.package-root }}" | Select-Object -ExpandProperty FullName
cd $packageDir
Write-Host "::group::publish to registry"
npm publish
Write-Host "::endgroup::"
$exit = 0
if ($LASTEXITCODE -gt 0) {
$exit = $LASTEXITCODE
}
exit $exit
working-directory: ${{ github.workspace }}
shell: pwsh
env:
NODE_AUTH_TOKEN: ${{ inputs.upm-auth-token }}
- name: tag version
if: ${{ env.VERSION != '' }}
run: |
git tag '${{ env.VERSION }}' upm
git push https://${{ inputs.github-username }}$env:[email protected]/${{ github.repository }}.git "${{ env.VERSION }}"
working-directory: ${{ github.workspace }}
shell: pwsh
env:
GITHUB_TOKEN: ${{ inputs.github-token }}