Skip to content

SC-85409 | Build and deploy demonstration previews on pull requests #1352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 63 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
b084fc6
scaffold
Alan-eMartin Apr 14, 2025
fddef21
Merge branch 'v2' into sc-85409-v-demos-are-built-on-pull-request
Alan-eMartin Apr 14, 2025
2e162d6
fmt
Alan-eMartin Apr 15, 2025
4b20c96
test
Alan-eMartin Apr 15, 2025
d08388b
typo
Alan-eMartin Apr 15, 2025
04186c3
add fork check
Alan-eMartin Apr 15, 2025
26d0389
correct the path, add pseudo steps
Alan-eMartin Apr 15, 2025
4895a89
missed checkout?
Alan-eMartin Apr 15, 2025
778eab6
??
Alan-eMartin Apr 15, 2025
799a7c8
check
Alan-eMartin Apr 15, 2025
201d0e7
test
Alan-eMartin Apr 15, 2025
7b28cde
again
Alan-eMartin Apr 15, 2025
6be650b
again
Alan-eMartin Apr 15, 2025
0395295
trigger ci
Alan-eMartin Apr 15, 2025
2bb3a6e
trigger
Alan-eMartin Apr 15, 2025
04b17ee
trigger, add debug
Alan-eMartin Apr 15, 2025
8776782
step fails, try moving to job
Alan-eMartin Apr 15, 2025
ec59fde
Use env var instead of set-output (depracated)
Alan-eMartin Apr 15, 2025
c259844
add build step
Alan-eMartin Apr 15, 2025
704c941
inherit secrets
Alan-eMartin Apr 15, 2025
539b1f4
create short list for testing
Alan-eMartin Apr 15, 2025
8c2e716
use swc-staging, add todos and notes
Alan-eMartin Apr 16, 2025
40f90d8
Merge branch 'v2' into sc-85409-v-demos-are-built-on-pull-request
Alan-eMartin Apr 16, 2025
51e28d5
snub other steps, and see if changed demos works as expected
Alan-eMartin Apr 16, 2025
8b5ad3d
check if change actually get picked up
Alan-eMartin Apr 16, 2025
dac0637
try again
Alan-eMartin Apr 16, 2025
0b3e1b0
remove newline for testing, add better desc
Alan-eMartin Apr 16, 2025
10d19c2
fmt
Alan-eMartin Apr 16, 2025
d12eb29
improve readability, leave notes, add permissions.
Alan-eMartin Apr 16, 2025
69f10af
test condition
Alan-eMartin Apr 16, 2025
04c8ecc
test exit
Alan-eMartin Apr 16, 2025
3360813
uncomment other jobs, remove delete
Alan-eMartin Apr 16, 2025
b2312d8
todo
Alan-eMartin Apr 16, 2025
4a5ce59
update casing
Alan-eMartin Apr 16, 2025
239d95e
Update .github/workflows/v2-deploy-demos.yml
Alan-eMartin Apr 17, 2025
6fc0139
rename file to match other v2
Alan-eMartin Apr 17, 2025
10b7f8b
add fork warning
Alan-eMartin Apr 18, 2025
f705ff8
clkean
Alan-eMartin Apr 21, 2025
60a3bd6
try comment
Alan-eMartin Apr 21, 2025
388920d
rm comments
Alan-eMartin Apr 21, 2025
12b07c6
put in summary
Alan-eMartin Apr 21, 2025
96f8b5e
add space for testing
Alan-eMartin Apr 21, 2025
a71fc63
fix: url for pl demos
Alan-eMartin Apr 21, 2025
c7abf4e
move back to two, rm comment for now.
Alan-eMartin Apr 21, 2025
56598f5
perms?
Alan-eMartin Apr 21, 2025
fe992f6
fix names
Alan-eMartin Apr 21, 2025
2c2fa46
debug
Alan-eMartin Apr 22, 2025
106c6c6
add branch and save PR number as artifact
Alan-eMartin Apr 22, 2025
c3a79bf
reference the directory not name
Alan-eMartin Apr 22, 2025
4ac06d4
add new workflows
Alan-eMartin Apr 23, 2025
17f5665
remove redundant commemt
Alan-eMartin Apr 23, 2025
e9be941
Update demonstrations_v2/gbs/demo.py
Alan-eMartin Apr 23, 2025
b589e46
use variable
Alan-eMartin Apr 23, 2025
013febe
Merge remote-tracking branch 'origin/sc-85409-v-demos-are-built-on-pu…
Alan-eMartin Apr 23, 2025
f69eb3e
remove exit code, use skip?
Alan-eMartin Apr 23, 2025
a6e5702
FMT, and remove unnecessary ifs
Alan-eMartin Apr 24, 2025
2f07f37
Update .github/workflows/v2-deploy-pr.yml
Alan-eMartin Apr 28, 2025
373a4b5
Update .github/workflows/v2-deploy-pr.yml
Alan-eMartin Apr 28, 2025
a402f51
rm on pr
Alan-eMartin Apr 28, 2025
deb3ef2
rm branch
Alan-eMartin Apr 28, 2025
f4b3c81
rm usage of branch
Alan-eMartin Apr 28, 2025
bc9375b
update how output is created, update gh token
Alan-eMartin Apr 29, 2025
f712b96
SC-89340 | Add ability to deploy demos manually (#1356)
Alan-eMartin Apr 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/v2-build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: V2 Build and Deploy Demos

on:
workflow_dispatch:
inputs:
environment:
description: SWC environment to deploy to
options:
- swc-staging
- swc-prod
- swc-dev
required: true
type: choice
target:
default: stable
description: PennyLane version to build the demos. Either 'latest' or the most recent 'stable' release.
options:
- latest
- stable
required: true
type: choice
demos:
description: Demos to build and deploy, space-separated list of slugs (e.g. "demo1 demo2 demo3"), or leave empty for all demos.
required: false
type: string
as-previews:
default: false
description: |
Whether to deploy the demos as previews.

**Please note** that demos built with the latest version cannot be published to swc-staging or swc-prod.
They can only be deployed as previews.
required: false
type: boolean

jobs:
validate-and-parse-inputs:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.set-branch.outputs.branch }}
steps:
- name: Set branch
id: set-branch
run: |
if [[ "${{ github.event.inputs.target }}" == "stable" ]]; then
echo "branch=master" >> $GITHUB_OUTPUT
elif [[ "${{ github.event.inputs.target }}" == "latest" ]]; then
echo "branch=dev" >> $GITHUB_OUTPUT
else
echo "branch=" >> $GITHUB_OUTPUT
fi

