Skip to content

Commit a5081f2

Browse files
brownj85anthayes92Alan-eMartindoctorperceptron
authored
QML Pipeline Improvements (#1322)
Co-authored-by: anthayes92 <[email protected]> Co-authored-by: Alan Martin <[email protected]> Co-authored-by: Alan Martin <[email protected]> Co-authored-by: Paul Finlay <[email protected]>
1 parent 179d360 commit a5081f2

File tree

60 files changed

+4282
-308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+4282
-308
lines changed
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: V2 Build and Deploy Demos
2+
3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
actions: read
7+
8+
on:
9+
workflow_dispatch:
10+
inputs:
11+
environment:
12+
description: SWC environment to deploy to.
13+
options:
14+
- swc-staging
15+
- swc-prod
16+
- swc-dev
17+
required: true
18+
type: choice
19+
target:
20+
default: stable
21+
description: PennyLane version to build the demos. Either 'latest' or the most recent 'stable' release.
22+
options:
23+
- latest
24+
- stable
25+
required: true
26+
type: choice
27+
demos:
28+
description: Demos to build and deploy, space-separated list of slugs (e.g. "demo1 demo2 demo3"), or leave empty for all demos.
29+
required: false
30+
type: string
31+
as-previews:
32+
default: false
33+
description: |
34+
Whether to deploy the demos as previews.
35+
36+
**Please note** that demos built with the latest version cannot be published to swc-staging or swc-prod.
37+
They can only be deployed as previews.
38+
required: false
39+
type: boolean
40+
41+
jobs:
42+
validate-and-parse-inputs:
43+
runs-on: ubuntu-latest
44+
outputs:
45+
branch: ${{ steps.set-branch.outputs.branch }}
46+
steps:
47+
- name: Set branch
48+
id: set-branch
49+
run: |
50+
if [[ "${{ github.event.inputs.target }}" == "stable" ]]; then
51+
echo "branch=master" >> $GITHUB_OUTPUT
52+
elif [[ "${{ github.event.inputs.target }}" == "latest" ]]; then
53+
echo "branch=dev" >> $GITHUB_OUTPUT
54+
else
55+
echo "branch=" >> $GITHUB_OUTPUT
56+
fi
57+
58+
- name: Validate preview input
59+
id: validate-preview
60+
run: |
61+
if [[
62+
("${{ github.event.inputs.environment }}" == "swc-staging" ||
63+
"${{ github.event.inputs.environment }}" == "swc-prod") &&
64+
"${{ github.event.inputs.target }}" == "latest" &&
65+
"${{ github.event.inputs.as-previews }}" == "false"
66+
]]; then
67+
echo "========================="
68+
echo "🚫 Invalid input detected:"
69+
echo "Demos built with the latest version cannot be published to 'swc-staging' or 'swc-prod'."
70+
echo "They can only be deployed as previews."
71+
echo "Please set the 'as-previews' input to 'true' in your workflow configuration."
72+
echo "========================="
73+
exit 1
74+
fi
75+
76+
build:
77+
needs: validate-and-parse-inputs
78+
if: >
79+
(needs.validate-and-parse-inputs.outputs.branch == 'master') ||
80+
(needs.validate-and-parse-inputs.outputs.branch == 'dev')
81+
uses: ./.github/workflows/v2-build-demos.yml
82+
with:
83+
ref: ${{ needs.validate-and-parse-inputs.outputs.branch }}
84+
demo-names: ${{ github.event.inputs.demos }}
85+
dev: ${{ github.event.inputs.target == 'latest' }}
86+
save-artifact: true
87+
artifact-name: build-and-deploy-${{ github.event.inputs.target }}
88+
keep-going: false
89+
quiet: false
90+
batch_size: 10
91+
92+
deploy:
93+
uses: ./.github/workflows/v2-deploy-demos.yml
94+
needs:
95+
- validate-and-parse-inputs
96+
- build
97+
secrets: inherit
98+
with:
99+
environment: ${{ github.event.inputs.environment }}
100+
artifact-name: build-and-deploy-${{ github.event.inputs.target }}
101+
preview: ${{ github.event.inputs.as-previews }}

.github/workflows/v2-build-demos.yml

+25-19
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ on:
88
type: string
99
demo-names:
1010
description: |
11-
Instead of building all demos, only build the demos specified in this list.
11+
Only build the demos specified in a space-separated list,
12+
e.g. demo1 demo2 demo3.
13+
14+
If not specified, all demos will be built.
1215
required: false
1316
type: string
1417
default: ''
18+
dev:
19+
description: Use development dependencies.
20+
required: false
21+
type: boolean
22+
default: false
1523
save-artifact:
16-
description: |
17-
Whether to save the built demos as an artifact.
24+
description: Save the built demos as an artifact.
1825
required: false
1926
type: boolean
2027
default: true
@@ -24,22 +31,19 @@ on:
2431
type: string
2532
default: ''
2633
keep-going:
27-
description: Whether to keep going if a demo fails to build
34+
description: Keep going if a demo fails to build.
2835
required: false
2936
type: boolean
3037
default: false
3138
quiet:
32-
description: |
33-
Whether to suppress output from the build process
39+
description: Suppress output from the build process.
3440
required: false
3541
type: boolean
3642
default: false
3743
batch_size:
38-
description: |
39-
Number of demos to build per job
44+
description: Number of demos to build per job.
4045
type: number
4146
default: 10
42-
4347
outputs:
4448
artifact-name:
4549
description: "Name of the artifact containing the built demos"
@@ -57,25 +61,28 @@ on:
5761
required: false
5862
type: string
5963
default: ''
64+
dev:
65+
description: Use development dependencies.
66+
required: false
67+
type: boolean
68+
default: false
6069
save-artifact:
61-
description: |
62-
Whether to save the built demos as an artifact.
70+
description: Save the built demos as an artifact.
6371
required: false
6472
type: boolean
6573
default: true
6674
artifact-name:
67-
description: Name of the artifact containing the built demos (defaults to demo-build-{ref})
68-
required: true
75+
description: Name of the build artifact (defaults to demo-build-{ref}).
76+
required: false
6977
type: string
7078
default: ''
7179
keep-going:
72-
description: Whether to keep going if a demo fails to build
80+
description: Keep going if a demo fails to build.
7381
required: false
7482
type: boolean
7583
default: false
7684
quiet:
77-
description: |
78-
Whether to suppress output from the build process
85+
description: Suppress output from the build process.
7986
required: false
8087
type: boolean
8188
default: false
@@ -165,7 +172,8 @@ jobs:
165172
--execute \
166173
${{ inputs.keep-going && '--keep-going' || '--no-keep-going' }} \
167174
${{ inputs.quiet && '--quiet' || '--no-quiet' }} \
168-
${{ steps.demo-name-list.outputs.demo-names }}
175+
${{ steps.demo-name-list.outputs.demo-names }} \
176+
${{ inputs.dev && '--dev' || '--no-dev' }}
169177
170178
- name: Upload artifacts
171179
id: upload-artifacts
@@ -207,5 +215,3 @@ jobs:
207215
uses: geekyeggo/delete-artifact@v5
208216
with:
209217
name: ${{ needs.generate-build-variables.outputs.artifact-name }}-c*
210-
211-

.github/workflows/v2-build-pr.yml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: V2 Build PR
2+
3+
on:
4+
pull_request:
5+
branches: [master, dev]
6+
7+
permissions:
8+
contents: read
9+
10+
concurrency:
11+
group: build-v2-demos-${{ github.event.pull_request.head.sha }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
# Step 1: Identify changed demos
16+
identify-changed-demos:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
updated: ${{ steps.get-changed-demos.outputs.updated }}
20+
deleted: ${{ steps.get-changed-demos.outputs.deleted }}
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Get changed demos
27+
id: get-changed-demos
28+
uses: ./.github/actions/get-changed-demos
29+
30+
- name: Output changed demos
31+
run: |
32+
echo "Updated Demos: ${{ steps.get-changed-demos.outputs.updated }}"
33+
echo "Deleted Demos: ${{ steps.get-changed-demos.outputs.deleted }}"
34+
35+
- name: Exit if no changes
36+
if: steps.get-changed-demos.outputs.updated == ''
37+
run: |
38+
echo "No changes found in demos. Exiting workflow."
39+
40+
# Step 2: Build demos
41+
build:
42+
if: needs.identify-changed-demos.outputs.updated != ''
43+
uses: ./.github/workflows/v2-build-demos.yml
44+
needs:
45+
- identify-changed-demos
46+
with:
47+
ref: ${{ github.event.pull_request.head.sha }}
48+
demo-names: ${{ needs.identify-changed-demos.outputs.updated }}
49+
dev: ${{ github.event.pull_request.base.ref == 'dev' }}
50+
save-artifact: true
51+
artifact-name: demo-build-${{ github.event.pull_request.head.sha }}
52+
keep-going: false
53+
quiet: false
54+
batch_size: 10
55+
56+
# Step 3: Save build context
57+
save-build-context:
58+
runs-on: ubuntu-latest
59+
needs:
60+
- build
61+
- identify-changed-demos
62+
steps:
63+
- name: Save Pull Request Event Context
64+
run: |
65+
mkdir -p /tmp/pr
66+
cat >/tmp/pr/pr_info.json <<EOL
67+
{
68+
"id": "${{ github.event.pull_request.number }}",
69+
"ref": "${{ github.event.pull_request.head.sha }}",
70+
"ref_name": "${{ github.event.pull_request.head.ref }}",
71+
"updated_demos": "${{ needs.identify-changed-demos.outputs.updated }}",
72+
"deleted_demos": "${{ needs.identify-changed-demos.outputs.deleted }}"
73+
}
74+
EOL
75+
76+
- name: Upload Pull Request Event Context as Artifact
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: pr_info
80+
path: /tmp/pr
81+
retention-days: 30

.github/workflows/v2-deploy-demos.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
type: environment
2222
required: true
2323
artifact-name:
24-
description: Name of artifact containing demo builds
24+
description: Name of artifact containing demo zip files.
2525
type: string
2626
preview:
2727
description: Whether to deploy demos as preview
@@ -38,7 +38,6 @@ jobs:
3838
- name: Checkout
3939
uses: actions/checkout@v4
4040
with:
41-
ref: ${{ inputs.branch }}
4241
fetch-depth: 1
4342

4443
- name: Configure AWS credentials
@@ -67,4 +66,3 @@ jobs:
6766
python3 .github/workflows/qml_pipeline_v2/deploy.py \
6867
--preview ${{ inputs.preview }} \
6968
_build/pack/*.zip
70-

0 commit comments

Comments
 (0)