From 4ca51e1d4796f30d4d81186f131811f403314250 Mon Sep 17 00:00:00 2001 From: Emily KL <4672118+emilykl@users.noreply.github.com> Date: Thu, 30 Apr 2026 12:15:32 -0400 Subject: [PATCH] add upload-dev-build workflow --- .github/workflows/ci.yml | 117 ---------------------- .github/workflows/publish-dist.yml | 129 +++++++++++++++++++++++++ .github/workflows/upload-dev-build.yml | 110 ++++++++++++++++++++- 3 files changed, 234 insertions(+), 122 deletions(-) create mode 100644 .github/workflows/publish-dist.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79a69597525..5785b12c9bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -575,123 +575,6 @@ jobs: # ============================================================ # Standalone jobs (no dependencies on install-and-cibuild) # ============================================================ - publish-dist: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - with: - fetch-depth: 0 - fetch-tags: true - - - uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'npm' - - - name: Set up build environment - run: .github/scripts/env_build.sh - - - name: Preview CHANGELOG for next release (only on master) - if: github.ref == 'refs/heads/master' - run: npm run use-draftlogs && git --no-pager diff --color-words CHANGELOG.md || true - - - name: Set draft version in package.json - run: | - node --eval "var fs = require('fs'); var inOut = './package.json'; var data = JSON.parse(fs.readFileSync(inOut)); var a = process.argv; data.version = a[a.length - 1].replace('v', ''); fs.writeFileSync(inOut, JSON.stringify(data, null, 2) + '\n');" $(git describe) - - - name: View package.json diff between previous and next releases - run: git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) package.json || true - - - name: Build dist/ - run: npm run build - - # Upload library uncompressed to allow for testing in REPLs - - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 - name: Upload uncompressed plotly.js built from PR, using Node 22 - with: - retention-days: 30 - archive: false - path: dist/plotly.js - - - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 - name: Upload Node 18 archive of plotly.js build folder - with: - name: dist-node18 - retention-days: 7 - path: dist/ - - - name: View dist/README.md diff between previous and next releases - run: git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) dist/README.md || true - - - name: Preview plot-schema diff (only on master) - if: github.ref == 'refs/heads/master' - run: git --no-pager diff tags/$(git describe --tags --abbrev=0) dist/plot-schema.json || true - - - name: Test plot-schema.json diff - run: diff --unified --color dist/plot-schema.json test/plot-schema.json - - publish-dist-node-v22: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - with: - fetch-depth: 0 - fetch-tags: true - - - uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6 - with: - node-version: '22.14.0' - cache: 'npm' - - - name: Set up build environment - run: .github/scripts/env_build.sh - - - name: Preview CHANGELOG for next release (only on master) - if: github.ref == 'refs/heads/master' - run: npm run use-draftlogs && git --no-pager diff --color-words CHANGELOG.md || true - - - name: Set draft version in package.json - run: | - node --eval "var fs = require('fs'); var inOut = './package.json'; var data = JSON.parse(fs.readFileSync(inOut)); var a = process.argv; data.version = a[a.length - 1].replace('v', ''); fs.writeFileSync(inOut, JSON.stringify(data, null, 2) + '\n');" $(git describe) - - - name: View package.json diff between previous and next releases - run: git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) package.json || true - - - name: Build dist/ - run: npm run build - - # This is necessary to avoid a naming collision with the upload from the Node 18 build - - name: Copy library for upload - run: cp dist/plotly.js dist/plotly.node22.js - - # Upload library uncompressed to allow for testing in REPLs - - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 - name: Upload uncompressed plotly.js built from PR, using Node 22 - with: - retention-days: 30 - archive: false - path: dist/plotly.node22.js - - - name: Remove copy of library - run: rm dist/plotly.node22.js - - - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 - name: Upload Node 22 archive of plotly.js build folder - with: - name: dist-node22 - retention-days: 7 - path: dist/ - - - name: View dist/README.md diff between previous and next releases - run: git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) dist/README.md || true - - - name: Preview plot-schema diff (only on master) - if: github.ref == 'refs/heads/master' - run: git --no-pager diff tags/$(git describe --tags --abbrev=0) dist/plot-schema.json || true - - - name: Test plot-schema.json diff - run: diff --unified --color dist/plot-schema.json test/plot-schema.json - test-stackgl-bundle: needs: detect-changes if: >- diff --git a/.github/workflows/publish-dist.yml b/.github/workflows/publish-dist.yml new file mode 100644 index 00000000000..f4e93db3db8 --- /dev/null +++ b/.github/workflows/publish-dist.yml @@ -0,0 +1,129 @@ +name: Publish Dist + +on: + push: + branches: [master] + pull_request: + types: + - opened + - reopened + - synchronize + workflow_dispatch: + +concurrency: + group: publish-dist-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + NODE_VERSION: '18' + +jobs: + publish-dist: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + fetch-depth: 0 + fetch-tags: true + + - uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'npm' + + - name: Set up build environment + run: .github/scripts/env_build.sh + + - name: Preview CHANGELOG for next release (only on master) + if: github.ref == 'refs/heads/master' + run: npm run use-draftlogs && git --no-pager diff --color-words CHANGELOG.md || true + + - name: Set draft version in package.json + run: | + node --eval "var fs = require('fs'); var inOut = './package.json'; var data = JSON.parse(fs.readFileSync(inOut)); var a = process.argv; data.version = a[a.length - 1].replace('v', ''); fs.writeFileSync(inOut, JSON.stringify(data, null, 2) + '\n');" $(git describe) + + - name: View package.json diff between previous and next releases + run: git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) package.json || true + + - name: Build dist/ + run: npm run build + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 + name: Upload Node 18 archive of plotly.js build folder + with: + name: dist-node18 + retention-days: 7 + path: dist/ + + - name: View dist/README.md diff between previous and next releases + run: git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) dist/README.md || true + + - name: Preview plot-schema diff (only on master) + if: github.ref == 'refs/heads/master' + run: git --no-pager diff tags/$(git describe --tags --abbrev=0) dist/plot-schema.json || true + + - name: Test plot-schema.json diff + run: diff --unified --color dist/plot-schema.json test/plot-schema.json + + publish-dist-node-v22: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + fetch-depth: 0 + fetch-tags: true + + - uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6 + with: + node-version: '22.14.0' + cache: 'npm' + + - name: Set up build environment + run: .github/scripts/env_build.sh + + - name: Preview CHANGELOG for next release (only on master) + if: github.ref == 'refs/heads/master' + run: npm run use-draftlogs && git --no-pager diff --color-words CHANGELOG.md || true + + - name: Set draft version in package.json + run: | + node --eval "var fs = require('fs'); var inOut = './package.json'; var data = JSON.parse(fs.readFileSync(inOut)); var a = process.argv; data.version = a[a.length - 1].replace('v', ''); fs.writeFileSync(inOut, JSON.stringify(data, null, 2) + '\n');" $(git describe) + + - name: View package.json diff between previous and next releases + run: git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) package.json || true + + - name: Build dist/ + run: npm run build + + # This is necessary to avoid a naming collision with the upload from the Node 18 build + - name: Copy library for upload + run: cp dist/plotly.js dist/plotly.node22.js + + # Upload library uncompressed to allow for testing in REPLs + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 + name: Upload uncompressed plotly.js built from PR, using Node 22 + with: + name: plotly.node22.js + retention-days: 30 + archive: false + path: dist/plotly.node22.js + + - name: Remove copy of library + run: rm dist/plotly.node22.js + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 + name: Upload Node 22 archive of plotly.js build folder + with: + name: dist-node22 + retention-days: 7 + path: dist/ + + - name: View dist/README.md diff between previous and next releases + run: git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) dist/README.md || true + + - name: Preview plot-schema diff (only on master) + if: github.ref == 'refs/heads/master' + run: git --no-pager diff tags/$(git describe --tags --abbrev=0) dist/plot-schema.json || true + + - name: Test plot-schema.json diff + run: diff --unified --color dist/plot-schema.json test/plot-schema.json diff --git a/.github/workflows/upload-dev-build.yml b/.github/workflows/upload-dev-build.yml index b7619a0caec..2a997219d63 100644 --- a/.github/workflows/upload-dev-build.yml +++ b/.github/workflows/upload-dev-build.yml @@ -2,16 +2,116 @@ name: Upload dev build from PR (placeholder, not yet implemented) on: workflow_run: - workflows: ["CI"] # ci.yml + workflows: ["Publish Dist"] # publish-dist.yml types: - completed workflow_dispatch: - + inputs: + pr_number: + description: 'PR Number to deploy' + required: true + run_id: + description: 'The Run ID of the CI workflow that has the artifact' + required: true jobs: - hello: + upload: runs-on: ubuntu-latest + if: | + github.event_name == 'workflow_dispatch' || + (github.event_name == 'workflow_run' && github.event.workflow_run.event == 'pull_request') steps: - - name: Hello World + - name: Download build artifact + id: download-artifact + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 + continue-on-error: true + with: + name: dist-node22 # uploaded by publish-dist.yml > publish-dist-node-v22 + run-id: ${{ github.event.workflow_run.id || inputs.run_id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + path: temp-dist + + - name: Check if artifact exists + if: steps.download-artifact.outcome != 'success' + env: + RUN_ID: ${{ github.event.workflow_run.id || inputs.run_id }} + run: | + echo "No build artifact found for $RUN_ID. Skipping upload." + exit 0 + + - name: Setup metadata and prepare folders + id: setup-metadata + env: + GH_TOKEN: ${{ github.token }} + PR_NUM: ${{ github.event.workflow_run.pull_requests[0].number || inputs.pr_number }} + run: | + # Get SHA from triggering workflow, or from manual input + if [ "${{ github.event_name }}" == "workflow_run" ]; then + SHA="${{ github.event.workflow_run.head_sha }}" + else + echo "Fetching latest SHA for PR #$PR_NUM..." + SHA=$(gh pr view "$PR_NUM" --repo ${{ github.repository }} --json headRefOid --template '{{.headRefOid}}') + fi + + echo "Using SHA: $SHA" + mkdir -p "upload/pr-$PR_NUM/$SHA" + cp temp-dist/plotly.js "upload/pr-$PR_NUM/$SHA/plotly.js" + cp temp-dist/plotly.min.js "upload/pr-$PR_NUM/$SHA/plotly.min.js" + cp temp-dist/plot-schema.json "upload/pr-$PR_NUM/$SHA/plot-schema.json" + cp -r "upload/pr-$PR_NUM/$SHA/" "upload/pr-$PR_NUM/latest/" + + UPLOAD_DIR_PATH=$(pwd)/upload/ + + echo "Created directory ${UPLOAD_DIR_PATH} with the following contents:" + echo "$(ls -lR ${UPLOAD_DIR_PATH})" + + echo "PR_NUM=$PR_NUM" >> $GITHUB_OUTPUT + echo "SHA=$SHA" >> $GITHUB_OUTPUT + echo "SHORT_SHA=${SHA::7}" >> $GITHUB_OUTPUT + + - name: Generate GitHub App token + id: generate-token + uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 #v3.1.1 + with: + client-id: ${{ vars.DEV_DEPLOY_APP_ID }} + private-key: ${{ secrets.DEV_DEPLOY_APP_PRIVATE_KEY }} + owner: plotly + repositories: plotly.js-dev-builds + + - name: Check out plotly.js-dev-builds repo + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + repository: plotly/plotly.js-dev-builds + token: ${{ steps.generate-token.outputs.token }} # token from previous step + path: plotly.js-dev-builds + + - name: Commit and push files + id: commit-and-push + run: | + # 1. Move 'upload' directory into repo folder and cd into repo root + mkdir -p plotly.js-dev-builds/upload/ + cp -r upload/ plotly.js-dev-builds/ + cd plotly.js-dev-builds + + # 2. Configure git + git config user.name "plotly.js-pr-upload" + git config user.email "<>" + + # 3. add, commit, and push + git add upload/ + + # Only commit if there are changes + if git diff --staged --quiet; then + echo "No changes to commit" + else + git commit -m "Deploy build for PR #${{ steps.setup-metadata.outputs.PR_NUM }} (commit ${{ steps.setup-metadata.outputs.SHORT_SHA }})" + git push origin main + fi + + - name: Generate summary run: | - echo "Hello World" + BASE="https://plotly.github.io/plotly.js-dev-builds/upload/pr-${{ steps.setup-metadata.outputs.PR_NUM }}" + echo "### PR Build Uploaded" >> $GITHUB_STEP_SUMMARY + echo "Builds for PR #${{ steps.setup-metadata.outputs.PR_NUM }} are available:" >> $GITHUB_STEP_SUMMARY + echo "- Latest build for this PR: [$BASE/latest/plotly.min.js]($BASE/latest/plotly.min.js)" >> $GITHUB_STEP_SUMMARY + echo "- Build for this commit (permalink): [$BASE/${{ steps.setup-metadata.outputs.SHA }}/plotly.min.js]($BASE/${{ steps.setup-metadata.outputs.SHA }}/plotly.min.js)" >> $GITHUB_STEP_SUMMARY