- name: Validate preview input
id: validate-preview
run: |
if [[
("${{ github.event.inputs.environment }}" == "swc-staging" ||
"${{ github.event.inputs.environment }}" == "swc-prod") &&
"${{ github.event.inputs.target }}" == "latest" &&
"${{ github.event.inputs.as-previews }}" == "false"
]]; then
echo "========================="
echo "🚫 Invalid input detected:"
echo "Demos built with the latest version cannot be published to 'swc-staging' or 'swc-prod'."
echo "They can only be deployed as previews."
echo "Please set the 'as-previews' input to 'true' in your workflow configuration."
echo "========================="
exit 1
fi

build:
needs: validate-and-parse-inputs
if: >
(needs.validate-and-parse-inputs.outputs.branch == 'master') ||
(needs.validate-and-parse-inputs.outputs.branch == 'dev')
uses: ./.github/workflows/v2-build-demos.yml
with:
ref: ${{ needs.validate-and-parse-inputs.outputs.branch }}
demo-names: ${{ github.event.inputs.demos }}
dev: ${{ github.event.inputs.target == 'latest' }}
save-artifact: true
artifact-name: build-and-deploy-${{ github.event.inputs.target }}
keep-going: false
quiet: false
batch_size: 10

deploy:
uses: ./.github/workflows/v2-deploy-demos.yml
needs:
- validate-and-parse-inputs
- build
secrets: inherit
with:
environment: ${{ github.event.inputs.environment }}
artifact-name: build-and-deploy-${{ github.event.inputs.target }}
preview: ${{ github.event.inputs.as-previews }}
branch: ${{ needs.validate-and-parse-inputs.outputs.branch }}
7 changes: 4 additions & 3 deletions .github/workflows/v2-build-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ on:
type: string
demo-names:
description: |
Only build the demos specified in this list.
Only build the demos specified in a space-separated list.
e.g. demo1 demo2 demo3

If not specified, all demos will be built.
required: false
type: string
default: ''
Expand Down Expand Up @@ -212,5 +215,3 @@ jobs:
uses: geekyeggo/delete-artifact@v5
with:
name: ${{ needs.generate-build-variables.outputs.artifact-name }}-c*


