Skip to content

Commit 92d110b

Browse files
authored
Merge pull request #7795 from plotly/persistent-dev-build-url-2
Add workflow for uploading dev builds of Plotly.js
2 parents d6bd654 + e09ca41 commit 92d110b

3 files changed

Lines changed: 192 additions & 122 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -575,123 +575,6 @@ jobs:
575575
# ============================================================
576576
# Standalone jobs (no dependencies on install-and-cibuild)
577577
# ============================================================
578-
publish-dist:
579-
runs-on: ubuntu-latest
580-
steps:
581-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
582-
with:
583-
fetch-depth: 0
584-
fetch-tags: true
585-
586-
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
587-
with:
588-
node-version: ${{ env.NODE_VERSION }}
589-
cache: 'npm'
590-
591-
- name: Set up build environment
592-
run: .github/scripts/env_build.sh
593-
594-
- name: Preview CHANGELOG for next release (only on master)
595-
if: github.ref == 'refs/heads/master'
596-
run: npm run use-draftlogs && git --no-pager diff --color-words CHANGELOG.md || true
597-
598-
- name: Set draft version in package.json
599-
run: |
600-
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)
601-
602-
- name: View package.json diff between previous and next releases
603-
run: git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) package.json || true
604-
605-
- name: Build dist/
606-
run: npm run build
607-
608-
# Upload library uncompressed to allow for testing in REPLs
609-
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
610-
name: Upload uncompressed plotly.js built from PR, using Node 22
611-
with:
612-
retention-days: 30
613-
archive: false
614-
path: dist/plotly.js
615-
616-
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
617-
name: Upload Node 18 archive of plotly.js build folder
618-
with:
619-
name: dist-node18
620-
retention-days: 7
621-
path: dist/
622-
623-
- name: View dist/README.md diff between previous and next releases
624-
run: git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) dist/README.md || true
625-
626-
- name: Preview plot-schema diff (only on master)
627-
if: github.ref == 'refs/heads/master'
628-
run: git --no-pager diff tags/$(git describe --tags --abbrev=0) dist/plot-schema.json || true
629-
630-
- name: Test plot-schema.json diff
631-
run: diff --unified --color dist/plot-schema.json test/plot-schema.json
632-
633-
publish-dist-node-v22:
634-
runs-on: ubuntu-latest
635-
steps:
636-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
637-
with:
638-
fetch-depth: 0
639-
fetch-tags: true
640-
641-
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
642-
with:
643-
node-version: '22.14.0'
644-
cache: 'npm'
645-
646-
- name: Set up build environment
647-
run: .github/scripts/env_build.sh
648-
649-
- name: Preview CHANGELOG for next release (only on master)
650-
if: github.ref == 'refs/heads/master'
651-
run: npm run use-draftlogs && git --no-pager diff --color-words CHANGELOG.md || true
652-
653-
- name: Set draft version in package.json
654-
run: |
655-
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)
656-
657-
- name: View package.json diff between previous and next releases
658-
run: git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) package.json || true
659-
660-
- name: Build dist/
661-
run: npm run build
662-
663-
# This is necessary to avoid a naming collision with the upload from the Node 18 build
664-
- name: Copy library for upload
665-
run: cp dist/plotly.js dist/plotly.node22.js
666-
667-
# Upload library uncompressed to allow for testing in REPLs
668-
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
669-
name: Upload uncompressed plotly.js built from PR, using Node 22
670-
with:
671-
retention-days: 30
672-
archive: false
673-
path: dist/plotly.node22.js
674-
675-
- name: Remove copy of library
676-
run: rm dist/plotly.node22.js
677-
678-
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
679-
name: Upload Node 22 archive of plotly.js build folder
680-
with:
681-
name: dist-node22
682-
retention-days: 7
683-
path: dist/
684-
685-
- name: View dist/README.md diff between previous and next releases
686-
run: git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) dist/README.md || true
687-
688-
- name: Preview plot-schema diff (only on master)
689-
if: github.ref == 'refs/heads/master'
690-
run: git --no-pager diff tags/$(git describe --tags --abbrev=0) dist/plot-schema.json || true
691-
692-
- name: Test plot-schema.json diff
693-
run: diff --unified --color dist/plot-schema.json test/plot-schema.json
694-
695578
test-stackgl-bundle:
696579
needs: detect-changes
697580
if: >-

.github/workflows/publish-dist.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Publish Dist
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
types:
8+
- opened
9+
- reopened
10+
- synchronize
11+
workflow_dispatch:
12+
13+
concurrency:
14+
group: publish-dist-${{ github.event.pull_request.number || github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
publish-dist:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
22+
with:
23+
fetch-depth: 0
24+
fetch-tags: true
25+
26+
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
27+
with:
28+
node-version: '18'
29+
cache: 'npm'
30+
31+
- name: Set up build environment
32+
run: .github/scripts/env_build.sh
33+
34+
- name: Set draft version in package.json
35+
run: |
36+
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)
37+
# View package.json diff from last release (should show that the version has been changed to the draft version)
38+
git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) package.json || true
39+
40+
- name: Build dist/
41+
run: npm run build
42+
43+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
44+
name: Upload Node 18 archive of plotly.js build folder
45+
with:
46+
name: dist-node18
47+
retention-days: 7
48+
path: dist/
49+
50+
- name: Test plot-schema.json diff
51+
run: diff --unified --color dist/plot-schema.json test/plot-schema.json
52+
53+
publish-dist-node-v22:
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
57+
with:
58+
fetch-depth: 0
59+
fetch-tags: true
60+
61+
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
62+
with:
63+
node-version: '22.14.0'
64+
cache: 'npm'
65+
66+
- name: Set up build environment
67+
run: .github/scripts/env_build.sh
68+
69+
- name: Set draft version in package.json
70+
run: |
71+
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)
72+
# View package.json diff from last release (should show that the version has been changed to the draft version)
73+
git --no-pager diff --color-words tags/$(git describe --tags --abbrev=0) package.json || true
74+
75+
- name: Build dist/
76+
run: npm run build
77+
78+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
79+
name: Upload Node 22 archive of plotly.js build folder
80+
with:
81+
name: dist-node22
82+
retention-days: 7
83+
path: dist/
84+
85+
- name: Test plot-schema.json diff
86+
run: diff --unified --color dist/plot-schema.json test/plot-schema.json

.github/workflows/upload-dev-build.yml

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,117 @@ name: Upload dev build from PR (placeholder, not yet implemented)
22

33
on:
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

1117
jobs:
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

Comments
 (0)