Skip to content

Commit c994d42

Browse files
committed
rework-main-job-deploy
1 parent dec057b commit c994d42

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ jobs:
4848

4949
- name: Verify Environment Variables
5050
run: |
51-
# Required secrets
51+
# Required actions secrets
5252
: "${GITHUB_TOKEN:?Required secret GITHUB_TOKEN not set}"
5353
: "${CPLN_TOKEN:?Required secret CPLN_TOKEN_STAGING not set}"
5454
55-
# Required variables
55+
# Required actions variables
5656
: "${CPLN_ORG:?Required variable CPLN_ORG_STAGING not set}"
5757
: "${STAGING_APP_NAME:?Required variable STAGING_APP_NAME not set}"
5858
: "${REVIEW_APP_PREFIX:?Required variable REVIEW_APP_PREFIX not set}"
@@ -104,8 +104,12 @@ jobs:
104104
echo "SHOULD_DEPLOY=true" >> $GITHUB_OUTPUT
105105
setup_pr_deployment "${{ github.event.issue.number }}"
106106
elif [[ "${{ github.event_name }}" == "push" ]]; then
107-
PR_NUMBER=$(gh pr list --head ${{ github.ref_name }} --json number --jq '.[0].number')
107+
# Get PR number for the current branch, handling refs/heads/ prefix
108+
BRANCH_NAME="${{ github.ref_name }}"
109+
PR_NUMBER=$(gh pr list --head "$BRANCH_NAME" --json number,state --jq '.[] | select(.state=="OPEN") | .number')
110+
108111
if [ -n "$PR_NUMBER" ]; then
112+
echo "Found PR #$PR_NUMBER for branch $BRANCH_NAME"
109113
APP_NAME="${{ env.REVIEW_APP_PREFIX }}-pr-$PR_NUMBER"
110114
if check_app_exists "$APP_NAME"; then
111115
echo "SHOULD_DEPLOY=true" >> $GITHUB_OUTPUT
@@ -114,6 +118,7 @@ jobs:
114118
no_deployment "No existing review app found for PR $PR_NUMBER"
115119
fi
116120
else
121+
echo "No open PR found for branch $BRANCH_NAME"
117122
no_deployment "No PR found for this branch"
118123
fi
119124
else
@@ -156,7 +161,7 @@ jobs:
156161
}
157162
158163
- name: Create Initial Comment
159-
if: env.IS_STAGING != 'true'
164+
if: env.IS_STAGING != 'true' && env.PR_NUMBER != ''
160165
id: create-comment
161166
uses: actions/github-script@v7
162167
with:

0 commit comments

Comments
 (0)