From 1cd73ec890f723192abb83ead560aac046f0d0fe Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 10:02:44 +1200 Subject: [PATCH 01/27] Create test-deploy.yml --- .github/workflows/test-deploy.yml | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/test-deploy.yml diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml new file mode 100644 index 00000000..30fff02c --- /dev/null +++ b/.github/workflows/test-deploy.yml @@ -0,0 +1,41 @@ +# This is a basic workflow to help you get started with Actions + +name: Test & Deploy + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + branches: [ master ] + pull_request: + branches: [ master ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + deploy: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + - uses: Azure/cli@v1 + + - uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + environment: 'AzureCloud' + + + # Runs a set of commands using the runners shell + - name: Run a multi-line script + run: | + cd azure-front-door/deploy-custom-domain + chmod ./deploy-custom-domain.sh +X + ./deploy-custom-domain.sh + From 5c86487baae940c2f6958bb71c2360717f43cb9f Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 10:06:23 +1200 Subject: [PATCH 02/27] Fix GH action --- .github/workflows/test-deploy.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 30fff02c..00bc3959 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -24,8 +24,7 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 - - uses: Azure/cli@v1 - + - uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} From 58d62d736563dd1c7c8d9455690bedfe92050d93 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 10:07:50 +1200 Subject: [PATCH 03/27] Fix GH action --- .github/workflows/test-deploy.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 00bc3959..6248a6d9 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -24,7 +24,7 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 - + - uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} @@ -35,6 +35,5 @@ jobs: - name: Run a multi-line script run: | cd azure-front-door/deploy-custom-domain - chmod ./deploy-custom-domain.sh +X + chmod +X ./deploy-custom-domain.sh ./deploy-custom-domain.sh - From 3d1227d4512016fa4fadfc3d7baaac6b24529b1c Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 10:38:07 +1200 Subject: [PATCH 04/27] Testing GH action --- .github/workflows/test-deploy.yml | 19 ++++++++++++++++--- .../deploy-custom-domain.sh | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 6248a6d9..3ce8d901 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -7,8 +7,12 @@ on: # Triggers the workflow on push or pull request events but only for the master branch push: branches: [ master ] + paths: + - '**.sh' pull_request: branches: [ master ] + paths: + - '**.sh' # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -24,6 +28,8 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 + with: + fetch-depth: 2 - uses: azure/login@v1 with: @@ -34,6 +40,13 @@ jobs: # Runs a set of commands using the runners shell - name: Run a multi-line script run: | - cd azure-front-door/deploy-custom-domain - chmod +X ./deploy-custom-domain.sh - ./deploy-custom-domain.sh + az config set extension.use_dynamic_install=yes_without_prompt + + for file in $( git diff-tree --no-commit-id --name-only -r ${{ github.sha }} ) + do + if [[ "$file" == *.sh ]] + then + chmod +X $file + /bin/bash $file + fi + done diff --git a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh index edb212e7..cb11f948 100755 --- a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh +++ b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh @@ -111,3 +111,4 @@ echo "$spaFQUrl" # echo "Deleting all resources" # az group delete --name $resourceGroup -y + From 47f73ecccf3519a6a7949c2ae888b1816426429f Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 10:50:34 +1200 Subject: [PATCH 05/27] Test deploy GH Action Set RG env var, run script, cleanup --- .github/workflows/test-deploy.yml | 6 ++++++ .../deploy-custom-domain/deploy-custom-domain.sh | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 3ce8d901..539b80b9 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -46,7 +46,13 @@ jobs: do if [[ "$file" == *.sh ]] then + let "randomIdentifier=$RANDOM*$RANDOM" + export RESOURCE_GROUP="test-deploy-rg-$randomIdentifier" + + echo "Running $file ..." chmod +X $file /bin/bash $file + + az group delete $RESOURCE_GROUP -y --no-wait fi done diff --git a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh index cb11f948..f89c5531 100755 --- a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh +++ b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh @@ -13,6 +13,14 @@ set -e # VARIABLES # Change these hardcoded values if required +if [[ -z "${RESOURCE_GROUP}" ]]; then + let "randomIdentifier=$RANDOM*$RANDOM" + location='AustraliaEast' + resourceGroup="msdocs-frontdoor-rg-$randomIdentifier" +else + resourceGroup="${RESOURCE_GROUP}" +fi + let "randomIdentifier=$RANDOM*$RANDOM" location='AustraliaEast' resourceGroup="msdocs-frontdoor-rg-$randomIdentifier" From 50f0499523fd0a2236d2ab2423ad3ae3ce4e2d99 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 10:56:04 +1200 Subject: [PATCH 06/27] gh action cd to file path --- .github/workflows/test-deploy.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 539b80b9..1493e3c2 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -50,9 +50,11 @@ jobs: export RESOURCE_GROUP="test-deploy-rg-$randomIdentifier" echo "Running $file ..." - chmod +X $file - /bin/bash $file + cd $(dirname "${file}") + chmod +X $(basename "${file}") + /bin/bash $(basename "${file}") + echo "az group delete $RESOURCE_GROUP -y --no-wait" az group delete $RESOURCE_GROUP -y --no-wait fi done From b840882ab22f2748aeb9ebe346cdba240305203c Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 10:58:46 +1200 Subject: [PATCH 07/27] test the action --- azure-front-door/deploy-custom-domain/deploy-custom-domain.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh index f89c5531..77fa426a 100755 --- a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh +++ b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh @@ -120,3 +120,4 @@ echo "$spaFQUrl" # echo "Deleting all resources" # az group delete --name $resourceGroup -y + From d9ee991d9d225b30bab5765da99e920284a5c8f9 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 11:03:53 +1200 Subject: [PATCH 08/27] test the action --- .github/workflows/test-deploy.yml | 4 ++-- azure-front-door/deploy-custom-domain/deploy-custom-domain.sh | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 1493e3c2..6d383496 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -54,7 +54,7 @@ jobs: chmod +X $(basename "${file}") /bin/bash $(basename "${file}") - echo "az group delete $RESOURCE_GROUP -y --no-wait" - az group delete $RESOURCE_GROUP -y --no-wait + echo "az group delete -n $RESOURCE_GROUP -y --no-wait" + az group delete -n $RESOURCE_GROUP -y --no-wait fi done diff --git a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh index 77fa426a..64af17eb 100755 --- a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh +++ b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh @@ -121,3 +121,4 @@ echo "$spaFQUrl" # az group delete --name $resourceGroup -y + From 98211248bbe9fdcf9a180204688a3ed66fe17b40 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 13:17:19 +1200 Subject: [PATCH 09/27] suppress resource group delete error --- .github/workflows/test-deploy.yml | 2 +- azure-front-door/deploy-custom-domain/deploy-custom-domain.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 6d383496..4837b450 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -55,6 +55,6 @@ jobs: /bin/bash $(basename "${file}") echo "az group delete -n $RESOURCE_GROUP -y --no-wait" - az group delete -n $RESOURCE_GROUP -y --no-wait + az group delete -n $RESOURCE_GROUP -y --no-wait 2>nul fi done diff --git a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh index 64af17eb..77fa426a 100755 --- a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh +++ b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh @@ -121,4 +121,3 @@ echo "$spaFQUrl" # az group delete --name $resourceGroup -y - From fc1de87c0eadd5e751abe83953f4e858e0e65efd Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 13:28:46 +1200 Subject: [PATCH 10/27] delete RG if exists --- .github/workflows/test-deploy.yml | 9 +++++---- .../deploy-custom-domain/deploy-custom-domain.sh | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 4837b450..87641c3a 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -47,14 +47,15 @@ jobs: if [[ "$file" == *.sh ]] then let "randomIdentifier=$RANDOM*$RANDOM" - export RESOURCE_GROUP="test-deploy-rg-$randomIdentifier" echo "Running $file ..." cd $(dirname "${file}") chmod +X $(basename "${file}") - /bin/bash $(basename "${file}") + /bin/bash RESOURCE_GROUP="test-deploy-rg-$randomIdentifier" $(basename "${file}") - echo "az group delete -n $RESOURCE_GROUP -y --no-wait" - az group delete -n $RESOURCE_GROUP -y --no-wait 2>nul + if [ $(az group exists --name $RESOURCE_GROUP) = true ]; then + echo "az group delete -n $RESOURCE_GROUP -y --no-wait" + az group delete -n $RESOURCE_GROUP -y --no-wait + fi fi done diff --git a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh index 77fa426a..f89c5531 100755 --- a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh +++ b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh @@ -120,4 +120,3 @@ echo "$spaFQUrl" # echo "Deleting all resources" # az group delete --name $resourceGroup -y - From 4d550df6cc8dc629bc45b6eb18b7be8c7642f996 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 13:32:58 +1200 Subject: [PATCH 11/27] Fix action --- .github/workflows/test-deploy.yml | 2 +- azure-front-door/deploy-custom-domain/deploy-custom-domain.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 87641c3a..c55468c7 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -51,7 +51,7 @@ jobs: echo "Running $file ..." cd $(dirname "${file}") chmod +X $(basename "${file}") - /bin/bash RESOURCE_GROUP="test-deploy-rg-$randomIdentifier" $(basename "${file}") + RESOURCE_GROUP="test-deploy-rg-$randomIdentifier" /bin/bash $(basename "${file}") if [ $(az group exists --name $RESOURCE_GROUP) = true ]; then echo "az group delete -n $RESOURCE_GROUP -y --no-wait" diff --git a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh index f89c5531..6d1b82ba 100755 --- a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh +++ b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh @@ -119,4 +119,3 @@ echo "$spaFQUrl" # echo "Deleting all resources" # az group delete --name $resourceGroup -y - From b5b468e9b5347445f55513ffb3c48ceacd81d54d Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 13:36:59 +1200 Subject: [PATCH 12/27] Fix GH test deploy action --- .github/workflows/test-deploy.yml | 9 +++++---- .../deploy-custom-domain/deploy-custom-domain.sh | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index c55468c7..48391205 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -47,15 +47,16 @@ jobs: if [[ "$file" == *.sh ]] then let "randomIdentifier=$RANDOM*$RANDOM" + resourceGroup="test-deploy-rg-$randomIdentifier" echo "Running $file ..." cd $(dirname "${file}") chmod +X $(basename "${file}") - RESOURCE_GROUP="test-deploy-rg-$randomIdentifier" /bin/bash $(basename "${file}") + RESOURCE_GROUP=$resourceGroup /bin/bash $(basename "${file}") - if [ $(az group exists --name $RESOURCE_GROUP) = true ]; then - echo "az group delete -n $RESOURCE_GROUP -y --no-wait" - az group delete -n $RESOURCE_GROUP -y --no-wait + if [ $(az group exists --name $resourceGroup) = true ]; then + echo "az group delete -n $resourceGroup -y --no-wait" + az group delete -n $resourceGroup -y --no-wait fi fi done diff --git a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh index 6d1b82ba..f89c5531 100755 --- a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh +++ b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh @@ -119,3 +119,4 @@ echo "$spaFQUrl" # echo "Deleting all resources" # az group delete --name $resourceGroup -y + From bab194b8cad6beca232828ca8f19bea014a4baf5 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 13:45:52 +1200 Subject: [PATCH 13/27] Fix resource group env var --- .github/workflows/test-deploy.yml | 7 +++---- .../deploy-custom-domain/deploy-custom-domain.sh | 16 +++++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 48391205..e094057b 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -29,19 +29,18 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 with: - fetch-depth: 2 + fetch-depth: 2 # Deep fetch so that we can query the diff-tree - uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} environment: 'AzureCloud' - - # Runs a set of commands using the runners shell - - name: Run a multi-line script + - name: Run any shell scripts in this commit run: | az config set extension.use_dynamic_install=yes_without_prompt + # For each file in this commit for file in $( git diff-tree --no-commit-id --name-only -r ${{ github.sha }} ) do if [[ "$file" == *.sh ]] diff --git a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh index f89c5531..245440a4 100755 --- a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh +++ b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh @@ -13,17 +13,16 @@ set -e # VARIABLES # Change these hardcoded values if required -if [[ -z "${RESOURCE_GROUP}" ]]; then - let "randomIdentifier=$RANDOM*$RANDOM" - location='AustraliaEast' - resourceGroup="msdocs-frontdoor-rg-$randomIdentifier" -else - resourceGroup="${RESOURCE_GROUP}" +# Use environment variable if set +if [ "$RESOURCE_GROUP" == '' ]; + then + let "randomIdentifier=$RANDOM*$RANDOM" + resourceGroup="msdocs-frontdoor-rg-$randomIdentifier" + else + resourceGroup="${RESOURCE_GROUP}" fi -let "randomIdentifier=$RANDOM*$RANDOM" location='AustraliaEast' -resourceGroup="msdocs-frontdoor-rg-$randomIdentifier" tag='deploy-custom-domain' storage="msdocsafd$randomIdentifier" @@ -119,4 +118,3 @@ echo "$spaFQUrl" # echo "Deleting all resources" # az group delete --name $resourceGroup -y - From 5bb6e253e78f5b1e3bafe37d2e72c43db24f9286 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 13:49:33 +1200 Subject: [PATCH 14/27] Fix resource group env var --- .github/workflows/test-deploy.yml | 2 ++ .../deploy-custom-domain/deploy-custom-domain.sh | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index e094057b..abd176cd 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -43,8 +43,10 @@ jobs: # For each file in this commit for file in $( git diff-tree --no-commit-id --name-only -r ${{ github.sha }} ) do + # If a shell script if [[ "$file" == *.sh ]] then + # Generate a resource group name so that it can be deleted when finished let "randomIdentifier=$RANDOM*$RANDOM" resourceGroup="test-deploy-rg-$randomIdentifier" diff --git a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh index 245440a4..f4395999 100755 --- a/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh +++ b/azure-front-door/deploy-custom-domain/deploy-custom-domain.sh @@ -13,10 +13,11 @@ set -e # VARIABLES # Change these hardcoded values if required -# Use environment variable if set +let "randomIdentifier=$RANDOM*$RANDOM" + +# Use resource group environment variable if set if [ "$RESOURCE_GROUP" == '' ]; then - let "randomIdentifier=$RANDOM*$RANDOM" resourceGroup="msdocs-frontdoor-rg-$randomIdentifier" else resourceGroup="${RESOURCE_GROUP}" From 4114456f935e2b2b270caa2887dea20fb833f388 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Tue, 24 May 2022 13:57:01 +1200 Subject: [PATCH 15/27] Tidy up GH action --- .github/workflows/test-deploy.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index abd176cd..c297a81b 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -1,10 +1,6 @@ -# This is a basic workflow to help you get started with Actions - name: Test & Deploy -# Controls when the workflow will run on: - # Triggers the workflow on push or pull request events but only for the master branch push: branches: [ master ] paths: @@ -17,16 +13,11 @@ on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" deploy: - # The type of runner that the job will run on runs-on: ubuntu-latest - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 with: fetch-depth: 2 # Deep fetch so that we can query the diff-tree @@ -55,6 +46,7 @@ jobs: chmod +X $(basename "${file}") RESOURCE_GROUP=$resourceGroup /bin/bash $(basename "${file}") + # Clean up the resource group if [ $(az group exists --name $resourceGroup) = true ]; then echo "az group delete -n $resourceGroup -y --no-wait" az group delete -n $resourceGroup -y --no-wait From 55c491ee1ad250966a7e82bdf0b3e9cab4e12bce Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Fri, 27 May 2022 10:44:53 +1200 Subject: [PATCH 16/27] echo out git diff --- .github/workflows/test-deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index c297a81b..8400865f 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -32,6 +32,7 @@ jobs: az config set extension.use_dynamic_install=yes_without_prompt # For each file in this commit + git diff-tree --no-commit-id --name-only -r ${{ github.sha }} for file in $( git diff-tree --no-commit-id --name-only -r ${{ github.sha }} ) do # If a shell script From d00db36249560745c58c1ad403f9d7114fa74855 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Fri, 27 May 2022 10:54:34 +1200 Subject: [PATCH 17/27] echo out git diff --- .github/workflows/test-deploy.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 8400865f..4727164d 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -32,8 +32,10 @@ jobs: az config set extension.use_dynamic_install=yes_without_prompt # For each file in this commit - git diff-tree --no-commit-id --name-only -r ${{ github.sha }} - for file in $( git diff-tree --no-commit-id --name-only -r ${{ github.sha }} ) + git --no-pager diff --name-only FETCH_HEAD...master + #git diff-tree --no-commit-id --name-only -r ${{ github.sha }} + #for file in $( git diff-tree --no-commit-id --name-only -r ${{ github.sha }} ) + for file in $( git --no-pager diff --name-only FETCH_HEAD...master ) do # If a shell script if [[ "$file" == *.sh ]] From 768f8419241366315b44c01a54790954ae4b4eeb Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Fri, 27 May 2022 11:56:36 +1200 Subject: [PATCH 18/27] fixing workflow --- .github/workflows/test-deploy.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 4727164d..13947899 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -28,14 +28,21 @@ jobs: environment: 'AzureCloud' - name: Run any shell scripts in this commit + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | az config set extension.use_dynamic_install=yes_without_prompt # For each file in this commit - git --no-pager diff --name-only FETCH_HEAD...master + + gh pr view XXX --json files -q '.files[].path' + + #git --no-pager diff --name-only FETCH_HEAD...master #git diff-tree --no-commit-id --name-only -r ${{ github.sha }} + #for file in $( git diff-tree --no-commit-id --name-only -r ${{ github.sha }} ) - for file in $( git --no-pager diff --name-only FETCH_HEAD...master ) + #for file in $( git --no-pager diff --name-only FETCH_HEAD...master ) + for file in $( gh pr view XXX --json files -q '.files[].path' ) do # If a shell script if [[ "$file" == *.sh ]] From 450de3c80e8d9dd8e2d028953e87d138fbb1521b Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Fri, 27 May 2022 12:12:58 +1200 Subject: [PATCH 19/27] fixing workflow --- .github/workflows/test-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 13947899..fc90f5f4 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -42,7 +42,7 @@ jobs: #for file in $( git diff-tree --no-commit-id --name-only -r ${{ github.sha }} ) #for file in $( git --no-pager diff --name-only FETCH_HEAD...master ) - for file in $( gh pr view XXX --json files -q '.files[].path' ) + for file in $( gh pr view master --json files -q '.files[].path' ) do # If a shell script if [[ "$file" == *.sh ]] From 926e75c4247a5965141110e496a21cd1208f7bce Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Fri, 27 May 2022 12:16:54 +1200 Subject: [PATCH 20/27] Update test-deploy.yml --- .github/workflows/test-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index fc90f5f4..19a93bc4 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -35,7 +35,7 @@ jobs: # For each file in this commit - gh pr view XXX --json files -q '.files[].path' + gh pr view master --json files -q '.files[].path' #git --no-pager diff --name-only FETCH_HEAD...master #git diff-tree --no-commit-id --name-only -r ${{ github.sha }} From d5a69abe8ae2f7d7a27ebfed3f01dbd18ecc01cf Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Fri, 27 May 2022 12:20:06 +1200 Subject: [PATCH 21/27] Update test-deploy.yml --- .github/workflows/test-deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 19a93bc4..9f8369af 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -35,14 +35,14 @@ jobs: # For each file in this commit - gh pr view master --json files -q '.files[].path' + gh pr view --json files -q '.files[].path' #git --no-pager diff --name-only FETCH_HEAD...master #git diff-tree --no-commit-id --name-only -r ${{ github.sha }} #for file in $( git diff-tree --no-commit-id --name-only -r ${{ github.sha }} ) #for file in $( git --no-pager diff --name-only FETCH_HEAD...master ) - for file in $( gh pr view master --json files -q '.files[].path' ) + for file in $( gh pr view --json files -q '.files[].path' ) do # If a shell script if [[ "$file" == *.sh ]] From 357b14741a24ab77e636299d78fda3e3cd6cecf3 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Fri, 27 May 2022 12:25:24 +1200 Subject: [PATCH 22/27] Update test-deploy.yml --- .github/workflows/test-deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 9f8369af..2a73a457 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -35,14 +35,14 @@ jobs: # For each file in this commit - gh pr view --json files -q '.files[].path' + gh pr view ${{ github.head_ref }} --json files -q '.files[].path' #git --no-pager diff --name-only FETCH_HEAD...master #git diff-tree --no-commit-id --name-only -r ${{ github.sha }} #for file in $( git diff-tree --no-commit-id --name-only -r ${{ github.sha }} ) #for file in $( git --no-pager diff --name-only FETCH_HEAD...master ) - for file in $( gh pr view --json files -q '.files[].path' ) + for file in $( gh pr view ${{ github.head_ref }} --json files -q '.files[].path' ) do # If a shell script if [[ "$file" == *.sh ]] From c2a3d8c498fae6473274f94162cabf1e59031dd3 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Fri, 27 May 2022 12:33:37 +1200 Subject: [PATCH 23/27] Tidy up workflow --- .github/workflows/test-deploy.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 2a73a457..4d849977 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -33,15 +33,10 @@ jobs: run: | az config set extension.use_dynamic_install=yes_without_prompt - # For each file in this commit - + echo "Files in PR ${{ github.head_ref }}:" gh pr view ${{ github.head_ref }} --json files -q '.files[].path' - #git --no-pager diff --name-only FETCH_HEAD...master - #git diff-tree --no-commit-id --name-only -r ${{ github.sha }} - - #for file in $( git diff-tree --no-commit-id --name-only -r ${{ github.sha }} ) - #for file in $( git --no-pager diff --name-only FETCH_HEAD...master ) + # For each file in this commit for file in $( gh pr view ${{ github.head_ref }} --json files -q '.files[].path' ) do # If a shell script From 139dd9dae6c32c38dee93d5722fcfd87f13d3733 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Fri, 27 May 2022 12:54:27 +1200 Subject: [PATCH 24/27] Fix cd => pushd --- .github/workflows/test-deploy.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 4d849977..bd4218f7 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -47,10 +47,11 @@ jobs: resourceGroup="test-deploy-rg-$randomIdentifier" echo "Running $file ..." - cd $(dirname "${file}") + pushd $(dirname "${file}") chmod +X $(basename "${file}") RESOURCE_GROUP=$resourceGroup /bin/bash $(basename "${file}") - + popd + # Clean up the resource group if [ $(az group exists --name $resourceGroup) = true ]; then echo "az group delete -n $resourceGroup -y --no-wait" From 3f14a6c0cbabae3f62bbd4740b7b0ee2ff31c4f4 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Fri, 27 May 2022 13:42:08 +1200 Subject: [PATCH 25/27] Don't run deleted files --- .github/workflows/test-deploy.yml | 43 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index bd4218f7..b8a547de 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -32,30 +32,37 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | az config set extension.use_dynamic_install=yes_without_prompt - + + echo "====================================" echo "Files in PR ${{ github.head_ref }}:" gh pr view ${{ github.head_ref }} --json files -q '.files[].path' - + echo "====================================" + # For each file in this commit for file in $( gh pr view ${{ github.head_ref }} --json files -q '.files[].path' ) do - # If a shell script - if [[ "$file" == *.sh ]] + # If file exists and is shell script + if [ -e "$file" ] then - # Generate a resource group name so that it can be deleted when finished - let "randomIdentifier=$RANDOM*$RANDOM" - resourceGroup="test-deploy-rg-$randomIdentifier" - - echo "Running $file ..." - pushd $(dirname "${file}") - chmod +X $(basename "${file}") - RESOURCE_GROUP=$resourceGroup /bin/bash $(basename "${file}") - popd - - # Clean up the resource group - if [ $(az group exists --name $resourceGroup) = true ]; then - echo "az group delete -n $resourceGroup -y --no-wait" - az group delete -n $resourceGroup -y --no-wait + if [[ "$file" == *.sh ]] + then + # Generate a resource group name so that it can be deleted when finished + let "randomIdentifier=$RANDOM*$RANDOM" + resourceGroup="test-deploy-rg-$randomIdentifier" + + echo "====================================" + echo "Running $file ..." + pushd $(dirname "${file}") + chmod +X $(basename "${file}") + RESOURCE_GROUP=$resourceGroup /bin/bash $(basename "${file}") + popd + echo "====================================" + + # Clean up the resource group + if [ $(az group exists --name $resourceGroup) = true ]; then + echo "Deleting resource group $resourceGroup..." + az group delete -n $resourceGroup -y --no-wait + fi fi fi done From 515977f00b0b72e6f10722eab809cb7201f720fb Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Fri, 27 May 2022 13:47:37 +1200 Subject: [PATCH 26/27] Update test-deploy.yml --- .github/workflows/test-deploy.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index b8a547de..e3faf054 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -19,8 +19,6 @@ jobs: steps: - uses: actions/checkout@v3 - with: - fetch-depth: 2 # Deep fetch so that we can query the diff-tree - uses: azure/login@v1 with: @@ -36,7 +34,6 @@ jobs: echo "====================================" echo "Files in PR ${{ github.head_ref }}:" gh pr view ${{ github.head_ref }} --json files -q '.files[].path' - echo "====================================" # For each file in this commit for file in $( gh pr view ${{ github.head_ref }} --json files -q '.files[].path' ) From 29d0230053b51d15186d0059d90f30f625d02c91 Mon Sep 17 00:00:00 2001 From: Daniel Larsen Date: Fri, 27 May 2022 16:30:46 +1200 Subject: [PATCH 27/27] Update test-deploy.yml --- .github/workflows/test-deploy.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index e3faf054..f95e552a 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -1,10 +1,6 @@ name: Test & Deploy on: - push: - branches: [ master ] - paths: - - '**.sh' pull_request: branches: [ master ] paths: