promote-packages.yaml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. # This automation promotes 3p packages based on a merge to default branches
  2. name: Promote 3P Packages
  3. on:
  4. # Allows you to run this workflow manually from the Actions screen
  5. workflow_dispatch:
  6. inputs:
  7. PR-num:
  8. type: string
  9. required: false
  10. description: PR number to pull from. Leave blank to pull from last successful run
  11. Run-id-num:
  12. type: string
  13. required: false
  14. description: Run id number (located in the build url) to pull from. Leave blank to pull from last successful run
  15. push:
  16. branches:
  17. - main
  18. - development
  19. paths:
  20. - 'package_build_list_host_*.json'
  21. jobs:
  22. deploy-dev:
  23. name: Deploying to dev S3 bucket
  24. runs-on: ubuntu-latest
  25. environment: development
  26. env:
  27. PACKAGE_PATH: packages/
  28. outputs:
  29. filelist: "${{ steps.dev-upload.outputs.filelist }}"
  30. steps:
  31. - name: Download packages
  32. uses: dawidd6/[email protected]
  33. with:
  34. workflow: build-pr-packages.yaml
  35. pr: ${{ inputs.PR-num }}
  36. run_id: ${{ inputs.Run-id-num }}
  37. check_artifacts: true
  38. path: ${{ env.PACKAGE_PATH }}
  39. - name: Check if package already exists in prod
  40. env:
  41. PROD_CDN: ${{ vars.PROD_CDN }} # Change this to compare on your own endpoint
  42. run: |
  43. find ${{ env.PACKAGE_PATH }} -type f | while read file; do
  44. filename=$(basename "$file")
  45. url="${{ env.PROD_CDN }}/${filename}"
  46. if curl --head --silent --fail ${url} > /dev/null 2>&1; then
  47. echo ${filename} already exists in prod. Check the rev in the json file to ensure it is incremented
  48. exit 1
  49. else
  50. echo ${filename} does not exist in CDN, continuing...
  51. fi
  52. done
  53. - name: Configure AWS Credentials
  54. uses: aws-actions/configure-aws-credentials@v4
  55. with:
  56. aws-access-key-id : ${{ secrets.AWS_CREDS_ACCESS_KEY }}
  57. aws-secret-access-key: ${{ secrets.AWS_CREDS_SECRET_KEY }}
  58. aws-region : ${{ secrets.AWS_CREDS_REGION_NAME }}
  59. - name: Copy to S3
  60. id: dev-upload
  61. shell: bash
  62. run: |
  63. find ${{ env.PACKAGE_PATH }} -type f | while read file; do
  64. filename=$(basename "$file")
  65. aws s3 cp "$file" "s3://${{ secrets.AWS_PACKAGE_DEV_S3_BUCKET }}/$filename" --acl bucket-owner-full-control
  66. FILELIST="$FILELIST$filename,"
  67. echo "filelist=$( echo "$FILELIST" )" >> $GITHUB_OUTPUT
  68. done
  69. create-o3de-3p-pr:
  70. name: Create PR in O3DE to update version
  71. needs: deploy-dev
  72. runs-on: ubuntu-latest
  73. env:
  74. O3DE_REPO_PATH: o3de
  75. DEV_CDN: ${{ vars.DEV_CDN }} # Change this to use your own endpoint
  76. UPLOADED_FILES: "${{ needs.deploy-dev.outputs.filelist }}"
  77. steps:
  78. - name: Checkout o3de repository
  79. uses: actions/checkout@v4
  80. with:
  81. repository: o3de/o3de
  82. token: ${{ secrets.GHA_TOKEN }}
  83. path: o3de
  84. - name: Copy dev package from S3
  85. run: |
  86. IFS=',' read -ra FILES <<< "$UPLOADED_FILES"
  87. for filename in "${FILES[@]}"; do
  88. if [[ $filename == *.tar.xz.SHA256SUMS ]]; then
  89. wget "${{ env.DEV_CDN }}/$filename"
  90. fi
  91. done
  92. - name: Update BuiltInPackages with new SHA256 and version
  93. shell: bash
  94. run: |
  95. IFS=',' read -ra FILENAMES <<<"$UPLOADED_FILES"
  96. for filename in "${FILENAMES[@]}"; do
  97. if [[ $filename == *.tar.xz.SHA256SUMS ]]; then
  98. content=$(cat "$filename")
  99. file=$(echo "$content" | awk -F'*' '{print $2}' | sed 's/.tar.xz//g') # *<package_name>-<version>-o3de-<rev>-<platform>.tar.xz
  100. hash=$(echo "$content" | awk '{print $1}')
  101. PACKAGE_NAME=$(echo "$file" | cut -d'-' -f1-2) # Extract package name without platform
  102. PARTIAL_PACKAGE_NAME=$(echo "$PACKAGE_NAME" | cut -d'-' -f1) # Extract the first part of the package name for matching
  103. PLATFORM=$(echo "$file" | rev | cut -d'-' -f1 | rev)
  104. # Determine x86 or aarch64 cmake file name based on file suffix
  105. if [[ $file == *linux-aarch64 ]]; then
  106. CMAKE_FILE=BuiltInPackages_linux_aarch64.cmake
  107. PLATFORM=linux
  108. elif [[ $file == *linux ]]; then
  109. CMAKE_FILE=BuiltInPackages_linux_x86_64.cmake
  110. elif [[ $file == *darwin ]]; then
  111. CMAKE_FILE=BuiltInPackages_mac.cmake
  112. PLATFORM=mac
  113. else
  114. CMAKE_FILE=BuiltInPackages_$PLATFORM.cmake
  115. fi
  116. FILE_PATH="${{ env.O3DE_REPO_PATH }}/cmake/3rdParty/Platform/${PLATFORM^}/$CMAKE_FILE"
  117. if [[ $PLATFORM == ios ]]; then
  118. FILE_PATH="${{ env.O3DE_REPO_PATH }}/cmake/3rdParty/Platform/iOS/$CMAKE_FILE"
  119. fi
  120. # Sample the first line after the comment "# platform-specific" to detect width
  121. sample_line=$(awk '/# platform-specific/{getline; print}' "$FILE_PATH")
  122. # Detect the width of the line until TARGETS
  123. width_before_targets=$(echo "$sample_line" | awk -F'TARGETS' '{print length($1 FS) - length("ly_associate_package(PACKAGE_NAME ") - length(" TARGETS")}')
  124. # Construct the new line using printf with the detected width
  125. new_line=$(printf "ly_associate_package(PACKAGE_NAME %-*s TARGETS %-27s PACKAGE_HASH %s" $width_before_targets "$file" "$PARTIAL_PACKAGE_NAME" "$hash")
  126. test_path=$(grep -q "$PARTIAL_PACKAGE_NAME" "$FILE_PATH" && echo 0 || echo 1)
  127. if [ $test_path -eq 0 ]; then
  128. sed -i "s|ly_associate_package(PACKAGE_NAME $PARTIAL_PACKAGE_NAME-[^ ]* .*PACKAGE_HASH [a-f0-9]\{64\}|$new_line|g" "$FILE_PATH"
  129. else
  130. echo "$new_line" >> "$FILE_PATH"
  131. fi
  132. fi
  133. done
  134. echo "package_name=$PACKAGE_NAME" >> $GITHUB_ENV
  135. - name: Commit and create PR
  136. uses: peter-evans/create-pull-request@v5
  137. with:
  138. token: ${{ secrets.GHA_TOKEN }}
  139. path: ${{ env.O3DE_REPO_PATH }}
  140. base: development
  141. branch: "update-3p-${{ env.package_name }}-cmake-file"
  142. commit-message: "Update 3P version and SHA256 hash for ${{ env.package_name }}"
  143. title: "Update 3P version and SHA256 hash for ${{ env.package_name }}"
  144. body: "Automated PR to update 3P version and SHA256 for ${{ env.package_name }}"
  145. draft: true
  146. signoff: true
  147. delete-branch: true
  148. deploy-prod:
  149. name: Deploying to prod S3 bucket
  150. needs: [deploy-dev, create-o3de-3p-pr]
  151. runs-on: ubuntu-latest
  152. environment: production
  153. env:
  154. UPLOADED_FILES: "${{ needs.deploy-dev.outputs.filelist }}"
  155. steps:
  156. - name: Configure AWS Credentials
  157. uses: aws-actions/configure-aws-credentials@v4
  158. with:
  159. aws-access-key-id : ${{ secrets.AWS_CREDS_ACCESS_KEY }}
  160. aws-secret-access-key: ${{ secrets.AWS_CREDS_SECRET_KEY }}
  161. aws-region : ${{ secrets.AWS_CREDS_REGION_NAME }}
  162. - name: Promote dev package to prod
  163. run: |
  164. IFS=',' read -ra FILES <<< "$UPLOADED_FILES"
  165. for filename in "${FILES[@]}"; do
  166. aws s3 cp "s3://${{ secrets.AWS_PACKAGE_DEV_S3_BUCKET }}/$filename" "s3://${{ secrets.AWS_PACKAGE_PROD_S3_BUCKET }}/$filename" --acl bucket-owner-full-control
  167. done