forked from Benimatic/twilightforest
-
Notifications
You must be signed in to change notification settings - Fork 199
/
azure-pipelines.yml
201 lines (184 loc) · 8.08 KB
/
azure-pipelines.yml
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
# Gradle
# Build your Java project and run tests with Gradle using a Gradle wrapper script.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/java
pool:
vmImage: 'Ubuntu-latest'
variables:
artifactName: 'Release'
GRADLE_USER_HOME: $(Pipeline.Workspace)/.gradle
SKIP_BUILD: $[contains(variables['Build.SourceBranch'], 'refs/heads/no-build/')]
${{ if not(contains(variables['Build.SourceBranch'], 'refs/heads/no-build/')) }}:
revision: $[counter('release-number', 0)]
steps:
- powershell: |
$json = [Ordered]@{
title = "Maven Publish Failed"
url = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)Twilight%20Forest/_build/results?buildId=$($Env:BUILD_BUILDID)&view=results"
color = 16733440
fields = (
[Ordered]@{
name = "Author"
value = "$($env:BUILD_SOURCEVERSIONAUTHOR)"
},
[Ordered]@{
name = "Commit"
value = "[$(($env:BUILD_SOURCEVERSION).Substring(0, 7))]($($env:BUILD_REPOSITORY_URI)/commit/$($env:BUILD_SOURCEVERSION))"
}
)
}
Write-Host "##vso[task.setvariable variable=DiscordMessageMavenFailed]$($json | ConvertTo-Json -Compress)"
displayName: Format failed maven publish discord message
condition: always()
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- task: Cache@2
inputs:
key: 'gradle | "$(Agent.OS)" | build.gradle | settings.gradle | gradle.properties | src/main/resources/META-INF/accesstransformer.cfg'
path: $(GRADLE_USER_HOME)
displayName: Restore Gradle Cache
condition: eq(variables.SKIP_BUILD, 'false')
- task: Cache@2
inputs:
key: 'gradleLocal | "$(Agent.OS)" | build.gradle | settings.gradle | gradle.properties | src/main/resources/META-INF/accesstransformer.cfg'
path: .gradle
displayName: Restore Project Level Gradle Cache
condition: eq(variables.SKIP_BUILD, 'false')
- task: Cache@2
inputs:
key: 'gradleBuildTmpLocal | "$(Agent.OS)" | build.gradle | settings.gradle | gradle.properties | src/main/resources/META-INF/accesstransformer.cfg'
path: build/tmp
displayName: Restore Project Level build/tmp Cache
condition: eq(variables.SKIP_BUILD, 'false')
- powershell: |
(Get-Content ./gradle.properties).Split([Environment]::NewLine) | % {
$kvp = $_.Split('=')
if ($kvp.Count -gt 1) {
$key = $kvp[0] -replace "\.", "_";
$value = $kvp[1];
Write-Host "##vso[task.setvariable variable=javaprops_$key]$value"
}
}
displayName: Create Azure DevOps variables from gradle properties file
condition: eq(variables.SKIP_BUILD, 'false')
- task: Gradle@2
displayName: Create Release Build
inputs:
workingDirectory: ''
options: '--build-cache --max-workers=1 -PCIRevision=$(javaprops_mod_version).$(revision) -PCIType=RELEASE'
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '21'
jdkArchitectureOption: 'x64'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
condition: eq(variables.SKIP_BUILD, 'false')
- task: CopyFiles@2
displayName: Copy Release build to artifact staging
inputs:
sourceFolder: './build/libs/'
contents: 'twilightforest-*-universal.jar'
targetFolder: $(build.artifactStagingDirectory)
condition: and(and(succeeded(), eq(variables['CreateArtifacts'], 'True')), eq(variables.SKIP_BUILD, 'false'))
- task: PublishPipelineArtifact@1
displayName: 'Publish Artifacts'
condition: and(and(succeeded(), eq(variables['CreateArtifacts'], 'True')), eq(variables.SKIP_BUILD, 'false'))
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: '$(artifactName)'
publishLocation: 'pipeline'
- powershell: |
$rawpath = "pipelineartifact://teamtwilight/projectId/1ef09d39-06cf-41fa-ad98-7258b70c2a72/buildId/$($Env:BUILD_BUILDID)/artifactName/Release"
$path = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($rawpath))
$jar = "twilightforest-$($env:JAVAPROPS_MINECRAFT_VERSION)-$($env:JAVAPROPS_MOD_VERSION).$($env:REVISION)-universal.jar"
$downloadUrl = "https://artprodcus3.artifacts.visualstudio.com/Abaabfa6c-deea-4587-ba05-c308c2597b7a/1ef09d39-06cf-41fa-ad98-7258b70c2a72/_apis/artifact/$($path)0/content?format=file&subPath=%2F$($jar)"
$jobResult = (Get-Culture).TextInfo.ToTitleCase(${env:agent.jobstatus})
$Colour = 65280
if ($jobResult -ne "Succeeded") {
$Colour = 16711680
}
Write-Host "##vso[task.setvariable variable=DiscordMessageColour]$Colour"
$json = [Ordered]@{
title = "Build $jobResult"
url = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)Twilight%20Forest/_build/results?buildId=$($Env:BUILD_BUILDID)&view=results"
color = $Colour
fields = (
[Ordered]@{
name = "Author"
value = "$($env:BUILD_SOURCEVERSIONAUTHOR)"
},
[Ordered]@{
name = "Minecraft Version"
value = "$($env:JAVAPROPS_MINECRAFT_VERSION)"
},
[Ordered]@{
name = "Mod Version"
value = "$($env:JAVAPROPS_MOD_VERSION).$($env:REVISION)"
},
[Ordered]@{
name = "NeoForge Version"
value = "$($env:JAVAPROPS_NEO_VERSION)"
},
[Ordered]@{
name = "Commit"
value = "[$(($env:BUILD_SOURCEVERSION).Substring(0, 7))]($($env:BUILD_REPOSITORY_URI)/commit/$($env:BUILD_SOURCEVERSION))"
}
)
}
if ($jobResult -eq "Succeeded") {
$json["fields"] += [Ordered]@{
name = "Download"
value = "[$($downloadUrl.Split("subPath=%2F")[1])]($downloadUrl)"
}
}
Write-Host "##vso[task.setvariable variable=DiscordMessage]$($json | ConvertTo-Json -Compress)"
displayName: Format build status discord message
condition: eq(variables.SKIP_BUILD, 'false')
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- task: ado-discord-webhook@1
displayName: Announce Build to discord
inputs:
channelId: '$(DiscordChannelID)'
webhookKey: '$(DiscordChannelSecret)'
messageType: 'embeds'
embeds: |
[$(DiscordMessage)]
condition: and(eq(variables.SKIP_BUILD, 'false'), eq(variables['CreateArtifacts'], 'True'))
- powershell: |
Write-Host "##vso[task.setvariable variable=RunMavenPublishTask]True"
displayName: Allow Maven Publish tasks
condition: and(and(succeeded(), eq(variables['CreateArtifacts'], 'True')), eq(variables.SKIP_BUILD, 'false'))
- task: Gradle@2
displayName: Publish to Maven
inputs:
workingDirectory: ''
options: '-PCIRevision=$(javaprops_mod_version).$(revision) -PCIType=RELEASE'
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '21'
jdkArchitectureOption: 'x64'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: 'publish'
condition: and(and(succeeded(), eq(variables['RunMavenPublishTask'], 'True')), eq(variables.SKIP_BUILD, 'false'))
env:
ARTIFACTORY_USER: $(Artifactory.User)
ARTIFACTORY_PASS: $(Artifactory.Password)
- task: ado-discord-webhook@1
displayName: Announce Failed Maven Publish to discord
inputs:
channelId: '$(DiscordChannelID)'
webhookKey: '$(DiscordChannelSecret)'
messageType: 'embeds'
embeds: |
[$(DiscordMessageMavenFailed)]
condition: and(and(failed(), eq(variables['RunMavenPublishTask'], 'True')), eq(variables.SKIP_BUILD, 'false'))
- script: |
# stop the Gradle daemon to ensure no files are left open (impacting the save cache operation later)
./gradlew --stop
displayName: Kill Daemon
condition: eq(variables.SKIP_BUILD, 'false')