@@ -2,16 +2,117 @@ name: Upload dev build from PR (placeholder, not yet implemented)
22
33on :
44 workflow_run :
5- workflows : ["CI "] # ci .yml
5+ workflows : ["Publish Dist "] # publish-dist .yml
66 types :
77 - completed
88 workflow_dispatch :
9-
9+ inputs :
10+ pr_number :
11+ description : ' PR Number to deploy'
12+ required : true
13+ run_id :
14+ description : ' The Run ID of the CI workflow that has the artifact'
15+ required : true
1016
1117jobs :
12- hello :
18+ upload :
1319 runs-on : ubuntu-latest
20+ if : |
21+ github.event_name == 'workflow_dispatch' ||
22+ (
23+ github.event_name == 'workflow_run' &&
24+ github.event.workflow_run.event == 'pull_request' &&
25+ github.event.workflow_run.conclusion == 'success'
26+ )
1427 steps :
15- - name : Hello World
28+ - name : Download build artifact
29+ id : download-artifact
30+ uses : actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
31+ with :
32+ name : dist-node22 # uploaded by publish-dist.yml > publish-dist-node-v22
33+ run-id : ${{ github.event.workflow_run.id || inputs.run_id }}
34+ github-token : ${{ secrets.GITHUB_TOKEN }}
35+ path : temp-dist
36+
37+ - name : Setup metadata and prepare folders
38+ id : setup-metadata
39+ env :
40+ GH_TOKEN : ${{ github.token }}
41+ PR_NUM : ${{ github.event.workflow_run.pull_requests[0].number || inputs.pr_number }}
42+ run : |
43+ # Get SHA from triggering workflow, or from manual input
44+ if [ "${{ github.event_name }}" == "workflow_run" ]; then
45+ SHA="${{ github.event.workflow_run.head_sha }}"
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}}')
49+ fi
50+ SHORT_SHA=${SHA::7}
51+ UPLOAD_DIR_NAME="upload"
52+
53+ echo "Using SHA: ${SHA}"
54+ echo "Short SHA: ${SHORT_SHA}"
55+ mkdir -p "${UPLOAD_DIR_NAME}/pr-${PR_NUM}/latest"
56+ mkdir -p "${UPLOAD_DIR_NAME}/pr-${PR_NUM}/${SHORT_SHA}"
57+ # Copy all 3 artifacts (plotly.js, plotly.min.js, plot-schema.json) to /latest/
58+ cp temp-dist/plotly.js "${UPLOAD_DIR_NAME}/pr-${PR_NUM}/latest/plotly.js"
59+ cp temp-dist/plotly.min.js "${UPLOAD_DIR_NAME}/pr-${PR_NUM}/latest/plotly.min.js"
60+ cp temp-dist/plot-schema.json "${UPLOAD_DIR_NAME}/pr-${PR_NUM}/latest/plot-schema.json"
61+ # Copy only plotly.min.js to /$SHORT_SHA/
62+ cp temp-dist/plotly.min.js "${UPLOAD_DIR_NAME}/pr-${PR_NUM}/${SHORT_SHA}/plotly.min.js"
63+
64+ UPLOAD_DIR_FULL_PATH=$(pwd)/${UPLOAD_DIR_NAME}/
65+ echo "Created directory ${UPLOAD_DIR_FULL_PATH} with the following contents:"
66+ echo "$(ls -lR ${UPLOAD_DIR_FULL_PATH})"
67+
68+ echo "PR_NUM=${PR_NUM}" >> $GITHUB_OUTPUT
69+ echo "SHA=${SHA}" >> $GITHUB_OUTPUT
70+ echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_OUTPUT
71+
72+ - name : Generate GitHub App token
73+ id : generate-token
74+ uses : actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
75+ with :
76+ client-id : ${{ vars.DEV_DEPLOY_APP_ID }}
77+ private-key : ${{ secrets.DEV_DEPLOY_APP_PRIVATE_KEY }}
78+ owner : plotly
79+ repositories : plotly.js-dev-builds
80+
81+ - name : Check out plotly.js-dev-builds repo
82+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
83+ with :
84+ repository : plotly/plotly.js-dev-builds
85+ token : ${{ steps.generate-token.outputs.token }} # token from previous step
86+ path : plotly.js-dev-builds
87+
88+ - name : Commit and push files
89+ id : commit-and-push
90+ run : |
91+ # 1. Move 'upload' directory into repo folder and cd into repo root
92+ mkdir -p plotly.js-dev-builds/upload/
93+ cp -r upload/ plotly.js-dev-builds/
94+ cd plotly.js-dev-builds
95+
96+ # 2. Configure git
97+ git config user.name "plotly.js-pr-upload"
98+ git config user.email "<>"
99+
100+ # 3. add, commit, and push
101+ git add upload/
102+
103+ # Only commit if there are changes
104+ if git diff --staged --quiet; then
105+ echo "No changes to commit"
106+ else
107+ git commit -m "Deploy build for PR #${{ steps.setup-metadata.outputs.PR_NUM }} (commit ${{ steps.setup-metadata.outputs.SHORT_SHA }})"
108+ git push origin main
109+ fi
110+
111+ - name : Generate summary
16112 run : |
17- echo "Hello World"
113+ BASE="https://plotly.github.io/plotly.js-dev-builds/upload/pr-${{ steps.setup-metadata.outputs.PR_NUM }}"
114+ echo "### PR Build Uploaded" >> $GITHUB_STEP_SUMMARY
115+ echo "Builds for PR #${{ steps.setup-metadata.outputs.PR_NUM }} can be accessed at:" >> $GITHUB_STEP_SUMMARY
116+ 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
118+ echo "The above links should start working a minute or two after this job completes." >> $GITHUB_STEP_SUMMARY
0 commit comments