@@ -6,24 +6,80 @@ name: Deploy Review App to Control Plane
6
6
on :
7
7
# Allows you to run this workflow manually from the Actions tab
8
8
workflow_dispatch :
9
+
10
+ # Uncomment these lines to trigger the workflow on pull request events
11
+ # pull_request:
12
+ # branches:
13
+ # - master
14
+
15
+ # deploy on comment "/deploy-review-app"
9
16
issue_comment :
10
17
types : [created, edited]
11
18
12
19
# Convert the GitHub secret variables to environment variables for use by the Control Plane CLI
13
20
env :
14
21
CPLN_ORG : ${{secrets.CPLN_ORG_STAGING}}
15
22
CPLN_TOKEN : ${{secrets.CPLN_TOKEN_STAGING}}
23
+ # Uncomment this line to use the PR number from the pull requests trigger event (that trigger is commented)
24
+ # PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}
25
+ PR_NUMBER : ${{ github.event.issue.number }}
16
26
17
27
jobs :
18
- deploy-to-control-plane-staging :
28
+ deploy-to-control-plane-review :
19
29
if : ${{ github.event_name != 'issue_comment' || (github.event.comment.body == '/deploy-review-app' && github.event.issue.pull_request) }}
20
30
runs-on : ubuntu-latest
21
31
22
32
steps :
23
- - name : Check out the repo
24
- uses : actions/checkout@v2
33
+ - name : Get PR HEAD Ref
34
+ if : ${{ github.event_name == 'issue_comment' }}
35
+ id : getRef
36
+ run : echo "PR_REF=$(gh pr view \"$PR_NUMBER\" --repo \"${{ github.repository }}\" --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT
37
+ env :
38
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
39
+
40
+ - name : Checkout source code from Github
41
+ uses : actions/checkout@v4
42
+ with :
43
+ fetch-depth : 0
44
+ ref : ${{ steps.getRef.outputs.PR_REF || github.ref }}
45
+
46
+ - name : Add GitHub Comment
47
+ if : ${{ github.event_name == 'issue_comment' }}
48
+ uses : actions/github-script@v6
49
+ with :
50
+ script : |
51
+ github.rest.issues.createComment({
52
+ issue_number: context.issue.number,
53
+ owner: context.repo.owner,
54
+ repo: context.repo.repo,
55
+ body: "We started working on your review-app deployment. You can track progress in the "Actions" Tab [here](https://github.com/shakacode/react-webpack-rails-tutorial/actions/workflows/deploy-to-control-plane-review.yml) on Github."
56
+ })
25
57
58
+ - name : Get PR number
59
+ if : ${{ github.event_name != 'issue_comment' }}
60
+ run : |
61
+ echo "GITHUB_REPOSITORY: \"$GITHUB_REPOSITORY\""
62
+ if [ -z "$PR_NUMBER" ]; then
63
+ echo "PR_NUMBER is not in the trigger event. Fetching PR number from open PRs."
64
+ REF="${{ github.ref }}"
65
+ REF=${REF#refs/heads/} # Remove 'refs/heads/' prefix
66
+ echo "REF: \"$REF\""
67
+ API_RESPONSE=$(curl --location --request GET "https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls?state=open" \
68
+ --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}')
69
+ PR_NUMBER=$(echo "$API_RESPONSE" | jq '.[] | select(.head.ref=="'$REF'") | .number')
70
+ fi
71
+ echo "PR_NUMBER: $PR_NUMBER"
72
+ if [ -z "$PR_NUMBER" ]; then
73
+ echo "PR_NUMBER is not set. Aborting."
74
+ exit 1
75
+ fi
76
+ echo "PR_NUMBER=\"$PR_NUMBER\"" >> $GITHUB_ENV
77
+ - name : Get App Name
78
+ run : |
79
+ echo "PR_NUMBER: ${{ env.PR_NUMBER }}"
80
+ echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }}" >> "$GITHUB_ENV"
81
+ echo "App Name: ${{ env.APP_NAME }}"
26
82
- uses : ./.github/actions/deploy-to-control-plane
27
83
with :
28
- app_name : qa-react-webpack-rails-tutorial-pr- ${{ github.event.pull_request.number }}
29
- org : ${{ secrets.CPLN_ORG_STAGING }}
84
+ app_name : ${{ env.APP_NAME }}
85
+ org : ${{ env.CPLN_ORG }}
0 commit comments