Skip to content

Commit 977b0c7

Browse files
committed
refactor: make reusable workflows util prefix
1 parent 66e478a commit 977b0c7

5 files changed

+74
-43
lines changed

.github/workflows/build-container.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
jobs:
1414
container-build:
15-
uses: ./.github/workflows/shared-build-and-deploy.yaml
15+
uses: ./.github/workflows/util-build-and-deploy.yaml
1616
with:
1717
deploy: false
1818
branchName: ${{ github.head_ref || github.ref_name }}

.github/workflows/deploy.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
jobs:
1212
build-and-deploy:
13-
uses: ./.github/workflows/shared-build-and-deploy.yaml
13+
uses: ./.github/workflows/util-build-and-deploy.yaml
1414
with:
1515
deploy: true
1616
branchName: ${{ github.head_ref || github.ref_name }}
@@ -20,4 +20,4 @@ jobs:
2020
# runs-on: ubuntu-latest
2121
# needs: build-and-deploy
2222
# steps:
23-
# - run: echo "container-app-url=${{ needs.build-and-deploy.outputs.container-app-url }}"
23+
# - run: echo "container-app-url=${{ needs.build-and-deploy.outputs.containerAppUrl }}"

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

+41-36
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,22 @@ on:
55
types: [created]
66

77
jobs:
8-
# output-context:
8+
# get-pr-branch-name:
99
# runs-on: ubuntu-latest
10+
# outputs:
11+
# branchName: ${{ steps.get-pr-branch-name.outputs.branchName }}
1012
# steps:
11-
# - name: Dump GitHub context
12-
# env:
13-
# GITHUB_CONTEXT: ${{ toJSON(github) }}
14-
# run: echo "$GITHUB_CONTEXT"
15-
# - name: Dump job context
16-
# env:
17-
# JOB_CONTEXT: ${{ toJSON(job) }}
18-
# run: echo "$JOB_CONTEXT"
19-
# - name: Dump steps context
20-
# env:
21-
# STEPS_CONTEXT: ${{ toJSON(steps) }}
22-
# run: echo "$STEPS_CONTEXT"
23-
# - name: Dump runner context
13+
# - id: get-pr-branch-name
14+
# run: |
15+
# branchName=$(gh pr view ${{ github.event.issue.number }} --json "headRefName" --jq ".headRefName" --repo ${{ github.repository }})
16+
# echo "branchName=$branchName" >> $GITHUB_OUTPUT
2417
# env:
25-
# RUNNER_CONTEXT: ${{ toJSON(runner) }}
26-
# run: echo "$RUNNER_CONTEXT"
27-
# - name: Dump strategy context
28-
# env:
29-
# STRATEGY_CONTEXT: ${{ toJSON(strategy) }}
30-
# run: echo "$STRATEGY_CONTEXT"
31-
# - name: Dump matrix context
32-
# env:
33-
# MATRIX_CONTEXT: ${{ toJSON(matrix) }}
34-
# run: echo "$MATRIX_CONTEXT"
18+
# GH_TOKEN: ${{ github.token }}
3519

3620
get-pr-branch-name:
37-
runs-on: ubuntu-latest
38-
outputs:
39-
branchName: ${{ steps.get-pr-branch-name.outputs.branchName }}
40-
steps:
41-
- id: get-pr-branch-name
42-
run: |
43-
branchName=$(gh pr view ${{ github.event.issue.number }} --json "headRefName" --jq ".headRefName" --repo ${{ github.repository }})
44-
echo "branchName=$branchName" >> $GITHUB_OUTPUT
45-
env:
46-
GH_TOKEN: ${{ github.token }}
21+
uses: ./.github/workflows/util-get-pr-branch-name.yaml
22+
with:
23+
pullRequestNumber: ${{ github.event.issue.number }}
4724

