-
Notifications
You must be signed in to change notification settings - Fork 0
51 lines (44 loc) · 1.46 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
name: Build
on:
pull_request:
branches:
- main
jobs:
bicep-build:
name: Bicep Build
runs-on: ubuntu-latest
env:
BICEP_FILE_PATH: main.bicep
OUTPUT_FILE_PATH: azuredeploy.json
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
ref: ${{ github.head_ref }} # Required to push commit to PR
- name: Build Bicep file
id: build
shell: bash {0} # Required to check exit code
run: |
git fetch origin "$GITHUB_BASE_REF"
git diff --exit-code --merge-base "origin/$GITHUB_BASE_REF" "$BICEP_FILE_PATH"
exit_code="$?"
if [[ "$exit_code" == 0 ]]; then
echo "No changes made to Bicep file. Skipping build."
exit "$exit_code"
fi
az bicep build --file "$BICEP_FILE_PATH" --outfile "$OUTPUT_FILE_PATH"
exit_code="$?"
if [[ "$exit_code" != 0 ]]; then
exit "$exit_code"
fi
git diff --exit-code "$OUTPUT_FILE_PATH"
exit_code="$?"
echo "exit-code=$exit_code" >> "$GITHUB_OUTPUT"
- name: Push commit
if: steps.build.outputs.exit-code != 0
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add "$OUTPUT_FILE_PATH"
git commit -m "Build Bicep file"
git push