82 changes: 82 additions & 0 deletions .github/workflows/v2-build-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: V2 Build PR

on:
pull_request:
# remove v2 after testing
branches: [master, dev, v2]

permissions:
contents: read

concurrency:
group: build-v2-demos-${{ github.event.pull_request.head.sha }}
cancel-in-progress: true

jobs:
# Step 1: Identify changed demos
identify-changed-demos:
runs-on: ubuntu-latest
outputs:
updated: ${{ steps.get-changed-demos.outputs.updated }}
deleted: ${{ steps.get-changed-demos.outputs.deleted }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get changed demos
id: get-changed-demos
uses: ./.github/actions/get-changed-demos

- name: Output changed demos
run: |
echo "Updated Demos: ${{ steps.get-changed-demos.outputs.updated }}"
echo "Deleted Demos: ${{ steps.get-changed-demos.outputs.deleted }}"

- name: Exit if no changes
if: steps.get-changed-demos.outputs.updated == ''
run: |
echo "No changes found in demos. Exiting workflow."

# Step 2: Build demos
build:
if: needs.identify-changed-demos.outputs.updated != ''
uses: ./.github/workflows/v2-build-demos.yml
needs:
- identify-changed-demos
with:
ref: ${{ github.event.pull_request.head.sha }}
demo-names: ${{ needs.identify-changed-demos.outputs.updated }}
dev: ${{ github.event.pull_request.base.ref == 'dev' }}
save-artifact: true
artifact-name: demo-build-${{ github.event.pull_request.head.sha }}
keep-going: false
quiet: false
batch_size: 10

# Step 3: Save build context
save-build-context:
runs-on: ubuntu-latest
needs:
- build
- identify-changed-demos
steps:
- name: Save Pull Request Event Context
run: |
mkdir -p /tmp/pr
cat >/tmp/pr/pr_info.json <<EOL
{
"id": "${{ github.event.pull_request.number }}",
"ref": "${{ github.event.pull_request.head.sha }}",
"ref_name": "${{ github.event.pull_request.head.ref }}",
"updated_demos": "${{ needs.identify-changed-demos.outputs.updated }}",
"deleted_demos": "${{ needs.identify-changed-demos.outputs.deleted }}"
}
EOL

- name: Upload Pull Request Event Context as Artifact
uses: actions/upload-artifact@v4
with:
name: pr_info
path: /tmp/pr
retention-days: 30
10 changes: 0 additions & 10 deletions .github/workflows/v2-deploy-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ on:
description: Whether to deploy demos as preview
type: boolean
required: true
branch:
description: Branch to checkout
type: string
default: sc-81925-qml-repository-ci-pushes-newly-built-demos

workflow_dispatch:
inputs:
Expand All @@ -31,10 +27,6 @@ on:
description: Whether to deploy demos as preview
type: boolean
required: true
branch:
description: Branch to checkout
type: string
default: sc-81925-qml-repository-ci-pushes-newly-built-demos

jobs:
deploy-demos:
Expand All @@ -46,7 +38,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
fetch-depth: 1

- name: Configure AWS credentials
Expand Down Expand Up @@ -75,4 +66,3 @@ jobs:
python3 .github/workflows/qml_pipeline_v2/deploy.py \
--preview ${{ inputs.preview }} \
_build/pack/*.zip

130 changes: 130 additions & 0 deletions .github/workflows/v2-deploy-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: V2 Deploy PR

on:
workflow_run:
workflows:
- "V2 Build PR"
types:
- completed

permissions:
actions: read
pull-requests: write
contents: read

concurrency:
group: deploy-v2-demos-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true

jobs:
# Step 1: Prepare the build context
prepare-build-context:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Download Build Context
uses: XanaduAI/cloud-actions/download-github-workflow-artifact@main
with:
workflow_run_id: ${{ github.event.workflow_run.id }}
artifact_name_regex: '^pr_info$'
github_token: ${{ github.token }}

- name: Check if Build Context file exists
id: build_context
env:
context_artifact_file_name: pr_info.zip
run: |
if test -f "$context_artifact_file_name"; then
echo "result=$context_artifact_file_name" >> $GITHUB_OUTPUT
fi

- name: Unpack Build Information
if: steps.build_context.outputs.result != ''
run: unzip ${{ steps.build_context.outputs.result }}

- name: Read Build Information
id: read_build_info
if: steps.build_context.outputs.result != ''
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const buildData = fs.readFileSync('pr_info.json', 'utf8');
return JSON.parse(buildData);

- name: Parse Pull Request Event Information
id: pr_info
if: github.event.workflow_run.event == 'pull_request' && steps.build_context.outputs.result != ''
run: |
echo '${{ steps.read_build_info.outputs.result }}' | jq -r '.id' > pr_id.txt
echo '${{ steps.read_build_info.outputs.result }}' | jq -r '.ref' > pr_ref.txt
echo '${{ steps.read_build_info.outputs.result }}' | jq -r '.ref_name' > pr_ref_name.txt
echo '${{ steps.read_build_info.outputs.result }}' | jq -c '.updated_demos' > updated_demos.json
echo '${{ steps.read_build_info.outputs.result }}' | jq -c '.deleted_demos' > deleted_demos.json

echo "pr_id=$(cat pr_id.txt)" >> $GITHUB_OUTPUT
echo "pr_ref=$(cat pr_ref.txt)" >> $GITHUB_OUTPUT
echo "pr_ref_name=$(cat pr_ref_name.txt)" >> $GITHUB_OUTPUT
echo "updated_demos=$(cat updated_demos.json)" >> $GITHUB_OUTPUT
echo "deleted_demos=$(cat deleted_demos.json)" >> $GITHUB_OUTPUT

- name: Set job outputs
if: github.event.workflow_run.event == 'pull_request' && steps.build_context.outputs.result != ''
id: set_job_outputs
run: |
echo "pr_id=${{ steps.pr_info.outputs.pr_id }}" >> $GITHUB_OUTPUT
echo "pr_ref=${{ steps.pr_info.outputs.pr_ref }}" >> $GITHUB_OUTPUT
echo "pr_ref_name=${{ steps.pr_info.outputs.pr_ref_name }}" >> $GITHUB_OUTPUT
echo "updated_demos=${{ steps.pr_info.outputs.updated_demos }}" >> $GITHUB_OUTPUT
echo "deleted_demos=${{ steps.pr_info.outputs.deleted_demos }}" >> $GITHUB_OUTPUT
outputs:
pr_id: ${{ steps.set_job_outputs.outputs.pr_id }}
pr_ref: ${{ steps.set_job_outputs.outputs.pr_ref }}
pr_ref_name: ${{ steps.set_job_outputs.outputs.pr_ref_name }}
updated_demos: ${{ steps.set_job_outputs.outputs.updated_demos }}
deleted_demos: ${{ steps.set_job_outputs.outputs.deleted_demos }}

# Step 2: Deploy the demos to SWC
deploy-preview-demos:
if: github.event.workflow_run.event == 'pull_request' && needs.prepare-build-context.result == 'success'
uses: ./.github/workflows/v2-deploy-demos.yml
needs: prepare-build-context
with:
# TODO: Update SWC environment to "swc-prod"
environment: 'swc-staging'
artifact-name: demo-build-${{ needs.prepare-build-context.outputs.pr_ref }}
preview: true
secrets: inherit

# Step 3: Create a comment on the PR with the demo links
generate-comment:
if: github.event.workflow_run.event == 'pull_request' && needs.prepare-build-context.outputs.pr_id != ''
runs-on: ubuntu-latest
needs: prepare-build-context
steps:
- name: Create markdown comment from demo names
id: generate-markdown
run: |
demos="${{ needs.prepare-build-context.outputs.updated_demos }}"

comment="### Preview(s) are ready! :tada:\n"
comment+="<details>\n"
comment+="<summary>Toggle to view preview links</summary>\n"
comment+="\n"
# TODO: Switch to prod once testing is complete
for demo in $demos; do
comment+="- [$demo](https://staging.pennylane.ai/qml/demos/$demo?preview=true)\n"
done

comment+="\n"
comment+="</details>"

echo "markdown=$comment" >> $GITHUB_OUTPUT

- name: Comment on PR
id: comment-on-pr
uses: XanaduAI/cloud-actions/create-and-update-pull-request-comment@main
with:
github_token: ${{ secrets.github_token }}
pull_request_number: ${{ needs.prepare-build-context.outputs.pr_id }}
comment_body: ${{ steps.generate-markdown.outputs.markdown }}
Loading