Skip to content

Commit 7aac4ff

Browse files
committed
feat: trigger deploying to control-plane review on opening a PR
1 parent 872d2d2 commit 7aac4ff

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@ 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
913
# inputs:
1014
# pr_number:
1115
# description: 'Pull request number'
1216
# 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
1717
issue_comment:
1818
types: [created, edited]
1919

20+
# Triggers the workflow on pull request events
21+
pull_request:
22+
branches:
23+
- master
24+
2025
# Convert the GitHub secret variables to environment variables for use by the Control Plane CLI
2126
env:
2227
CPLN_ORG: ${{secrets.CPLN_ORG_STAGING}}
2328
CPLN_TOKEN: ${{secrets.CPLN_TOKEN_STAGING}}
29+
PR_NUMBER: ${{github.event.number}}
2430

2531
jobs:
2632
deploy-to-control-plane-review:
@@ -34,13 +40,15 @@ jobs:
3440
- name: Get PR number
3541
run: |
3642
echo "GITHUB_REPOSITORY: \"$GITHUB_REPOSITORY\""
37-
REF=${{ github.ref }}
38-
REF=${REF#refs/heads/} # Remove 'refs/heads/' prefix
39-
echo "REF: \"$REF\""
40-
API_RESPONSE=$(curl --location --request GET "https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open" \
41-
--header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}')
42-
echo "API_RESPONSE: $API_RESPONSE"
43-
PR_NUMBER=$(echo $API_RESPONSE | jq '.[] | select(.head.ref=="'$REF'") | .number')
43+
if [ -z "$PR_NUMBER" ]; then
44+
echo "PR_NUMBER is not in the trigger event. Fetching PR number from open PRs."
45+
REF=${{ github.ref }}
46+
REF=${REF#refs/heads/} # Remove 'refs/heads/' prefix
47+
echo "REF: \"$REF\""
48+
API_RESPONSE=$(curl --location --request GET "https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open" \
49+
--header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}')
50+
PR_NUMBER=$(echo $API_RESPONSE | jq '.[] | select(.head.ref=="'$REF'") | .number')
51+
fi
4452
echo "PR_NUMBER: $PR_NUMBER"
4553
if [ -z "$PR_NUMBER" ]; then
4654
echo "PR_NUMBER is not set. Aborting."
@@ -57,4 +65,4 @@ jobs:
5765
- uses: ./.github/actions/deploy-to-control-plane
5866
with:
5967
app_name: ${{ env.APP_NAME }}
60-
org: ${{ secrets.CPLN_ORG_STAGING }}
68+
org: ${{ env.CPLN_ORG }}

0 commit comments

Comments
 (0)