@@ -5,24 +5,30 @@ run-name: ${{ github.event_name == 'issue_comment' && 'Deploying Review App' ||
5
5
on :
6
6
issue_comment :
7
7
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
8
12
9
13
# Use concurrency to cancel in-progress runs
10
14
concurrency :
11
- group : deploy-${{ github.event.issue.number }}
15
+ group : deploy-pr- ${{ github.event.issue.number }}
12
16
cancel-in-progress : true
13
17
14
18
env :
15
- APP_NAME : qa-react-webpack-rails-tutorial-pr-${{ github.event.issue.number }}
16
19
CPLN_ORG : ${{ secrets.CPLN_ORG }}
17
20
CPLN_TOKEN : ${{ secrets.CPLN_TOKEN }}
18
- PR_NUMBER : ${{ github.event.issue.number }}
19
21
20
22
jobs :
21
23
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
22
26
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)
26
32
runs-on : ubuntu-latest
27
33
permissions :
28
34
contents : read
@@ -35,10 +41,47 @@ jobs:
35
41
with :
36
42
fetch-depth : 0
37
43
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
+
38
81
- name : Get PR HEAD Ref
39
82
id : getRef
40
83
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)
42
85
echo "PR_REF=$(echo "$PR_DATA" | jq -r '.headRefName')" >> $GITHUB_OUTPUT
43
86
echo "PR_SHA=$(echo "$PR_DATA" | jq -r '.headRefOid')" >> $GITHUB_OUTPUT
44
87
env :
48
91
run : git checkout ${{ steps.getRef.outputs.PR_REF }}
49
92
50
93
- name : Deploy to Control Plane
94
+ if : github.event_name == 'issue_comment' || steps.check-app.outputs.app_exists == 'true'
51
95
uses : ./.github/actions/deploy-to-control-plane
52
96
with :
53
97
app_name : ${{ env.APP_NAME }}
0 commit comments