Comment Artifact URL on PR #9793
This file contains 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" | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
comment-success: | |
if: github.event.workflow_run.conclusion == 'success' | |
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" | |
if [[ $GITHUB_REF == refs/tags/v* ]]; then | |
ARTIFACT_S3_DESTINATION_PATH="@dcl/$REPO/releases/$GITHUB_REF_NAME" | |
else | |
HEAD_BRANCH=$(jq -r '.pull_requests[0].head.ref' \ | |
<<< "$WORKFLOW_RUN_EVENT_OBJ") | |
ARTIFACT_S3_DESTINATION_PATH="@dcl/$REPO/branch/$HEAD_BRANCH" | |
fi | |
echo "Artifact S3 Destination Path: $ARTIFACT_S3_DESTINATION_PATH" | |
echo "ARTIFACT_S3_DESTINATION_PATH=$ARTIFACT_S3_DESTINATION_PATH" >> "$GITHUB_ENV" | |
PR_NUMBER=$(jq -r '.pull_requests[0].number' \ | |
<<< "$WORKFLOW_RUN_EVENT_OBJ") | |
echo "Pull request Number: $PR_NUMBER" | |
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV" | |
HEAD_SHA=$(jq -r '.pull_requests[0].head.sha' \ | |
<<< "$WORKFLOW_RUN_EVENT_OBJ") | |
echo "Head SHA: $HEAD_SHA" | |
echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV" | |
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
echo "Build done on: $BUILD_DATE" | |
echo "BUILD_DATE=$BUILD_DATE" >> "$GITHUB_ENV" | |
- name: Find Comment | |
uses: peter-evans/find-comment@v2 | |
id: find-comment | |
with: | |
issue-number: ${{ env.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: ${{ env.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 successfull 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 }} | | |
[badge]: https://img.shields.io/badge/Build-Success!-3fb950?logo=github&style=for-the-badge | |
comment-failed: | |
if: github.event.workflow_run.conclusion == 'failure' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get PR info | |
env: | |
WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }} | |
OWNER: ${{ github.repository_owner }} | |
REPO: ${{ github.event.repository.name }} | |
run: | | |
PR_NUMBER=$(jq -r '.pull_requests[0].number' \ | |
<<< "$WORKFLOW_RUN_EVENT_OBJ") | |
echo "Pull request Number: $PR_NUMBER" | |
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV" | |
- name: Find Comment | |
uses: peter-evans/find-comment@v2 | |
id: find-comment | |
with: | |
issue-number: ${{ env.PR_NUMBER }} | |
comment-author: 'github-actions[bot]' | |
- name: Update Comment | |
uses: peter-evans/create-or-update-comment@v3 | |
with: | |
issue-number: ${{ env.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 |