azure-pipelines.yml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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-20.04'
  7. container: eclipse-temurin:17.0.3_7-jdk
  8. variables:
  9. revision: $[counter('release-number', 0)]
  10. artifactName: 'Release'
  11. GRADLE_USER_HOME: $(Pipeline.Workspace)/.gradle
  12. steps:
  13. - bash: |
  14. loc="/opt/java/openjdk"
  15. echo "##vso[task.setvariable variable=JAVA_HOME_17_X64]${loc}"
  16. echo "##vso[task.setvariable variable=JAVA_HOME]${loc}"
  17. echo "##vso[task.setvariable variable=PATH]${loc}/bin:$(PATH)"
  18. displayName: Set JAVA_HOME Variable
  19. - task: Cache@2
  20. inputs:
  21. key: 'gradle | "$(Agent.OS)" | build.gradle | gradle.properties | src/main/resources/twilightforest.accesswidener'
  22. restoreKeys: gradle
  23. path: $(GRADLE_USER_HOME)
  24. displayName: Gradle build cache
  25. - bash: |
  26. while IFS= read -r line; do
  27. IFS='='; kvp=(${line}); unset IFS;
  28. if [[ ${#kvp[@]} -gt 1 ]]
  29. then
  30. key=${kvp[0]//"."/"_"}
  31. val=${kvp[1]}
  32. echo "##vso[task.setvariable variable=javaprops_${key}]${val}"
  33. fi
  34. done < ./gradle.properties
  35. displayName: Create Azure DevOps variables from gradle properties file
  36. - task: Gradle@2
  37. displayName: Create Release Build
  38. inputs:
  39. workingDirectory: ''
  40. options: '--build-cache --max-workers=1 -PCIRevision=$(javaprops_mod_version).$(revision) -PCIType=RELEASE'
  41. gradleWrapperFile: 'gradlew'
  42. gradleOptions: '-Xmx3072m'
  43. javaHomeOption: 'JDKVersion'
  44. jdkVersionOption: '17'
  45. jdkArchitectureOption: 'x64'
  46. publishJUnitResults: false
  47. testResultsFiles: '**/TEST-*.xml'
  48. tasks: 'build'
  49. - task: CopyFiles@2
  50. displayName: Copy Release build to artifact staging
  51. inputs:
  52. sourceFolder: './build/libs/'
  53. contents: 'twilightforest-*.jar'
  54. targetFolder: $(build.artifactStagingDirectory)
  55. condition: and(succeeded(), eq(variables['CreateArtifacts'], 'True'))
  56. - task: PublishPipelineArtifact@1
  57. displayName: 'Publish Artifacts'
  58. condition: and(succeeded(), eq(variables['CreateArtifacts'], 'True'))
  59. inputs:
  60. targetPath: '$(Build.ArtifactStagingDirectory)'
  61. artifact: '$(artifactName)'
  62. publishLocation: 'pipeline'
  63. - bash: |
  64. rawpath="pipelineartifact://teamtwilight/projectId/1ef09d39-06cf-41fa-ad98-7258b70c2a72/buildId/${BUILD_BUILDID}/artifactName/Release"
  65. path=$(echo -ne ${rawpath} | base64)
  66. path=$(echo -ne ${path} | tr -d ' ')
  67. jar="twilightforest-fabric-${JAVAPROPS_MINECRAFT_VERSION}-${JAVAPROPS_MOD_VERSION}.${REVISION}.jar"
  68. 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}"
  69. jobResult=${AGENT_JOBSTATUS^}
  70. Colour=65280
  71. if [ "${jobResult}" != "Succeeded" ]
  72. then
  73. Colour=16711680
  74. fi
  75. echo "##vso[task.setvariable variable=DiscordMessageColour]${Colour}"
  76. json="{
  77. \"title\": \"Build ${jobResult}\",
  78. \"url\": \"${SYSTEM_TEAMFOUNDATIONSERVERURI}Twilight%20Forest/_build/results?buildId=${BUILD_BUILDID}&view=results\",
  79. \"color\": ${Colour},
  80. \"fields\": [
  81. {
  82. \"name\": \"Author\",
  83. \"value\": \"${BUILD_SOURCEVERSIONAUTHOR}\"
  84. },
  85. {
  86. \"name\": \"Minecraft Version\",
  87. \"value\": \"${JAVAPROPS_MINECRAFT_VERSION}\"
  88. },
  89. {
  90. \"name\": \"Mod Version\",
  91. \"value\": \"${JAVAPROPS_MOD_VERSION}.${REVISION}\"
  92. },
  93. {
  94. \"name\": \"Fabric API Version\",
  95. \"value\": \"${JAVAPROPS_FABRIC_VERSION}\"
  96. },
  97. {
  98. \"name\": \"Fabric Loader Version\",
  99. \"value\": \"${JAVAPROPS_LOADER_VERSION}\"
  100. },
  101. {
  102. \"name\": \"Commit\",
  103. \"value\": \"[${BUILD_SOURCEVERSION:0:6}]${BUILD_REPOSITORY_URI}/commit/${BUILD_SOURCEVERSION}\"
  104. }"
  105. if [ "${jobResult}" = "Succeeded" ]
  106. then
  107. json="${json},
  108. {
  109. \"name\": \"Download\",
  110. \"value\": \"${downloadUrl}\"
  111. }"
  112. fi
  113. json="${json}
  114. ]
  115. }"
  116. json=$(echo ${json} | tr -d '\n' | sed 's/ //g')
  117. echo "##vso[task.setvariable variable=DiscordMessage]${json}"
  118. displayName: Format discord message
  119. condition: always()
  120. env:
  121. SYSTEM_ACCESSTOKEN: $(System.AccessToken)
  122. - task: ado-discord-webhook@1
  123. displayName: Announce Build to discord
  124. inputs:
  125. channelId: '$(DiscordChannelID)'
  126. webhookKey: '$(DiscordChannelSecret)'
  127. messageType: 'embeds'
  128. embeds: |
  129. [$(DiscordMessage)]
  130. condition: and(always(), eq(variables['CreateArtifacts'], 'True'))
  131. #- task: Gradle@2
  132. # displayName: Publish to Maven
  133. # inputs:
  134. # workingDirectory: ''
  135. # options: '-PCIRevision=$(javaprops_mod_version).$(revision) -PCIType=RELEASE'
  136. # gradleWrapperFile: 'gradlew'
  137. # gradleOptions: '-Xmx3072m'
  138. # javaHomeOption: 'JDKVersion'
  139. # jdkVersionOption: '16'
  140. # jdkArchitectureOption: 'x64'
  141. # publishJUnitResults: false
  142. # testResultsFiles: '**/TEST-*.xml'
  143. # tasks: 'publish'
  144. # condition: and(succeeded(), eq(variables['CreateArtifacts'], 'True'))
  145. # env:
  146. # ARTIFACTORY_USER: $(Artifactory.User)
  147. # ARTIFACTORY_PASS: $(Artifactory.Password)
  148. - script: |
  149. # stop the Gradle daemon to ensure no files are left open (impacting the save cache operation later)
  150. ./gradlew --stop
  151. displayName: Kill Daemon