Skip to content

Commit 9511476

Browse files
committed
feat: branch name in pr comment
1 parent 20d64e1 commit 9511476

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

.github/workflows/deploy.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
uses: ./.github/workflows/shared-build-and-deploy.yaml
1414
with:
1515
deploy: true
16+
branchName: ${{ github.head_ref || github.ref_name }}
1617
secrets: inherit
1718

1819
get-container-app-url:

.github/workflows/pull-request-action.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,22 @@ jobs:
1313
GITHUB_CONTEXT: ${{ toJSON(github) }}
1414
run: echo "$GITHUB_CONTEXT"
1515

16+
get-branch-name:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
branchName: ${{ steps.get-branch-name.outputs.branchName }}
20+
steps:
21+
- id: get-branch-name
22+
run: |
23+
branchName=$(gh pr view ${{ github.event.issue.number }} --json "headRefName" --jq ".headRefName" --repo ${{ github.repository }})
24+
echo "branchName=$branchName" >> $GITHUB_OUTPUT
25+
1626
build-and-deploy:
1727
# check if the comment comes from a pull request and contains the required keyword
1828
if: contains(github.event.comment.html_url, '/pull/') && contains(github.event.comment.body, '/deploy')
29+
needs: get-branch-name
1930
uses: ./.github/workflows/shared-build-and-deploy.yaml
2031
with:
2132
deploy: true
33+
branchName: ${{ needs.get-branch-name.outputs.branchName }}
2234
secrets: inherit

.github/workflows/shared-build-and-deploy.yaml

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ on:
66
deploy:
77
required: true
88
type: boolean
9+
branchName:
10+
required: true
11+
type: string
12+
913
# secrets:
1014
# personal_access_token:
1115
# required: true
1216
# Map the workflow outputs to job outputs
17+
1318
outputs:
1419
container-app-url:
1520
description: "The URL of the deployed container app"
@@ -18,7 +23,6 @@ on:
1823
env:
1924
RESOURCE_GROUP: rg-poorclaresarundel
2025
REGISTRY: ghcr.io
21-
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
2226

2327
jobs:
2428
build:
@@ -101,14 +105,19 @@ jobs:
101105
uses: azure/CLI@v2
102106
with:
103107
inlineScript: |
104-
REF_SHA="${{ env.BRANCH_NAME }}.${{ needs.build.outputs.sha-short }}"
108+
BRANCH_NAME="${{ inputs.branchName }}"
109+
REF_SHA="${{ inputs.branchName }}.${{ needs.build.outputs.sha-short }}"
105110
DEPLOYMENT_NAME="${REF_SHA////-}"
106111
echo "DEPLOYMENT_NAME=$DEPLOYMENT_NAME"
107112
108113
webServiceImage="${{ needs.build.outputs.image-name }}:sha-${{ needs.build.outputs.sha-short }}"
109114
echo "webServiceImage=$webServiceImage"
110115
111-
webServiceContainerAppName='${{ env.BRANCH_NAME }}-web'
116+
if [ "$BRANCH_NAME" == "main" ]; then
117+
webServiceContainerAppName="main-web"
118+
else
119+
webServiceContainerAppName="preview-web"
120+
fi
112121
echo "webServiceContainerAppName=$webServiceContainerAppName"
113122
114123
TAGS='{"owner":"johnnyreilly", "email":"johnny_reilly@hotmail.com"}'
@@ -121,7 +130,7 @@ jobs:
121130
containerRegistry=${{ env.REGISTRY }} \
122131
containerRegistryUsername=${{ github.actor }} \
123132
containerRegistryPassword=${{ secrets.PACKAGES_TOKEN }} \
124-
branchName='${{ env.BRANCH_NAME }}' \
133+
branchName="$BRANCH_NAME" \
125134
workspaceName='shared-log-analytics' \
126135
appInsightsName='shared-app-insights' \
127136
managedEnvironmentName='shared-env' \

0 commit comments

Comments
 (0)