2020 # Set this to the mainline branch you are using
2121 branches :
2222 - main
23+ pull_request :
24+ # Run when pull requests are opened or updated
25+ branches :
26+ - main
27+
2328# GitHub Actions workflow to deploy to Azure using azd
29+ # Ensure only one deployment runs at a time to prevent conflicts
30+ concurrency :
31+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
32+ cancel-in-progress : false
2433
2534permissions :
2635 actions : read # Needed for uploading SARIF reports
2736 security-events : write # Needed for uploading SARIF reports
28- id-token : write
37+ id-token : write # Needed for OIDC Authentication
2938 contents : read
3039
3140
3241jobs :
3342 build :
3443 runs-on : ${{ fromJson(vars.ACTIONS_RUNNER_NAME || '["ubuntu-latest"]') }}
3544 env :
36- AZURE_ENV_NAME : ${{ github.event.inputs.azd_environment_name || 'CICD' }}
45+ AZURE_ENV_NAME : ${{ github.event.inputs.azd_environment_name || (github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number)) || 'CICD' }}
3746 AZURE_LOCATION : ${{ github.event.inputs.azure_location || 'eastus' }}
3847
3948 steps :
40- - name : Checkout the branch ${{ github.ref_name }}
41- uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
49+ - name : Checkout code
50+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4251 with :
43- ref : ${{ github.ref_name }}
52+ persist-credentials : false
4453
4554 - name : Install azd
46- uses : Azure/setup-azd@cf638ffd167fc81e1851241a478a723c05fa9cb3 # v2.2.0
55+ uses : Azure/setup-azd@cf638ffd167fc81e1851241a478a723c05fa9cb3 # v2.2.0
4756 with :
4857 version : ' 1.20.0' # Specify your desired azd version here
4958
5059 - name : Setup Node.js
51- uses : actions/setup-node@v5
60+ uses : actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
5261 with :
5362 node-version : ' 18.x'
5463
5867 terraform_version : 1.13.3
5968
6069 - name : Install TFLint
61- uses : terraform-linters/setup-tflint@acd1575d3c037258ce5b2dd01379dc49ce24c6b7 # v6.2.0
70+ uses : terraform-linters/setup-tflint@acd1575d3c037258ce5b2dd01379dc49ce24c6b7 # v6.2.0
6271 with :
6372 tflint_version : v0.58.1
6473 github_token : ${{ secrets.GITHUB_TOKEN }} # Used to avoid rate
8695 echo "GitLeaks scan completed"
8796
8897 - name : Setup .NET SDK
89- uses : actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.0
90- with :
91- dotnet-version : ' 8.0.x'
98+ shell : bash
99+ run : |
100+ # Install .NET SDK to temp directory for self-hosted runners to avoid permission issues
101+ DOTNET_INSTALL_DIR="${{ runner.temp }}/dotnet"
102+ mkdir -p "$DOTNET_INSTALL_DIR"
103+
104+ # Download and run the dotnet-install script
105+ curl -sSL https://dot.net/v1/dotnet-install.sh -o dotnet-install.sh
106+ chmod +x dotnet-install.sh
107+ ./dotnet-install.sh --channel 9.0 --install-dir "$DOTNET_INSTALL_DIR"
108+ rm dotnet-install.sh
109+
110+ # Add to PATH for subsequent steps
111+ echo "$DOTNET_INSTALL_DIR" >> $GITHUB_PATH
112+ echo "DOTNET_ROOT=$DOTNET_INSTALL_DIR" >> $GITHUB_ENV
92113
93114 - name : Install Power Platform Tools
94115 uses : microsoft/powerplatform-actions/actions-install@6c7b538671a040d11afd8ab94d77bfe3b3ed87e6 # v1.9.1
@@ -100,7 +121,7 @@ jobs:
100121 pac help
101122
102123 - name : Set Up Python
103- uses : actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # 6.0.0
124+ uses : actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # 6.0.0
104125 with :
105126 python-version : " 3.x"
106127
@@ -180,8 +201,8 @@ jobs:
180201 with :
181202 sarif_file : ./checkov-results.sarif/results_sarif.sarif
182203
183- - name : Azd down
184- if : ${{ github.event.inputs.run_azd_down == 'true' }}
204+ - name : Destroy Infrastructure
205+ if : ${{ github.event.inputs.run_azd_down == 'true' || github.event_name == 'pull_request' }}
185206 env :
186207 POWER_PLATFORM_CLIENT_ID : ${{ vars.AZURE_CLIENT_ID }}
187208 POWER_PLATFORM_TENANT_ID : ${{ vars.AZURE_TENANT_ID }}
0 commit comments