download-artifacts.yml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. name: Download Artifacts from Run
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. run_id:
  6. description: 'GitHub Actions Run ID to download artifacts from'
  7. required: true
  8. type: string
  9. release_tag:
  10. description: 'Release tag to upload to'
  11. required: true
  12. type: string
  13. jobs:
  14. download-and-upload:
  15. runs-on: ubuntu-latest
  16. env:
  17. GH_TOKEN: ${{ github.token }}
  18. steps:
  19. - name: Checkout repository
  20. uses: actions/checkout@v4
  21. - name: Set target release tag
  22. id: get_release
  23. run: |
  24. echo "tag=${{ inputs.release_tag }}" >> $GITHUB_OUTPUT
  25. echo "Using release tag: ${{ inputs.release_tag }}"
  26. # Verify the release exists
  27. if ! gh release view "${{ inputs.release_tag }}" >/dev/null 2>&1; then
  28. echo "Error: Release '${{ inputs.release_tag }}' does not exist"
  29. echo "Available releases:"
  30. gh release list --limit 10
  31. exit 1
  32. fi
  33. echo "Release '${{ inputs.release_tag }}' found and verified"
  34. - name: Download AnyKernel3 artifacts from specified run
  35. run: |
  36. echo "Downloading AnyKernel3 artifacts from run ID: ${{ inputs.run_id }}"
  37. # Create directory for downloaded artifacts
  38. mkdir -p ./downloaded-artifacts
  39. # Get list of all artifacts from the run
  40. echo "Getting artifact list from run..."
  41. gh api repos/${{ github.repository }}/actions/runs/${{ inputs.run_id }}/artifacts --jq '.artifacts[] | select(.name | endswith("-AnyKernel3")) | {name: .name, id: .id}' > artifacts.json
  42. # Check if any AnyKernel3 artifacts were found
  43. if [ ! -s artifacts.json ]; then
  44. echo "Error: No AnyKernel3 artifacts found in run ${{ inputs.run_id }}"
  45. echo "Available artifacts in this run:"
  46. gh api repos/${{ github.repository }}/actions/runs/${{ inputs.run_id }}/artifacts --jq '.artifacts[].name'
  47. exit 1
  48. fi
  49. echo "Found AnyKernel3 artifacts:"
  50. cat artifacts.json
  51. # Download only the AnyKernel3 artifacts
  52. while IFS= read -r artifact; do
  53. artifact_name=$(echo "$artifact" | jq -r '.name')
  54. artifact_id=$(echo "$artifact" | jq -r '.id')
  55. echo "Downloading artifact: $artifact_name (ID: $artifact_id)"
  56. gh api repos/${{ github.repository }}/actions/artifacts/$artifact_id/zip > "${artifact_name}.zip"
  57. # Extract the artifact
  58. unzip -q "${artifact_name}.zip" -d "./downloaded-artifacts/${artifact_name}/"
  59. rm "${artifact_name}.zip"
  60. done < <(jq -c '.' artifacts.json)
  61. echo "Downloaded AnyKernel3 artifacts:"
  62. ls -la ./downloaded-artifacts/
  63. - name: Prepare and upload AnyKernel3 artifacts to release
  64. run: |
  65. echo "Preparing AnyKernel3 artifacts for upload..."
  66. # Check if we have any downloaded artifacts
  67. if [ ! -d "./downloaded-artifacts" ] || [ -z "$(ls -A ./downloaded-artifacts)" ]; then
  68. echo "Error: No artifacts were downloaded"
  69. exit 1
  70. fi
  71. # Process each AnyKernel3 artifact directory
  72. for artifact_dir in ./downloaded-artifacts/*/; do
  73. if [ -d "$artifact_dir" ]; then
  74. # Get the artifact name (remove path and trailing slash)
  75. artifact_name=$(basename "$artifact_dir")
  76. echo "Processing artifact: $artifact_name"
  77. # Create ZIP file with the artifact name
  78. # The ZIP will contain all subfolders and subfiles from the artifact
  79. cd "$artifact_dir"
  80. zip -r "../../${artifact_name}.zip" . -x "*.git*"
  81. cd - > /dev/null
  82. echo "Created ZIP: ${artifact_name}.zip"
  83. # Upload to release
  84. echo "Uploading ${artifact_name}.zip to release ${{ steps.get_release.outputs.tag }}..."
  85. gh release upload "${{ steps.get_release.outputs.tag }}" "${artifact_name}.zip" --clobber --repo ${{ github.repository }}
  86. echo "Successfully uploaded: ${artifact_name}.zip"
  87. fi
  88. done
  89. echo "All AnyKernel3 artifacts have been processed and uploaded!"
  90. # Show final summary
  91. echo "## Upload Summary" >> $GITHUB_STEP_SUMMARY
  92. echo "| Artifact | Status |" >> $GITHUB_STEP_SUMMARY
  93. echo "|----------|--------|" >> $GITHUB_STEP_SUMMARY
  94. for artifact_dir in ./downloaded-artifacts/*/; do
  95. if [ -d "$artifact_dir" ]; then
  96. artifact_name=$(basename "$artifact_dir")
  97. echo "| ${artifact_name}.zip | ✅ Uploaded |" >> $GITHUB_STEP_SUMMARY
  98. fi
  99. done
  100. - name: Summary
  101. run: |
  102. echo "## Artifact Download and Upload Summary" >> $GITHUB_STEP_SUMMARY
  103. echo "- **Source Run ID**: ${{ inputs.run_id }}" >> $GITHUB_STEP_SUMMARY
  104. echo "- **Target Release**: ${{ env.RELEASE_TAG }}" >> $GITHUB_STEP_SUMMARY
  105. echo "- **Repository**: ${{ github.repository }}" >> $GITHUB_STEP_SUMMARY
  106. echo "" >> $GITHUB_STEP_SUMMARY
  107. echo "### Artifacts Processed" >> $GITHUB_STEP_SUMMARY
  108. for dir in ./downloaded-artifacts/*/; do
  109. if [[ "$(basename "$dir")" == *"-AnyKernel3" ]]; then
  110. artifact_name=$(basename "$dir")
  111. echo "- ✅ $artifact_name" >> $GITHUB_STEP_SUMMARY
  112. fi
  113. done
  114. echo "" >> $GITHUB_STEP_SUMMARY
  115. echo "[🔗 View Release](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ env.RELEASE_TAG }})" >> $GITHUB_STEP_SUMMARY