Skip to content

Commit 160c785

Browse files
committed
big-refactor-might-not-work
1 parent 5b451fa commit 160c785

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

.github/workflows/deploy-to-control-plane.yml

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,30 @@ run-name: ${{ github.event_name == 'issue_comment' && 'Deploying Review App' ||
55
on:
66
issue_comment:
77
types: [created]
8+
push:
9+
branches-ignore:
10+
- main # Don't run on main branch pushes
11+
- master # Don't run on master branch pushes
812

913
# Use concurrency to cancel in-progress runs
1014
concurrency:
11-
group: deploy-${{ github.event.issue.number }}
15+
group: deploy-pr-${{ github.event.issue.number }}
1216
cancel-in-progress: true
1317

1418
env:
15-
APP_NAME: qa-react-webpack-rails-tutorial-pr-${{ github.event.issue.number }}
1619
CPLN_ORG: ${{ secrets.CPLN_ORG }}
1720
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
18-
PR_NUMBER: ${{ github.event.issue.number }}
1921

2022
jobs:
2123
Process-Deployment-Command:
24+
# For issue comments, only run on /deploy-review-app command
25+
# For push events, only run if PR exists and has a review app
2226
if: |
23-
github.event_name == 'issue_comment' &&
24-
github.event.issue.pull_request &&
25-
github.event.comment.body == '/deploy-review-app'
27+
(github.event_name == 'issue_comment' &&
28+
github.event.issue.pull_request &&
29+
github.event.comment.body == '/deploy-review-app') ||
30+
(github.event_name == 'push' &&
31+
github.event.pull_request)
2632
runs-on: ubuntu-latest
2733
permissions:
2834
contents: read
@@ -35,10 +41,47 @@ jobs:
3541
with:
3642
fetch-depth: 0
3743

44+
- name: Setup Environment
45+
uses: ./.github/actions/setup-environment
46+
47+
- name: Get PR Number for Push Event
48+
if: github.event_name == 'push'
49+
id: get-pr
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
run: |
53+
# Get PR number from branch
54+
PR_NUMBER=$(gh pr list --head ${{ github.ref_name }} --json number --jq '.[0].number')
55+
if [ -n "$PR_NUMBER" ]; then
56+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
57+
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-$PR_NUMBER" >> $GITHUB_ENV
58+
else
59+
echo "No PR found for this branch"
60+
exit 0
61+
fi
62+
63+
- name: Set PR Number for Comment Event
64+
if: github.event_name == 'issue_comment'
65+
run: |
66+
echo "PR_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV
67+
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ github.event.issue.number }}" >> $GITHUB_ENV
68+
69+
- name: Check if Review App Exists
70+
id: check-app
71+
if: github.event_name == 'push'
72+
env:
73+
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
74+
run: |
75+
if ! cpflow exists -a ${{ env.APP_NAME }}; then
76+
echo "No review app exists for this PR"
77+
exit 0
78+
fi
79+
echo "app_exists=true" >> $GITHUB_OUTPUT
80+
3881
- name: Get PR HEAD Ref
3982
id: getRef
4083
run: |
41-
PR_DATA=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName,headRefOid)
84+
PR_DATA=$(gh pr view ${{ env.PR_NUMBER }} --repo ${{ github.repository }} --json headRefName,headRefOid)
4285
echo "PR_REF=$(echo "$PR_DATA" | jq -r '.headRefName')" >> $GITHUB_OUTPUT
4386
echo "PR_SHA=$(echo "$PR_DATA" | jq -r '.headRefOid')" >> $GITHUB_OUTPUT
4487
env:
@@ -48,6 +91,7 @@ jobs:
4891
run: git checkout ${{ steps.getRef.outputs.PR_REF }}
4992

5093
- name: Deploy to Control Plane
94+
if: github.event_name == 'issue_comment' || steps.check-app.outputs.app_exists == 'true'
5195
uses: ./.github/actions/deploy-to-control-plane
5296
with:
5397
app_name: ${{ env.APP_NAME }}

0 commit comments

Comments
 (0)