azure-pipelines.yml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. # Gradle
  2. # Build your Java project and run tests with Gradle using a Gradle wrapper script.
  3. # Add steps that analyze code, save build artifacts, deploy, and more:
  4. # https://docs.microsoft.com/azure/devops/pipelines/languages/java
  5. pool:
  6. vmImage: 'Ubuntu-latest'
  7. variables:
  8. artifactName: 'Release'
  9. GRADLE_USER_HOME: $(Pipeline.Workspace)/.gradle
  10. SKIP_BUILD: $[contains(variables['Build.SourceBranch'], 'refs/heads/no-build/')]
  11. ${{ if not(contains(variables['Build.SourceBranch'], 'refs/heads/no-build/')) }}:
  12. revision: $[counter('release-number', 0)]
  13. steps:
  14. - powershell: |
  15. $json = [Ordered]@{
  16. title = "Maven Publish Failed"
  17. url = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)Twilight%20Forest/_build/results?buildId=$($Env:BUILD_BUILDID)&view=results"
  18. color = 16733440
  19. fields = (
  20. [Ordered]@{
  21. name = "Author"
  22. value = "$($env:BUILD_SOURCEVERSIONAUTHOR)"
  23. },
  24. [Ordered]@{
  25. name = "Commit"
  26. value = "[$(($env:BUILD_SOURCEVERSION).Substring(0, 7))]($($env:BUILD_REPOSITORY_URI)/commit/$($env:BUILD_SOURCEVERSION))"
  27. }
  28. )
  29. }
  30. Write-Host "##vso[task.setvariable variable=DiscordMessageMavenFailed]$($json | ConvertTo-Json -Compress)"
  31. displayName: Format failed maven publish discord message
  32. condition: always()
  33. env:
  34. SYSTEM_ACCESSTOKEN: $(System.AccessToken)
  35. - task: Cache@2
  36. inputs:
  37. key: 'gradle | "$(Agent.OS)" | build.gradle | settings.gradle | gradle.properties | src/main/resources/META-INF/accesstransformer.cfg'
  38. path: $(GRADLE_USER_HOME)
  39. displayName: Restore Gradle Cache
  40. condition: eq(variables.SKIP_BUILD, 'false')
  41. - task: Cache@2
  42. inputs:
  43. key: 'gradleLocal | "$(Agent.OS)" | build.gradle | settings.gradle | gradle.properties | src/main/resources/META-INF/accesstransformer.cfg'
  44. path: .gradle
  45. displayName: Restore Project Level Gradle Cache
  46. condition: eq(variables.SKIP_BUILD, 'false')
  47. - task: Cache@2
  48. inputs:
  49. key: 'gradleBuildTmpLocal | "$(Agent.OS)" | build.gradle | settings.gradle | gradle.properties | src/main/resources/META-INF/accesstransformer.cfg'
  50. path: build/tmp
  51. displayName: Restore Project Level build/tmp Cache
  52. condition: eq(variables.SKIP_BUILD, 'false')
  53. - powershell: |
  54. (Get-Content ./gradle.properties).Split([Environment]::NewLine) | % {
  55. $kvp = $_.Split('=')
  56. if ($kvp.Count -gt 1) {
  57. $key = $kvp[0] -replace "\.", "_";
  58. $value = $kvp[1];
  59. Write-Host "##vso[task.setvariable variable=javaprops_$key]$value"
  60. }
  61. }
  62. displayName: Create Azure DevOps variables from gradle properties file
  63. condition: eq(variables.SKIP_BUILD, 'false')
  64. - task: Gradle@2
  65. displayName: Create Release Build
  66. inputs:
  67. workingDirectory: ''
  68. options: '--build-cache --max-workers=1 -PCIRevision=$(javaprops_mod_version).$(revision) -PCIType=RELEASE'
  69. gradleWrapperFile: 'gradlew'
  70. gradleOptions: '-Xmx3072m'
  71. javaHomeOption: 'JDKVersion'
  72. jdkVersionOption: '21'
  73. jdkArchitectureOption: 'x64'
  74. publishJUnitResults: false
  75. testResultsFiles: '**/TEST-*.xml'
  76. tasks: 'build'
  77. condition: eq(variables.SKIP_BUILD, 'false')
  78. - task: CopyFiles@2
  79. displayName: Copy Release build to artifact staging
  80. inputs:
  81. sourceFolder: './build/libs/'
  82. contents: 'twilightforest-*-universal.jar'
  83. targetFolder: $(build.artifactStagingDirectory)
  84. condition: and(and(succeeded(), eq(variables['CreateArtifacts'], 'True')), eq(variables.SKIP_BUILD, 'false'))
  85. - task: PublishPipelineArtifact@1
  86. displayName: 'Publish Artifacts'
  87. condition: and(and(succeeded(), eq(variables['CreateArtifacts'], 'True')), eq(variables.SKIP_BUILD, 'false'))
  88. inputs:
  89. targetPath: '$(Build.ArtifactStagingDirectory)'
  90. artifact: '$(artifactName)'
  91. publishLocation: 'pipeline'
  92. - powershell: |
  93. $rawpath = "pipelineartifact://teamtwilight/projectId/1ef09d39-06cf-41fa-ad98-7258b70c2a72/buildId/$($Env:BUILD_BUILDID)/artifactName/Release"
  94. $path = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($rawpath))
  95. $jar = "twilightforest-$($env:JAVAPROPS_MINECRAFT_VERSION)-$($env:JAVAPROPS_MOD_VERSION).$($env:REVISION)-universal.jar"
  96. $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)"
  97. $jobResult = (Get-Culture).TextInfo.ToTitleCase(${env:agent.jobstatus})
  98. $Colour = 65280
  99. if ($jobResult -ne "Succeeded") {
  100. $Colour = 16711680
  101. }
  102. Write-Host "##vso[task.setvariable variable=DiscordMessageColour]$Colour"
  103. $json = [Ordered]@{
  104. title = "Build $jobResult"
  105. url = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)Twilight%20Forest/_build/results?buildId=$($Env:BUILD_BUILDID)&view=results"
  106. color = $Colour
  107. fields = (
  108. [Ordered]@{
  109. name = "Author"
  110. value = "$($env:BUILD_SOURCEVERSIONAUTHOR)"
  111. },
  112. [Ordered]@{
  113. name = "Minecraft Version"
  114. value = "$($env:JAVAPROPS_MINECRAFT_VERSION)"
  115. },
  116. [Ordered]@{
  117. name = "Mod Version"
  118. value = "$($env:JAVAPROPS_MOD_VERSION).$($env:REVISION)"
  119. },
  120. [Ordered]@{
  121. name = "NeoForge Version"
  122. value = "$($env:JAVAPROPS_NEO_VERSION)"
  123. },
  124. [Ordered]@{
  125. name = "Commit"
  126. value = "[$(($env:BUILD_SOURCEVERSION).Substring(0, 7))]($($env:BUILD_REPOSITORY_URI)/commit/$($env:BUILD_SOURCEVERSION))"
  127. }
  128. )
  129. }
  130. if ($jobResult -eq "Succeeded") {
  131. $json["fields"] += [Ordered]@{
  132. name = "Download"
  133. value = "[$($downloadUrl.Split("subPath=%2F")[1])]($downloadUrl)"
  134. }
  135. }
  136. Write-Host "##vso[task.setvariable variable=DiscordMessage]$($json | ConvertTo-Json -Compress)"
  137. displayName: Format build status discord message
  138. condition: eq(variables.SKIP_BUILD, 'false')
  139. env:
  140. SYSTEM_ACCESSTOKEN: $(System.AccessToken)
  141. - task: ado-discord-webhook@1
  142. displayName: Announce Build to discord
  143. inputs:
  144. channelId: '$(DiscordChannelID)'
  145. webhookKey: '$(DiscordChannelSecret)'
  146. messageType: 'embeds'
  147. embeds: |
  148. [$(DiscordMessage)]
  149. condition: and(eq(variables.SKIP_BUILD, 'false'), eq(variables['CreateArtifacts'], 'True'))
  150. - powershell: |
  151. Write-Host "##vso[task.setvariable variable=RunMavenPublishTask]True"
  152. displayName: Allow Maven Publish tasks
  153. condition: and(and(succeeded(), eq(variables['CreateArtifacts'], 'True')), eq(variables.SKIP_BUILD, 'false'))
  154. - task: Gradle@2
  155. displayName: Publish to Maven
  156. inputs:
  157. workingDirectory: ''
  158. options: '-PCIRevision=$(javaprops_mod_version).$(revision) -PCIType=RELEASE'
  159. gradleWrapperFile: 'gradlew'
  160. gradleOptions: '-Xmx3072m'
  161. javaHomeOption: 'JDKVersion'
  162. jdkVersionOption: '21'
  163. jdkArchitectureOption: 'x64'
  164. publishJUnitResults: false
  165. testResultsFiles: '**/TEST-*.xml'
  166. tasks: 'publish'
  167. condition: and(and(succeeded(), eq(variables['RunMavenPublishTask'], 'True')), eq(variables.SKIP_BUILD, 'false'))
  168. env:
  169. ARTIFACTORY_USER: $(Artifactory.User)
  170. ARTIFACTORY_PASS: $(Artifactory.Password)
  171. - task: ado-discord-webhook@1
  172. displayName: Announce Failed Maven Publish to discord
  173. inputs:
  174. channelId: '$(DiscordChannelID)'
  175. webhookKey: '$(DiscordChannelSecret)'
  176. messageType: 'embeds'
  177. embeds: |
  178. [$(DiscordMessageMavenFailed)]
  179. condition: and(and(failed(), eq(variables['RunMavenPublishTask'], 'True')), eq(variables.SKIP_BUILD, 'false'))
  180. - script: |
  181. # stop the Gradle daemon to ensure no files are left open (impacting the save cache operation later)
  182. ./gradlew --stop
  183. displayName: Kill Daemon
  184. condition: eq(variables.SKIP_BUILD, 'false')