Skip to content

Commit c6be254

Browse files
committed
feat: trigger deploying to control-plane review on opening a PR
1 parent 2625eb7 commit c6be254

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ name: Deploy Review App to Control Plane
66
on:
77
# Allows you to run this workflow manually from the Actions tab
88
workflow_dispatch:
9-
# inputs:
10-
# pr_number:
11-
# description: 'Pull request number'
12-
# required: false
13-
# Triggers the workflow on pull request events
14-
# pull_request:
15-
# branches:
16-
# - main # or the branch you want to trigger the workflow
9+
# inputs:
10+
# pr_number:
11+
# description: 'Pull request number'
12+
# required: false
13+
14+
# Triggers the workflow on pull request events
15+
pull_request:
16+
branches:
17+
- master
1718

1819
# Convert the GitHub secret variables to environment variables for use by the Control Plane CLI
1920
env:
2021
CPLN_ORG: ${{secrets.CPLN_ORG_STAGING}}
2122
CPLN_TOKEN: ${{secrets.CPLN_TOKEN_STAGING}}
23+
PR_NUMBER: ${{github.event.number}}
2224

2325
jobs:
2426
deploy-to-control-plane-review:
@@ -31,13 +33,15 @@ jobs:
3133
- name: Get PR number
3234
run: |
3335
echo "GITHUB_REPOSITORY: \"$GITHUB_REPOSITORY\""
34-
REF=${{ github.ref }}
35-
REF=${REF#refs/heads/} # Remove 'refs/heads/' prefix
36-
echo "REF: \"$REF\""
37-
API_RESPONSE=$(curl --location --request GET "https://github.com/api/repos/$GITHUB_REPOSITORY/pulls?state=open" \
38-
--header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}')
39-
echo "API_RESPONSE: $API_RESPONSE"
40-
PR_NUMBER=$(echo $API_RESPONSE | jq '.[] | select(.head.ref=="'$REF'") | .number')
36+
if [ -z "$PR_NUMBER" ]; then
37+
echo "PR_NUMBER is not in the trigger event. Fetching PR number from open PRs."
38+
REF=${{ github.ref }}
39+
REF=${REF#refs/heads/} # Remove 'refs/heads/' prefix
40+
echo "REF: \"$REF\""
41+
API_RESPONSE=$(curl --location --request GET "https://github.com/api/repos/$GITHUB_REPOSITORY/pulls?state=open" \
42+
--header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}')
43+
PR_NUMBER=$(echo $API_RESPONSE | jq '.[] | select(.head.ref=="'$REF'") | .number')
44+
fi
4145
echo "PR_NUMBER: $PR_NUMBER"
4246
if [ -z "$PR_NUMBER" ]; then
4347
echo "PR_NUMBER is not set. Aborting."
@@ -54,4 +58,4 @@ jobs:
5458
- uses: ./.github/actions/deploy-to-control-plane
5559
with:
5660
app_name: ${{ env.APP_NAME }}
57-
org: ${{ secrets.CPLN_ORG_STAGING }}
61+
org: ${{ env.CPLN_ORG }}

0 commit comments

Comments
 (0)