Skip to content

Commit f5518c8

Browse files
authored
SC-90266 v2 demos build and deploy on merge to dev (#1416)
This update streamlines V2 GitHub Actions workflows to support dev and master branches, allowing conditional deployments to specific SWC environments. - V2 workflows renamed and updated to handle dev, master, and test-v2-dev branches. - Introduced logic to dynamically determine the SWC environment based on the branch name. - Standardized artifact naming and improved context handling for better branch identification. - Add a condition to prevent `v2-deploy-pr` failure.
1 parent 6a53033 commit f5518c8

File tree

3 files changed

+44
-30
lines changed

3 files changed

+44
-30
lines changed

.github/workflows/v2-build-master.yml renamed to .github/workflows/v2-build-demos-swc-env.yml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1-
name: V2 Build Master for Production Environment
2-
3-
# WIP #
4-
# The following workflow is responsible for the following:
5-
# 1. Identifying changed demos in the master branch when a PR is merged.
6-
# 2. Building the demos that have changed.
7-
# 3. Save the build context in an artifact for later use in the V2 Deploy Production workflow.
8-
# 4. If successful, trigger the V2 Deploy Production workflow.
9-
# Notes: We want to ensure that the builds are queued and not cancelled if a new PR is merged while the build is in progress.
1+
name: V2 Build Demos for SWC Environment
102

113
on:
124
push:
135
branches:
146
- master
15-
- test-v2-master # A master branch for testing purposes
16-
- v2-deploy-on-push # A branch for testing purposes
7+
- test-v2-master
8+
- dev
9+
- test-v2-dev
1710

1811
permissions:
1912
contents: read
2013
actions: read
2114
pull-requests: write
2215

2316
concurrency:
24-
group: build-v2-demos-master-${{ github.sha }}
17+
group: demo-deployment-build-${{ github.sha }}
2518
cancel-in-progress: true
2619

2720
jobs:
@@ -54,9 +47,9 @@ jobs:
5447
with:
5548
ref: ${{ github.sha }}
5649
demo-names: ${{ needs.identify-changed-demos.outputs.updated }}
57-
dev: false
50+
dev: ${{ github.ref_name == 'dev' || github.ref_name == 'test-v2-dev' }} # TODO remove test-v2-dev when stable
5851
save-artifact: true
59-
artifact-name: demo-master-build-${{ github.sha }} # Specific name for master builds
52+
artifact-name: demo-deployment-build-${{ github.sha }}
6053
keep-going: false
6154
quiet: false
6255
batch_size: 10
@@ -71,10 +64,11 @@ jobs:
7164
steps:
7265
- name: Save Merge Commit Information
7366
run: |
74-
mkdir -p /tmp/pr
75-
cat >/tmp/pr/master_build_context.json <<EOL
67+
mkdir -p /tmp/merge
68+
cat >/tmp/merge/deployment_build_context.json <<EOL
7669
{
7770
"ref": "${{ github.sha }}",
71+
"ref_name": "${{ github.ref_name }}",
7872
"updated_demos": "${{ needs.identify-changed-demos.outputs.updated }}",
7973
"deleted_demos": "${{ needs.identify-changed-demos.outputs.deleted }}"
8074
}
@@ -83,6 +77,6 @@ jobs:
8377
- name: Upload Pull Request Event Context as Artifact
8478
uses: actions/upload-artifact@v4
8579
with:
86-
name: master_build_context
87-
path: /tmp/pr
80+
name: deployment_build_context
81+
path: /tmp/merge
8882
retention-days: 30

.github/workflows/v2-deploy-master.yml renamed to .github/workflows/v2-deploy-demos-swc-env.yml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: V2 Deploy Master to Production Environment
1+
name: V2 Deploy Demos to SWC Environment
22

33
on:
44
workflow_run:
55
workflows:
6-
- "V2 Build Master for Production Environment"
6+
- "V2 Build Demos for SWC Environment"
77
types:
88
- completed
99

@@ -13,7 +13,7 @@ permissions:
1313
contents: read
1414

1515
concurrency:
16-
group: deploy-v2-demos-master-${{ github.event.workflow_run.head_branch }}
16+
group: v2-deploy-demos-swc-${{ github.event.workflow_run.head_branch }}
1717
cancel-in-progress: true
1818

1919
jobs:
@@ -26,13 +26,13 @@ jobs:
2626
uses: XanaduAI/cloud-actions/download-github-workflow-artifact@main
2727
with:
2828
workflow_run_id: ${{ github.event.workflow_run.id }}
29-
artifact_name_regex: '^master_build_context$'
29+
artifact_name_regex: '^deployment_build_context$'
3030
github_token: ${{ github.token }}
3131

3232
- name: Check if Build Context file exists
3333
id: build_context
3434
env:
35-
context_artifact_file_name: master_build_context.zip
35+
context_artifact_file_name: deployment_build_context.zip
3636
run: |
3737
if test -f "$context_artifact_file_name"; then
3838
echo "result=$context_artifact_file_name" >> $GITHUB_OUTPUT
@@ -49,37 +49,56 @@ jobs:
4949
with:
5050
script: |
5151
const fs = require('fs');
52-
const buildData = fs.readFileSync('master_build_context.json', 'utf8');
52+
const buildData = fs.readFileSync('deployment_build_context.json', 'utf8');
5353
return JSON.parse(buildData);
5454
5555
- name: Parse Push Event Information
5656
id: pr_info
5757
if: github.event.workflow_run.event == 'push' && steps.build_context.outputs.result != ''
5858
run: |
5959
echo '${{ steps.read_build_info.outputs.result }}' | jq -r '.ref' > merge_ref.txt
60+
echo '${{ steps.read_build_info.outputs.result }}' | jq -r '.ref_name' > merge_ref_name.txt
6061
echo '${{ steps.read_build_info.outputs.result }}' | jq -c '.updated_demos' > updated_demos.json
6162
echo '${{ steps.read_build_info.outputs.result }}' | jq -c '.deleted_demos' > deleted_demos.json
6263
6364
echo "merge_ref=$(cat merge_ref.txt)" >> $GITHUB_OUTPUT
65+
echo "merge_ref_name=$(cat merge_ref_name.txt)" >> $GITHUB_OUTPUT
6466
echo "updated_demos=$(cat updated_demos.json)" >> $GITHUB_OUTPUT
6567
echo "deleted_demos=$(cat deleted_demos.json)" >> $GITHUB_OUTPUT
68+
69+
- name: Determine SWC environment via merge_ref_name
70+
if: steps.pr_info.outputs.merge_ref_name != ''
71+
id: determine_env
72+
## Todo: Remove test-v2-master and test-v2-dev once the new branches are fully adopted
73+
## Todo: Update master to deploy into swc-prod environment instead of swc-staging
74+
run: |
75+
if [[ "${{ steps.pr_info.outputs.merge_ref_name }}" == "master" || "${{ steps.pr_info.outputs.merge_ref_name }}" == "test-v2-master" ]]; then
76+
echo "swc-env=swc-staging" >> $GITHUB_OUTPUT
77+
elif [[ "${{ steps.pr_info.outputs.merge_ref_name }}" == "dev" || "${{ steps.pr_info.outputs.merge_ref_name }}" == "test-v2-dev" ]]; then
78+
echo "swc-env=swc-dev" >> $GITHUB_OUTPUT
79+
else
80+
echo "Unknown branch: ${{ steps.pr_info.outputs.merge_ref_name }}"
81+
exit 1
82+
fi
6683
outputs:
6784
merge_ref: ${{ steps.pr_info.outputs.merge_ref }}
85+
merge_ref_name: ${{ steps.pr_info.outputs.merge_ref_name }}
6886
updated_demos: ${{ steps.pr_info.outputs.updated_demos }}
6987
deleted_demos: ${{ steps.pr_info.outputs.deleted_demos }}
88+
swc-env: ${{ steps.determine_env.outputs.swc-env }}
7089

71-
# Step 2: Deploy the demos to SWC production environment
90+
# Step 2: Deploy the demos to SWC
7291
deploy-production-demos:
7392
if: |
7493
github.event.workflow_run.event == 'push' &&
7594
needs.prepare-build-context.result == 'success' &&
76-
needs.prepare-build-context.outputs.merge_ref != ''
95+
needs.prepare-build-context.outputs.merge_ref != '' &&
96+
needs.prepare-build-context.outputs.updated_demos != '[]'
7797
uses: ./.github/workflows/v2-deploy-demos.yml
7898
needs: prepare-build-context
7999
with:
80-
# Change to 'swc-prod' when ready for release
81-
environment: 'swc-dev'
82-
artifact-name: demo-master-build-${{ needs.prepare-build-context.outputs.merge_ref }}
100+
environment: ${{ needs.prepare-build-context.outputs.swc-env }}
101+
artifact-name: demo-deployment-build-${{ needs.prepare-build-context.outputs.merge_ref }}
83102
workflow-run-id: ${{ github.event.workflow_run.id }}
84103
pr_number: 0
85104
secrets: inherit

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ jobs:
7979
if: |
8080
github.event.workflow_run.event == 'pull_request' &&
8181
needs.prepare-build-context.result == 'success' &&
82-
needs.prepare-build-context.outputs.pr_ref != ''
82+
needs.prepare-build-context.outputs.pr_ref != '' &&
83+
needs.prepare-build-context.outputs.updated_demos != '[]'
8384
uses: ./.github/workflows/v2-deploy-demos.yml
8485
needs: prepare-build-context
8586
with:

0 commit comments

Comments
 (0)