|
| 1 | +name: Deploy dev build from PR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["CI"] # ci.yml |
| 6 | + types: |
| 7 | + - completed |
| 8 | + |
| 9 | +jobs: |
| 10 | + deploy: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: github.event.workflow_run.event == 'pull_request' |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Download Build Artifact |
| 16 | + id: download-artifact |
| 17 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 |
| 18 | + continue-on-error: true |
| 19 | + with: |
| 20 | + name: plotly.node22.js # uploaded by ci.yml > publish-dist-node-v22 |
| 21 | + run-id: ${{ github.event.workflow_run.id }} |
| 22 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 23 | + path: temp-dist |
| 24 | + |
| 25 | + - name: Check if Artifact Exists |
| 26 | + if: steps.download-artifact.outcome != 'success' |
| 27 | + run: | |
| 28 | + echo "No build artifact found for this run. Skipping deployment." |
| 29 | + exit 0 |
| 30 | +
|
| 31 | + - name: Prepare Folder Structure |
| 32 | + id: prepare-folder-structure |
| 33 | + run: | |
| 34 | + PR_NUM="${{ github.event.workflow_run.pull_requests[0].number }}" |
| 35 | + SHA="${{ github.event.workflow_run.head_sha }}" |
| 36 | + |
| 37 | + mkdir -p "deploy/pr-$PR_NUM/$SHA" |
| 38 | + mkdir -p "deploy/pr-$PR_NUM/latest" |
| 39 | + |
| 40 | + # Name of file must match name of file uploaded by ci.yml > publish-dist-node-v22 |
| 41 | + cp temp-dist/plotly.node22.js "deploy/pr-$PR_NUM/$SHA/plotly.js" |
| 42 | + cp temp-dist/plotly.node22.js "deploy/pr-$PR_NUM/latest/plotly.js" |
| 43 | + |
| 44 | + echo "PR_NUM=$PR_NUM" >> $GITHUB_OUTPUT |
| 45 | + echo "SHA=$SHA" >> $GITHUB_OUTPUT |
| 46 | +
|
| 47 | + - name: Generate GitHub App Token |
| 48 | + id: generate-token |
| 49 | + uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 #v3.1.1 |
| 50 | + with: |
| 51 | + app-id: ${{ variables.DEV_DEPLOY_APP_ID }} |
| 52 | + private-key: ${{ secrets.DEV_DEPLOY_APP_PRIVATE_KEY }} |
| 53 | + owner: plotly |
| 54 | + repositories: plotly.js-dev-builds |
| 55 | + |
| 56 | + - name: Deploy to plotly.js-dev-builds repo |
| 57 | + uses: JamesIves/github-pages-deploy-action@d92aa235d04922e8f08b40ce78cc5442fcfbfa2f # v4.8.0 |
| 58 | + with: |
| 59 | + repository-name: plotly/plotly.js-dev-builds |
| 60 | + token: ${{ steps.generate-token.outputs.token }} # create-github-app-token action automatically outputs the token |
| 61 | + branch: gh-pages |
| 62 | + folder: deploy |
| 63 | + target-folder: . |
| 64 | + clean: false |
| 65 | + |
| 66 | + - name: Generate Summary |
| 67 | + run: | |
| 68 | + BASE="https://plotly.github.io/plotly.js-dev-builds/pr-${{ steps.prepare-folder-structure.outputs.PR_NUM }}" |
| 69 | + echo "### PR Build Deployed" >> $GITHUB_STEP_SUMMARY |
| 70 | + echo "Builds for PR #${{ steps.prepare-folder-structure.outputs.PR_NUM }} are available:" >> $GITHUB_STEP_SUMMARY |
| 71 | + echo "- [Latest for PR]($BASE/latest/plotly.js)" >> $GITHUB_STEP_SUMMARY |
| 72 | + echo "- [Immutable (this commit)]($BASE/${{ steps.prepare-folder-structure.outputs.SHA }}/plotly.js)" >> $GITHUB_STEP_SUMMARY |
0 commit comments