4825
pre-deploy:
4926
# check if the comment comes from a pull request and contains the required keyword
@@ -59,7 +36,7 @@ jobs:
5936
# check if the comment comes from a pull request and contains the required keyword
6037
if: contains(github.event.comment.html_url, '/pull/') && contains(github.event.comment.body, '/deploy')
6138
needs: [get-pr-branch-name, pre-deploy]
62-
uses: ./.github/workflows/shared-build-and-deploy.yaml
39+
uses: ./.github/workflows/util-build-and-deploy.yaml
6340
with:
6441
deploy: true
6542
branchName: ${{ needs.get-pr-branch-name.outputs.branchName }}
@@ -70,6 +47,34 @@ jobs:
7047
needs: deploy
7148
steps:
7249
- run: |
73-
gh issue comment ${{ github.event.issue.number }} --body "Preview environment deployed: https://${{ needs.deploy.outputs.container-app-url }}" --repo ${{ github.repository }}
50+
gh issue comment ${{ github.event.issue.number }} --body "Preview environment deployed: https://${{ needs.deploy.outputs.containerAppUrl }}" --repo ${{ github.repository }}
7451
env:
7552
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
54+
# output-context:
55+
# runs-on: ubuntu-latest
56+
# steps:
57+
# - name: Dump GitHub context
58+
# env:
59+
# GITHUB_CONTEXT: ${{ toJSON(github) }}
60+
# run: echo "$GITHUB_CONTEXT"
61+
# - name: Dump job context
62+
# env:
63+
# JOB_CONTEXT: ${{ toJSON(job) }}
64+
# run: echo "$JOB_CONTEXT"
65+
# - name: Dump steps context
66+
# env:
67+
# STEPS_CONTEXT: ${{ toJSON(steps) }}
68+
# run: echo "$STEPS_CONTEXT"
69+
# - name: Dump runner context
70+
# env:
71+
# RUNNER_CONTEXT: ${{ toJSON(runner) }}
72+
# run: echo "$RUNNER_CONTEXT"
73+
# - name: Dump strategy context
74+
# env:
75+
# STRATEGY_CONTEXT: ${{ toJSON(strategy) }}
76+
# run: echo "$STRATEGY_CONTEXT"
77+
# - name: Dump matrix context
78+
# env:
79+
# MATRIX_CONTEXT: ${{ toJSON(matrix) }}
80+
# run: echo "$MATRIX_CONTEXT"

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Shared build and deploy
1+
name: Build and deploy
22

33
on:
44
workflow_call:
@@ -11,9 +11,9 @@ on:
1111
type: string
1212

1313
outputs:
14-
container-app-url:
14+
containerAppUrl:
1515
description: "The URL of the deployed container app"
16-
value: ${{ jobs.deploy.outputs.container-app-url }}
16+
value: ${{ jobs.deploy.outputs.containerAppUrl }}
1717

1818
env:
1919
RESOURCE_GROUP: rg-poorclaresarundel
@@ -88,7 +88,7 @@ jobs:
8888
if: inputs.deploy == true
8989
needs: build
9090
outputs:
91-
container-app-url: ${{ steps.deploy.outputs.CONTAINER_APP_URL }}
91+
containerAppUrl: ${{ steps.deploy.outputs.CONTAINER_APP_URL }}
9292
permissions:
9393
id-token: write
9494
contents: read
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Get PR branch name
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
pullRequestNumber:
7+
required: true
8+
type: number
9+
10+
outputs:
11+
branchName:
12+
description: "The source branch name for the pull request"
13+
value: ${{ jobs.get-pr-branch-name.outputs.branchName }}
14+
15+
jobs:
16+
get-pr-branch-name:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
branchName: ${{ steps.get-pr-branch-name.outputs.branchName }}
20+
steps:
21+
- id: get-pr-branch-name
22+
run: |
23+
branchName=$(gh pr view ${{ inputs.pullRequestNumber }} --json "headRefName" --jq ".headRefName" --repo ${{ github.repository }})
24+
echo "branchName=$branchName" >> $GITHUB_OUTPUT
25+
env:
26+
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)