Comment Artifact URL on PR #27628
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # pr-comment-artifact-url.yml | |
| --- | |
| name: Comment Artifact URL on PR | |
| on: | |
| workflow_run: | |
| types: | |
| - "completed" | |
| workflows: | |
| - "Unity Cloud Build" | |
| branches-ignore: | |
| - "main" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| pre-validation: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| pr-number: ${{ steps.check-pr.outputs.pr-number }} | |
| steps: | |
| - name: Check if PR number exists | |
| id: check-pr | |
| env: | |
| WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }} | |
| run: | | |
| PR_NUMBER=$(jq -r '.pull_requests[0].number' <<< "$WORKFLOW_RUN_EVENT_OBJ") | |
| echo "Pull request Number: $PR_NUMBER" | |
| if [[ -z "$PR_NUMBER" || "$PR_NUMBER" == "null" ]]; then | |
| echo "PR_NUMBER is not set, skipping comment update." | |
| exit 0 | |
| fi | |
| echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT | |
| check-build-ran: | |
| needs: pre-validation | |
| if: needs.pre-validation.outputs.pr-number != '' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| build-ran: ${{ steps.check.outputs.build-ran }} | |
| steps: | |
| - name: Check if build jobs actually ran | |
| id: check | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| OWNER: ${{ github.repository_owner }} | |
| REPO: ${{ github.event.repository.name }} | |
| RUN_ID: ${{ github.event.workflow_run.id }} | |
| run: | | |
| # Check if any build artifacts exist (they only exist when Build jobs ran) | |
| ARTIFACT_COUNT=$(gh api "/repos/$OWNER/$REPO/actions/runs/$RUN_ID/artifacts" \ | |
| --jq '[.artifacts[] | select(.name | startswith("Decentraland_"))] | length') | |
| echo "Build artifact count: $ARTIFACT_COUNT" | |
| if [ "$ARTIFACT_COUNT" -gt 0 ]; then | |
| echo "build-ran=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "build-ran=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| comment-skipped: | |
| needs: [pre-validation, check-build-ran] | |
| if: github.event.workflow_run.conclusion == 'success' && needs.pre-validation.outputs.pr-number != '' && needs.check-build-ran.outputs.build-ran == 'false' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Find Comment | |
| uses: peter-evans/find-comment@v2 | |
| id: find-comment | |
| with: | |
| issue-number: ${{ needs.pre-validation.outputs.pr-number }} | |
| comment-author: 'github-actions[bot]' | |
| - name: Post skipped comment | |
| uses: peter-evans/create-or-update-comment@v3 | |
| with: | |
| issue-number: ${{ needs.pre-validation.outputs.pr-number }} | |
| comment-id: ${{ steps.find-comment.outputs.comment-id }} | |
| edit-mode: replace | |
| body: |- | |
| ![badge] <img src="https://ui.decentraland.org/decentraland_256x256.png" width="30"> | |
| Build skipped — no changes detected under `Explorer/`. | |
| [badge]: https://img.shields.io/badge/Build-Skipped-yellow?logo=github&style=for-the-badge | |
| comment-success: | |
| needs: [pre-validation, check-build-ran] | |
| if: github.event.workflow_run.conclusion == 'success' && needs.pre-validation.outputs.pr-number != '' && needs.check-build-ran.outputs.build-ran == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Get Artifact and Pull request info | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }} | |
| OWNER: ${{ github.repository_owner }} | |
| REPO: ${{ github.event.repository.name }} | |
| run: | | |
| PREVIOUS_JOB_ID=$(jq -r '.id' <<< "$WORKFLOW_RUN_EVENT_OBJ") | |
| echo "Previous Job ID: $PREVIOUS_JOB_ID" | |
| echo "PREVIOUS_JOB_ID=$PREVIOUS_JOB_ID" >> "$GITHUB_ENV" | |
| SUITE_ID=$(jq -r '.check_suite_id' <<< "$WORKFLOW_RUN_EVENT_OBJ") | |
| echo "Previous Suite ID: $SUITE_ID" | |
| echo "SUITE_ID=$SUITE_ID" >> "$GITHUB_ENV" | |
| WINDOWS_ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" \ | |
| --jq ".artifacts.[] | | |
| select(.workflow_run.id==${PREVIOUS_JOB_ID}) | | |
| select(.expired==false) | | |
| select(.name==\"Decentraland_windows64\") | | |
| .id") | |
| echo "Windows Artifact ID: $WINDOWS_ARTIFACT_ID" | |
| echo "WINDOWS_ARTIFACT_ID=$WINDOWS_ARTIFACT_ID" >> "$GITHUB_ENV" | |
| MAC_ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" \ | |
| --jq ".artifacts.[] | | |
| select(.workflow_run.id==${PREVIOUS_JOB_ID}) | | |
| select(.expired==false) | | |
| select(.name==\"Decentraland_macos\") | | |
| .id") | |
| echo "Mac Artifact ID: $MAC_ARTIFACT_ID" | |
| echo "MAC_ARTIFACT_ID=$MAC_ARTIFACT_ID" >> "$GITHUB_ENV" | |
| ORIGINAL_EVENT=$(jq -r '.event' <<< "$WORKFLOW_RUN_EVENT_OBJ") | |
| echo "Original Event: $ORIGINAL_EVENT" | |
| HEAD_SHA=$(jq -r '.pull_requests[0].head.sha // .head_sha' <<< "$WORKFLOW_RUN_EVENT_OBJ") | |
| echo "Head SHA: $HEAD_SHA" | |
| echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV" | |
| SHORT_SHA=$(echo "$HEAD_SHA" | cut -c1-7) | |
| echo "Short SHA: $SHORT_SHA" | |
| SAFE_BRANCH_NAME=$(jq -r '.pull_requests[0].head.ref // .head_branch' <<< "$WORKFLOW_RUN_EVENT_OBJ") | |
| echo "Safe Branch Name: $SAFE_BRANCH_NAME" | |
| echo "SAFE_BRANCH_NAME=$SAFE_BRANCH_NAME" >> "$GITHUB_ENV" | |
| RUN_NUMBER=$(jq -r '.run_number' <<< "$WORKFLOW_RUN_EVENT_OBJ") | |
| echo "Run number: $RUN_NUMBER" | |
| echo "RUN_NUMBER=$RUN_NUMBER" >> "$GITHUB_ENV" | |
| case "$ORIGINAL_EVENT" in | |
| pull_request) BUILD_PREFIX="pr" ;; | |
| push) BUILD_PREFIX="pu" ;; | |
| merge_group) BUILD_PREFIX="mg" ;; | |
| workflow_dispatch) BUILD_PREFIX="wd" ;; | |
| workflow_call) BUILD_PREFIX="wc" ;; | |
| schedule) BUILD_PREFIX="sc" ;; | |
| *) BUILD_PREFIX="gn" ;; | |
| esac | |
| echo "Build Prefix: $BUILD_PREFIX" | |
| ARTIFACT_S3_DESTINATION_PATH="@dcl/$REPO/branch/$SAFE_BRANCH_NAME/${BUILD_PREFIX}-${RUN_NUMBER}-${SHORT_SHA}" | |
| echo "Artifact S3 Destination Path: $ARTIFACT_S3_DESTINATION_PATH" | |
| echo "ARTIFACT_S3_DESTINATION_PATH=$ARTIFACT_S3_DESTINATION_PATH" >> "$GITHUB_ENV" | |
| BUILD_DATE=$(jq -r '.updated_at' <<< "$WORKFLOW_RUN_EVENT_OBJ") | |
| echo "Build done on: $BUILD_DATE" | |
| echo "BUILD_DATE=$BUILD_DATE" >> "$GITHUB_ENV" | |
| - name: Download size reports | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| OWNER: ${{ github.repository_owner }} | |
| REPO: ${{ github.event.repository.name }} | |
| run: | | |
| gh run download "$PREVIOUS_JOB_ID" \ | |
| --repo "$OWNER/$REPO" \ | |
| --name size_report_windows64_launcher \ | |
| --dir size_reports 2>/dev/null || true | |
| gh run download "$PREVIOUS_JOB_ID" \ | |
| --repo "$OWNER/$REPO" \ | |
| --name size_report_macos_launcher \ | |
| --dir size_reports 2>/dev/null || true | |
| WINDOWS_ROW=$(grep "^|" size_reports/size_report_windows64_launcher.md 2>/dev/null || true) | |
| MACOS_ROW=$(grep "^|" size_reports/size_report_macos_launcher.md 2>/dev/null || true) | |
| RELEASE_TAG=$(grep "^release_tag=" size_reports/size_report_windows64_launcher.md size_reports/size_report_macos_launcher.md 2>/dev/null | head -1 | cut -d= -f2 || true) | |
| if [ -n "$WINDOWS_ROW" ] || [ -n "$MACOS_ROW" ]; then | |
| { | |
| echo "SIZE_REPORT<<EOF" | |
| echo "### Artifact size check" | |
| echo "" | |
| echo "| Target | Size (MB / MiB) | Cap (MB) | Δ MB vs release | Δ % vs release | Result |" | |
| echo "|--------|----------------:|--------:|----------------:|---------------:|--------|" | |
| [ -n "$WINDOWS_ROW" ] && echo "$WINDOWS_ROW" | |
| [ -n "$MACOS_ROW" ] && echo "$MACOS_ROW" | |
| [ -n "$RELEASE_TAG" ] && echo "" && echo "_Comparing against: **${RELEASE_TAG}**_" | |
| echo "EOF" | |
| } >> "$GITHUB_ENV" | |
| else | |
| echo "SIZE_REPORT=" >> "$GITHUB_ENV" | |
| fi | |
| - name: Find Comment | |
| uses: peter-evans/find-comment@v2 | |
| id: find-comment | |
| with: | |
| issue-number: ${{ needs.pre-validation.outputs.pr-number }} | |
| comment-author: 'github-actions[bot]' | |
| - name: Update Comment | |
| env: | |
| JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}" | |
| WINDOWS_ARTIFACT_URL: "${{ github.server_url }}/${{ github.repository }}/suites/${{ env.SUITE_ID }}/artifacts/${{ env.WINDOWS_ARTIFACT_ID }}" | |
| WINDOWS_ARTIFACT_S3_URL: "${{ format('{0}/{1}/Decentraland_windows64.zip', vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL, env.ARTIFACT_S3_DESTINATION_PATH) }}" | |
| MAC_ARTIFACT_URL: "${{ github.server_url }}/${{ github.repository }}/suites/${{ env.SUITE_ID }}/artifacts/${{ env.MAC_ARTIFACT_ID }}" | |
| MAC_ARTIFACT_S3_URL: "${{ format('{0}/{1}/Decentraland_macos.zip', vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL, env.ARTIFACT_S3_DESTINATION_PATH) }}" | |
| HEAD_SHA: "${{ env.HEAD_SHA }}" | |
| uses: peter-evans/create-or-update-comment@v3 | |
| with: | |
| issue-number: ${{ needs.pre-validation.outputs.pr-number }} | |
| comment-id: ${{ steps.find-comment.outputs.comment-id }} | |
| edit-mode: replace | |
| body: |- | |
| ![badge] <img src="https://ui.decentraland.org/decentraland_256x256.png" width="30"> | |
| Windows and Mac build successful in Unity Cloud! You can find a link to the downloadable artifact below. | |
| | Name | Link | | |
| | -------- | ----------------------- | | |
| | Commit | ${{ env.HEAD_SHA }} | | |
| | Logs | ${{ env.JOB_PATH }} | | |
| | Download Windows | ${{ env.WINDOWS_ARTIFACT_URL }} | | |
| | Download Windows S3 | ${{ env.WINDOWS_ARTIFACT_S3_URL }} | | |
| | Download Mac | ${{ env.MAC_ARTIFACT_URL }} | | |
| | Download Mac S3 | ${{ env.MAC_ARTIFACT_S3_URL }} | | |
| | Built on | ${{ env.BUILD_DATE }} | | |
| ${{ env.SIZE_REPORT }} | |
| [badge]: https://img.shields.io/badge/Build-Success!-3fb950?logo=github&style=for-the-badge | |
| - name: Find latest release | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| run: gh release view -R $GITHUB_REPOSITORY --json tagName --template "RELEASE_TAG={{.tagName}}" >> $GITHUB_ENV | |
| - name: Trigger performance test | |
| uses: peter-evans/repository-dispatch@v4 | |
| with: | |
| repository: decentraland/performance-testing | |
| event-type: unity-explorer | |
| token: ${{ secrets.PERFORMANCE_TESTING_PAT }} | |
| client-payload: |- | |
| { | |
| "run_name": "${{ github.event.workflow_run.display_title }}", | |
| "pr_number": "${{ needs.pre-validation.outputs.pr-number }}", | |
| "win_change_build_url": "${{ vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL }}/${{ env.ARTIFACT_S3_DESTINATION_PATH }}/Decentraland_windows64.zip", | |
| "win_base_build_url": "${{ vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL }}/@dcl/unity-explorer/releases/${{ env.RELEASE_TAG }}/Decentraland_windows64.zip", | |
| "mac_change_build_url": "${{ vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL }}/${{ env.ARTIFACT_S3_DESTINATION_PATH }}/Decentraland_macos.zip", | |
| "mac_base_build_url": "${{ vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL }}/@dcl/unity-explorer/releases/${{ env.RELEASE_TAG }}/Decentraland_macos.zip" | |
| } | |
| comment-failed: | |
| needs: [pre-validation, check-build-ran] | |
| if: github.event.workflow_run.conclusion == 'failure' && needs.pre-validation.outputs.pr-number != '' && needs.check-build-ran.outputs.build-ran == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Find Comment | |
| uses: peter-evans/find-comment@v2 | |
| id: find-comment | |
| with: | |
| issue-number: ${{ needs.pre-validation.outputs.pr-number }} | |
| comment-author: 'github-actions[bot]' | |
| - name: Update Comment | |
| uses: peter-evans/create-or-update-comment@v3 | |
| with: | |
| issue-number: ${{ needs.pre-validation.outputs.pr-number }} | |
| comment-id: ${{ steps.find-comment.outputs.comment-id }} | |
| edit-mode: replace | |
| body: |- | |
| ![badge] <img src="https://ui.decentraland.org/decentraland_256x256.png" width="30"> | |
| Build failed! Check the logs to see what went wrong | |
| [badge]: https://img.shields.io/badge/Build-Failed!-ff0000?logo=github&style=for-the-badge |