-
Notifications
You must be signed in to change notification settings - Fork 209
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
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
b084fc6
scaffold
Alan-eMartin fddef21
Merge branch 'v2' into sc-85409-v-demos-are-built-on-pull-request
Alan-eMartin 2e162d6
fmt
Alan-eMartin 4b20c96
test
Alan-eMartin d08388b
typo
Alan-eMartin 04186c3
add fork check
Alan-eMartin 26d0389
correct the path, add pseudo steps
Alan-eMartin 4895a89
missed checkout?
Alan-eMartin 778eab6
??
Alan-eMartin 799a7c8
check
Alan-eMartin 201d0e7
test
Alan-eMartin 7b28cde
again
Alan-eMartin 6be650b
again
Alan-eMartin 0395295
trigger ci
Alan-eMartin 2bb3a6e
trigger
Alan-eMartin 04b17ee
trigger, add debug
Alan-eMartin 8776782
step fails, try moving to job
Alan-eMartin ec59fde
Use env var instead of set-output (depracated)
Alan-eMartin c259844
add build step
Alan-eMartin 704c941
inherit secrets
Alan-eMartin 539b1f4
create short list for testing
Alan-eMartin 8c2e716
use swc-staging, add todos and notes
Alan-eMartin 40f90d8
Merge branch 'v2' into sc-85409-v-demos-are-built-on-pull-request
Alan-eMartin 51e28d5
snub other steps, and see if changed demos works as expected
Alan-eMartin 8b5ad3d
check if change actually get picked up
Alan-eMartin dac0637
try again
Alan-eMartin 0b3e1b0
remove newline for testing, add better desc
Alan-eMartin 10d19c2
fmt
Alan-eMartin d12eb29
improve readability, leave notes, add permissions.
Alan-eMartin 69f10af
test condition
Alan-eMartin 04c8ecc
test exit
Alan-eMartin 3360813
uncomment other jobs, remove delete
Alan-eMartin b2312d8
todo
Alan-eMartin 4a5ce59
update casing
Alan-eMartin 239d95e
Update .github/workflows/v2-deploy-demos.yml
Alan-eMartin 6fc0139
rename file to match other v2
Alan-eMartin 10b7f8b
add fork warning
Alan-eMartin f705ff8
clkean
Alan-eMartin 60a3bd6
try comment
Alan-eMartin 388920d
rm comments
Alan-eMartin 12b07c6
put in summary
Alan-eMartin 96f8b5e
add space for testing
Alan-eMartin a71fc63
fix: url for pl demos
Alan-eMartin c7abf4e
move back to two, rm comment for now.
Alan-eMartin 56598f5
perms?
Alan-eMartin fe992f6
fix names
Alan-eMartin 2c2fa46
debug
Alan-eMartin 106c6c6
add branch and save PR number as artifact
Alan-eMartin c3a79bf
reference the directory not name
Alan-eMartin 4ac06d4
add new workflows
Alan-eMartin 17f5665
remove redundant commemt
Alan-eMartin e9be941
Update demonstrations_v2/gbs/demo.py
Alan-eMartin b589e46
use variable
Alan-eMartin 013febe
Merge remote-tracking branch 'origin/sc-85409-v-demos-are-built-on-pu…
Alan-eMartin f69eb3e
remove exit code, use skip?
Alan-eMartin a6e5702
FMT, and remove unnecessary ifs
Alan-eMartin 2f07f37
Update .github/workflows/v2-deploy-pr.yml
Alan-eMartin 373a4b5
Update .github/workflows/v2-deploy-pr.yml
Alan-eMartin a402f51
rm on pr
Alan-eMartin deb3ef2
rm branch
Alan-eMartin f4b3c81
rm usage of branch
Alan-eMartin bc9375b
update how output is created, update gh token
Alan-eMartin f712b96
SC-89340 | Add ability to deploy demos manually (#1356)
Alan-eMartin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
Alan-eMartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
path: /tmp/pr | ||
retention-days: 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 != '' | ||
Alan-eMartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 }} | ||
Alan-eMartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# 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 }} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.