Skip to content

Commit dec057b

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

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Deploy to Control Plane
22

3-
run-name: ${{ github.event_name == 'issue_comment' && format('Deploying Review App for {0}', github.ref_name) || github.ref == 'main' && 'Deploying to Staging' || format('Deploying Review App for {0}', github.ref_name) }}
3+
run-name: ${{ github.event_name == 'issue_comment' && format('Deploying Review App for {0}', github.ref_name) || github.ref == '${{ steps.default-branch.outputs.name }}' && 'Deploying to Staging' || format('Deploying Review App for {0}', github.ref_name) }}
44

55
on:
66
issue_comment:
@@ -15,7 +15,7 @@ on:
1515

1616
# Use concurrency to cancel in-progress runs
1717
concurrency:
18-
group: ${{ github.ref == 'main' && 'deploy-staging' || format('deploy-pr-{0}', github.event.issue.number) }}
18+
group: ${{ github.ref == '${{ steps.default-branch.outputs.name }}' && 'deploy-staging' || format('deploy-pr-{0}', github.event.issue.number) }}
1919
cancel-in-progress: true
2020

2121
jobs:
@@ -37,7 +37,7 @@ jobs:
3737
env:
3838
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3939
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
40-
CPLN_ORG: ${{ secrets.CPLN_ORG_STAGING }}
40+
CPLN_ORG: ${{ vars.CPLN_ORG_STAGING }}
4141
STAGING_APP_NAME: ${{ vars.STAGING_APP_NAME }}
4242
REVIEW_APP_PREFIX: ${{ vars.REVIEW_APP_PREFIX }}
4343

@@ -48,19 +48,16 @@ jobs:
4848

4949
- name: Verify Environment Variables
5050
run: |
51-
# Required environment variables
52-
: "${CPLN_ORG:?Required environment variable not set}"
53-
: "${CPLN_TOKEN:?Required environment variable not set}"
54-
: "${REVIEW_APP_PREFIX:?Required environment variable not set}"
55-
: "${STAGING_APP_NAME:?Required environment variable not set}"
51+
# Required secrets
52+
: "${GITHUB_TOKEN:?Required secret GITHUB_TOKEN not set}"
53+
: "${CPLN_TOKEN:?Required secret CPLN_TOKEN_STAGING not set}"
5654
57-
echo "All required environment variables are set"
58-
59-
- name: Set Default Branch
60-
id: default-branch
61-
run: |
62-
DEFAULT_BRANCH="main"
63-
echo "DEFAULT_BRANCH=$DEFAULT_BRANCH" >> $GITHUB_ENV
55+
# Required variables
56+
: "${CPLN_ORG:?Required variable CPLN_ORG_STAGING not set}"
57+
: "${STAGING_APP_NAME:?Required variable STAGING_APP_NAME not set}"
58+
: "${REVIEW_APP_PREFIX:?Required variable REVIEW_APP_PREFIX not set}"
59+
60+
echo "All required secrets and variables are set"
6461
6562
- name: Setup Deployment Configuration
6663
id: setup
@@ -92,8 +89,12 @@ jobs:
9289
exit 0
9390
}
9491
92+
# Get default branch
93+
DEFAULT_BRANCH="refs/heads/$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')"
94+
echo "DEFAULT_BRANCH=$DEFAULT_BRANCH" >> $GITHUB_OUTPUT
95+
9596
# Check if we should deploy
96-
if [[ "${{ github.ref }}" == "${{ env.DEFAULT_BRANCH }}" ]]; then
97+
if [[ "${{ github.ref }}" == "$DEFAULT_BRANCH" ]]; then
9798
echo "SHOULD_DEPLOY=true" >> $GITHUB_OUTPUT
9899
echo "IS_STAGING=true" >> $GITHUB_ENV
99100
echo "APP_NAME=${{ env.STAGING_APP_NAME }}" >> $GITHUB_ENV

0 commit comments

Comments
 (0)