|
9 | 9 | inputs: |
10 | 10 | pr_number: |
11 | 11 | description: 'PR Number to deploy' |
12 | | - required: true |
| 12 | + required: false |
13 | 13 | run_id: |
14 | 14 | description: 'The Run ID of the CI workflow that has the artifact' |
15 | 15 | required: true |
@@ -44,14 +44,35 @@ jobs: |
44 | 44 | if [ "${{ github.event_name }}" == "workflow_run" ]; then |
45 | 45 | SHA="${{ github.event.workflow_run.head_sha }}" |
46 | 46 | else |
47 | | - echo "Fetching latest SHA for PR #$PR_NUM..." |
48 | | - SHA=$(gh pr view "$PR_NUM" --repo ${{ github.repository }} --json headRefOid --template '{{.headRefOid}}') |
| 47 | + echo "Fetching latest SHA for PR #${PR_NUM}..." |
| 48 | + if [ -n "${PR_NUM}" ]; then |
| 49 | + SHA=$(gh pr view "${PR_NUM}" --repo "${{ github.repository }}" --json headRefOid --template '{{.headRefOid}}') |
| 50 | + fi |
| 51 | + fi |
| 52 | +
|
| 53 | + # Validate that we have a SHA |
| 54 | + if [ -z "${SHA}" ]; then |
| 55 | + echo "Failed to get commit SHA, exiting" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | +
|
| 59 | + # If PR_NUM is empty (this is the case for forks) get PR number using SHA |
| 60 | + if [ -z "${PR_NUM}" ]; then |
| 61 | + PR_NUM=$(gh pr list --search "sha:${SHA}" --state open --json number --jq '.[0].number') |
| 62 | + fi |
| 63 | +
|
| 64 | + # Validate that we have a PR number and that it is less than 5 characters |
| 65 | + if [ -z "${PR_NUM}" ] || [ ${#PR_NUM} -gt 5 ]; then |
| 66 | + echo "Failed to get PR number, exiting (PR_NUM=${PR_NUM})" |
| 67 | + exit 1 |
49 | 68 | fi |
| 69 | +
|
50 | 70 | SHORT_SHA=${SHA::7} |
51 | 71 | UPLOAD_DIR_NAME="upload" |
52 | 72 |
|
53 | | - echo "Using SHA: ${SHA}" |
| 73 | + echo "SHA: ${SHA}" |
54 | 74 | echo "Short SHA: ${SHORT_SHA}" |
| 75 | + echo "PR number: ${PR_NUM}" |
55 | 76 | mkdir -p "${UPLOAD_DIR_NAME}/pr-${PR_NUM}/latest" |
56 | 77 | mkdir -p "${UPLOAD_DIR_NAME}/pr-${PR_NUM}/${SHORT_SHA}" |
57 | 78 | # Copy all 3 artifacts (plotly.js, plotly.min.js, plot-schema.json) to /latest/ |
@@ -114,5 +135,5 @@ jobs: |
114 | 135 | echo "### PR Build Uploaded" >> $GITHUB_STEP_SUMMARY |
115 | 136 | echo "Builds for PR #${{ steps.setup-metadata.outputs.PR_NUM }} can be accessed at:" >> $GITHUB_STEP_SUMMARY |
116 | 137 | echo "- Latest build for this PR: [$BASE/latest/plotly.min.js]($BASE/latest/plotly.min.js)" >> $GITHUB_STEP_SUMMARY |
117 | | - echo "- Build for this commit: [$BASE/${{ steps.setup-metadata.outputs.SHA }}/plotly.min.js]($BASE/${{ steps.setup-metadata.outputs.SHA }}/plotly.min.js)" >> $GITHUB_STEP_SUMMARY |
| 138 | + echo "- Build for this commit: [$BASE/${{ steps.setup-metadata.outputs.SHA }}/plotly.min.js]($BASE/${{ steps.setup-metadata.outputs.SHORT_SHA }}/plotly.min.js)" >> $GITHUB_STEP_SUMMARY |
118 | 139 | echo "The above links should start working a minute or two after this job completes." >> $GITHUB_STEP_SUMMARY |
0 commit comments