azure-pipelines.yml 6.9 KB

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