From d09e7c0a3fcda6ff0cc1495c2a281738224a9803 Mon Sep 17 00:00:00 2001 From: Fred Gohsman Date: Thu, 26 Aug 2021 16:25:06 -0400 Subject: [PATCH 1/8] modified to use variable files --- .github/variables/dev.json | 12 ++++ .github/variables/prod.json | 12 ++++ .github/variables/qa.json | 12 ++++ .github/workflows/continuous-delivery.yml | 72 +++++++++++++++-------- infra/azuredeploy.dev.parameters.json | 2 +- infra/azuredeploy.prod.parameters.json | 2 +- infra/azuredeploy.qa.parameters.json | 2 +- 7 files changed, 86 insertions(+), 28 deletions(-) create mode 100644 .github/variables/dev.json create mode 100644 .github/variables/prod.json create mode 100644 .github/variables/qa.json diff --git a/.github/variables/dev.json b/.github/variables/dev.json new file mode 100644 index 0000000..e3bdb85 --- /dev/null +++ b/.github/variables/dev.json @@ -0,0 +1,12 @@ +{ + "variables": [ + { + "name": "resourceGroup", + "value": "rg-dev" + }, + { + "name": "webAppName", + "value": "app-0a1b2c-dev" + } + ] + } \ No newline at end of file diff --git a/.github/variables/prod.json b/.github/variables/prod.json new file mode 100644 index 0000000..5221d41 --- /dev/null +++ b/.github/variables/prod.json @@ -0,0 +1,12 @@ +{ + "variables": [ + { + "name": "resourceGroup", + "value": "rg-prod" + }, + { + "name": "webAppName", + "value": "app-0a1b2c" + } + ] + } \ No newline at end of file diff --git a/.github/variables/qa.json b/.github/variables/qa.json new file mode 100644 index 0000000..0aaff55 --- /dev/null +++ b/.github/variables/qa.json @@ -0,0 +1,12 @@ +{ + "variables": [ + { + "name": "resourceGroup", + "value": "rg-qa" + }, + { + "name": "webAppName", + "value": "app-0a1b2c-dev" + } + ] + } \ No newline at end of file diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 80335cb..553f2ba 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -14,12 +14,6 @@ on: env: deploymentSlotName: stage - devResourceGroup: rg-dev - devUrl: https://app-0a1b2c-dev.azurewebsites.net - prodResourceGroup: rg-prod - prodUrl: https://app-0a1b2c.azurewebsites.net - qaResourceGroup: rg-qa - qaUrl: https://app-0a1b2c-qa.azurewebsites.net stageUrl: https://app-0a1b2c-stage.azurewebsites.net jobs: @@ -36,6 +30,7 @@ jobs: run: echo "Running build steps..." # Publish the artificats so they are available by subsequent jobs + # Uploading application to build artifact - name: Upload ARM Templates as Artifact continue-on-error: false @@ -44,7 +39,6 @@ jobs: name: infra path: infra - # Publish the artificats so they are available by subsequent jobs # Uploading application to build artifact - name: Upload Application Build as Artifact continue-on-error: false @@ -53,6 +47,14 @@ jobs: name: build path: src + # Uploading variables folder to build artifact + - name: Upload Application Build as Artifact + continue-on-error: false + uses: actions/upload-artifact@v2 + with: + name: variables + path: variables + # Deploy to the Development servers DeployDev: @@ -62,13 +64,18 @@ jobs: runs-on: ubuntu-latest environment: name: Development - url: ${{ env.devUrl }} steps: # Download Artifacts - name: Download Artifacts uses: actions/download-artifact@v2 continue-on-error: false + + # Load Environment Variables from local file + - name: Load Environment Variables + uses: deep-mm/set-variables@v1 + with: + variableFileName: ./variables/dev # Log in to Azure - uses: azure/login@v1 @@ -80,15 +87,15 @@ jobs: id: deployStep with: subscriptionId: ${{ secrets.SUBSCRIPTIONID }} - resourceGroupName: ${{ env.devResourceGroup }} + resourceGroupName: ${{ env.resourceGroup }} template: ./infra/azuredeploy.json - parameters: ./infra/azuredeploy.dev.parameters.json + parameters: ./infra/azuredeploy.dev.parameters.json webAppName=${{ env.webAppName }} # Deploy code to web app - name: Deploy code to the WebApp uses: Azure/webapps-deploy@v2 with: - app-name: ${{ steps.deployStep.outputs.webAppName }} + app-name: ${{ env.webAppName }} package: ./build - name: Deployment Message @@ -103,13 +110,18 @@ jobs: runs-on: ubuntu-latest environment: name: QA - url: ${{ env.qaUrl }} steps: # Download Artifacts - name: Download Artifacts uses: actions/download-artifact@v2 continue-on-error: false + + # Load Environment Variables from local file + - name: Load Environment Variables + uses: deep-mm/set-variables@v1 + with: + variableFileName: ./variables/qa # Log in to Azure - uses: azure/login@v1 @@ -121,15 +133,15 @@ jobs: id: deployStep with: subscriptionId: ${{ secrets.SUBSCRIPTIONID }} - resourceGroupName: ${{ env.qaResourceGroup }} + resourceGroupName: ${{ env.resourceGroup }} template: ./infra/azuredeploy.json - parameters: ./infra/azuredeploy.qa.parameters.json + parameters: ./infra/azuredeploy.qa.parameters.json webAppName=${{ env.webAppName }} # Deploy code to web app - name: Deploy code to the WebApp uses: Azure/webapps-deploy@v2 with: - app-name: ${{ steps.deployStep.outputs.webAppName }} + app-name: ${{ env.webAppName }} package: ./build - name: Deployment Message @@ -143,15 +155,18 @@ jobs: runs-on: ubuntu-latest environment: name: Stage - url: ${{ env.stageUrl }} - outputs: - webAppName: ${{ steps.deployStep.outputs.webAppName }} steps: # Download Artifacts - name: Download Artifacts uses: actions/download-artifact@v2 continue-on-error: false + + # Load Environment Variables from local file + - name: Load Environment Variables + uses: deep-mm/set-variables@v1 + with: + variableFileName: ./variables/prod # Log in to Azure - uses: azure/login@v1 @@ -163,15 +178,15 @@ jobs: id: deployStep with: subscriptionId: ${{ secrets.SUBSCRIPTIONID }} - resourceGroupName: ${{ env.prodResourceGroup }} + resourceGroupName: ${{ env.resourceGroup }} template: ./infra/azuredeploy.json - parameters: ./infra/azuredeploy.prod.parameters.json + parameters: ./infra/azuredeploy.prod.parameters.json webAppName=${{ env.webAppName }} # Deploy code to web app - name: Deploy code to the WebApp uses: Azure/webapps-deploy@v2 with: - app-name: ${{ steps.deployStep.outputs.webAppName }} + app-name: ${{ env.webAppName }} slot-name: ${{ env.deploymentSlotName }} package: ./build @@ -186,11 +201,18 @@ jobs: runs-on: ubuntu-latest environment: name: Production - url: ${{ env.prodUrl }} steps: - - name: Deploy to Production - run: echo "Deploy Application to Production" + # Download Artifacts + - name: Download Artifacts + uses: actions/download-artifact@v2 + continue-on-error: false + + # Load Environment Variables from local file + - name: Load Environment Variables + uses: deep-mm/set-variables@v1 + with: + variableFileName: ./variables/prod # Log in to Azure - uses: azure/login@v1 @@ -202,4 +224,4 @@ jobs: - uses: azure/cli@v1 with: inlineScript: | - az webapp deployment slot swap -g ${{ env.prodResourceGroup }} -n ${{ needs.DeployStage.outputs.webAppName }} -s ${{ env.deploymentSlotName }} + az webapp deployment slot swap -g ${{ env.resourceGroup }} -n ${{ env.webAppName }} -s ${{ env.deploymentSlotName }} diff --git a/infra/azuredeploy.dev.parameters.json b/infra/azuredeploy.dev.parameters.json index 5f763c1..010708b 100644 --- a/infra/azuredeploy.dev.parameters.json +++ b/infra/azuredeploy.dev.parameters.json @@ -12,7 +12,7 @@ "value": "asp-0a1b2c-dev" }, "webAppName": { - "value": "app-0a1b2c-dev" + "value": "web-app-dev" } } } \ No newline at end of file diff --git a/infra/azuredeploy.prod.parameters.json b/infra/azuredeploy.prod.parameters.json index a25e3ee..4ef4930 100644 --- a/infra/azuredeploy.prod.parameters.json +++ b/infra/azuredeploy.prod.parameters.json @@ -12,7 +12,7 @@ "value": "asp-0a1b2c" }, "webAppName": { - "value": "app-0a1b2c" + "value": "web-app-prod" } } } \ No newline at end of file diff --git a/infra/azuredeploy.qa.parameters.json b/infra/azuredeploy.qa.parameters.json index 68b6a6b..38655ae 100644 --- a/infra/azuredeploy.qa.parameters.json +++ b/infra/azuredeploy.qa.parameters.json @@ -12,7 +12,7 @@ "value": "asp-0a1b2c-qa" }, "webAppName": { - "value": "app-0a1b2c-qa" + "value": "web-app-qa" } } } \ No newline at end of file From a0049dc35d98a957f13a470a0654e22671b39300 Mon Sep 17 00:00:00 2001 From: Fred Gohsman Date: Thu, 26 Aug 2021 16:52:36 -0400 Subject: [PATCH 2/8] added own custom action --- .github/actions/set-variables/action.yml | 28 ++++++++++++++++ .github/actions/set-variables/readme.md | 39 +++++++++++++++++++++++ .github/workflows/continuous-delivery.yml | 21 ++++++------ 3 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 .github/actions/set-variables/action.yml create mode 100644 .github/actions/set-variables/readme.md diff --git a/.github/actions/set-variables/action.yml b/.github/actions/set-variables/action.yml new file mode 100644 index 0000000..370c71d --- /dev/null +++ b/.github/actions/set-variables/action.yml @@ -0,0 +1,28 @@ +name: 'Set Variable' +description: 'Convert your variables.json file in .github/variables into environment variables to be used within the scope of a job.' +inputs: + variableFileName: + description: 'Name of variable file. File must be of format {"variables": [{"name": "variable1","value": "variable1value"}]}' + required: true + default: 'variable' +outputs: + status: + description: "Status" + value: "Pass" +runs: + using: "composite" + steps: + - run: echo Setting variables from following file ${{ inputs.variableFileName }}.json + shell: bash + + - name: Set Environment Variables - ${{ inputs.variableFileName }}.json + shell: bash + run: | + variablePath='${{ inputs.variableFileName }}.json' + while read variable; do + key=$(jq -r '.name' <<< $variable) + value=$(jq -r '.value' <<< $variable) + echo $key + echo $value + echo "$key=$value" >> $GITHUB_ENV + done <<< $(jq -c '.variables[]' $variablePath) \ No newline at end of file diff --git a/.github/actions/set-variables/readme.md b/.github/actions/set-variables/readme.md new file mode 100644 index 0000000..1d5e824 --- /dev/null +++ b/.github/actions/set-variables/readme.md @@ -0,0 +1,39 @@ +# GitHub Action - Set Variables +Are you missing the Azure DevOps Library variable groups in GitHub Actions? +If yes, then this action will act as a substitution of Library variable groups in GitHub. [Currently only supports windows and ubuntu agents] + +This is a GitHub Action used to convert variables.json files into environment variables. + +## 1. Add your variable files as json in this folder - .github/variables/{variable_file_name}.json +The format of the file should be: +``` +{ + "variables": [ + { + "name": "variable1", + "value": "variable1value" + }, + { + "name": "variable2", + "value": "variable2value" + } + ] +} +``` + +## 2. Now in your job, to use these variables, add the following action into your job +``` +- name: Set Variable + uses: deep-mm/set-variables@v1.0 + with: + # Name of variable file + variableFileName: 'variables' #Dont write .json here +``` +The variables in your variables.json file will now be converted to environment variables that you can use in the next steps of the same job. +Ths scope of variables is only the job and not the entire workflow. + +## 3. Use these variables in next steps +``` +${{ env.variable1 }} +${{ env.variable2 }} +``` \ No newline at end of file diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 553f2ba..506e763 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -26,9 +26,6 @@ jobs: # Checks-out the repository under $GITHUB_WORKSPACE, so the job can access it - uses: actions/checkout@v2 - - name: Build Steps Here - run: echo "Running build steps..." - # Publish the artificats so they are available by subsequent jobs # Uploading application to build artifact @@ -53,7 +50,7 @@ jobs: uses: actions/upload-artifact@v2 with: name: variables - path: variables + path: .github/variables # Deploy to the Development servers @@ -73,9 +70,9 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: deep-mm/set-variables@v1 + uses: actions/set-variables with: - variableFileName: ./variables/dev + variableFileName: dev # Log in to Azure - uses: azure/login@v1 @@ -119,9 +116,9 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: deep-mm/set-variables@v1 + uses: actions/set-variables with: - variableFileName: ./variables/qa + variableFileName: qa # Log in to Azure - uses: azure/login@v1 @@ -164,9 +161,9 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: deep-mm/set-variables@v1 + uses: actions/set-variables with: - variableFileName: ./variables/prod + variableFileName: prod # Log in to Azure - uses: azure/login@v1 @@ -210,9 +207,9 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: deep-mm/set-variables@v1 + uses: actions/set-variables with: - variableFileName: ./variables/prod + variableFileName: prod # Log in to Azure - uses: azure/login@v1 From aa2f3fa76515c7d11435bd6f1ec81764d0554fbe Mon Sep 17 00:00:00 2001 From: Fred Gohsman Date: Thu, 26 Aug 2021 17:06:46 -0400 Subject: [PATCH 3/8] changed name of action --- .github/workflows/continuous-delivery.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 506e763..4d456e2 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -70,7 +70,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: actions/set-variables + uses: fredcicles/set-variables with: variableFileName: dev @@ -116,7 +116,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: actions/set-variables + uses: fredcicles/set-variables with: variableFileName: qa @@ -161,7 +161,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: actions/set-variables + uses: fredcicles/set-variables with: variableFileName: prod @@ -207,7 +207,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: actions/set-variables + uses: fredcicles/set-variables with: variableFileName: prod From 04abbbd1829a8d0411781314a90909f2ae6c0c00 Mon Sep 17 00:00:00 2001 From: Fred Gohsman Date: Thu, 26 Aug 2021 17:07:42 -0400 Subject: [PATCH 4/8] changed name of action --- .github/workflows/continuous-delivery.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 4d456e2..7007cb7 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -70,7 +70,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: fredcicles/set-variables + uses: fredcicles/github-actions/set-variables with: variableFileName: dev @@ -116,7 +116,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: fredcicles/set-variables + uses: fredcicles/github-actions/set-variables with: variableFileName: qa @@ -161,7 +161,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: fredcicles/set-variables + uses: fredcicles/github-actions/set-variables with: variableFileName: prod @@ -207,7 +207,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: fredcicles/set-variables + uses: fredcicles/github-actions/set-variables with: variableFileName: prod From a601b7ca9e186cbe9cbff263a855933578bf2139 Mon Sep 17 00:00:00 2001 From: Fred Gohsman Date: Thu, 26 Aug 2021 17:09:00 -0400 Subject: [PATCH 5/8] changed name of action --- .github/workflows/continuous-delivery.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 7007cb7..e3f261a 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -70,7 +70,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: fredcicles/github-actions/set-variables + uses: fredcicles/github-actions/.github/actions/set-variables with: variableFileName: dev @@ -116,7 +116,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: fredcicles/github-actions/set-variables + uses: fredcicles/github-actions/.github/actions/set-variables with: variableFileName: qa @@ -161,7 +161,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: fredcicles/github-actions/set-variables + uses: fredcicles/github-actions/.github/actions/set-variables with: variableFileName: prod @@ -207,7 +207,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: fredcicles/github-actions/set-variables + uses: fredcicles/github-actions/.github/actions/set-variables with: variableFileName: prod From 51874c71987ab3e9f7dea4def915b99cb7fa6594 Mon Sep 17 00:00:00 2001 From: Fred Gohsman Date: Thu, 26 Aug 2021 17:11:31 -0400 Subject: [PATCH 6/8] changed name of action --- .github/workflows/continuous-delivery.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index e3f261a..7d850c1 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -70,7 +70,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: fredcicles/github-actions/.github/actions/set-variables + uses: fredcicles/github-actions/.github/actions/set-variables@samples/variable-files with: variableFileName: dev @@ -116,7 +116,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: fredcicles/github-actions/.github/actions/set-variables + uses: fredcicles/github-actions/.github/actions/set-variables@samples/variable-files with: variableFileName: qa @@ -161,7 +161,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: fredcicles/github-actions/.github/actions/set-variables + uses: fredcicles/github-actions/.github/actions/set-variables@samples/variable-files with: variableFileName: prod @@ -207,7 +207,7 @@ jobs: # Load Environment Variables from local file - name: Load Environment Variables - uses: fredcicles/github-actions/.github/actions/set-variables + uses: fredcicles/github-actions/.github/actions/set-variables@samples/variable-files with: variableFileName: prod From 0f02b09230dddac4a7c529cb2a140b8ac4d699f4 Mon Sep 17 00:00:00 2001 From: Fred Gohsman Date: Thu, 26 Aug 2021 17:24:10 -0400 Subject: [PATCH 7/8] changed name of action --- .github/workflows/continuous-delivery.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 7d850c1..75848a0 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -72,7 +72,7 @@ jobs: - name: Load Environment Variables uses: fredcicles/github-actions/.github/actions/set-variables@samples/variable-files with: - variableFileName: dev + variableFileName: ./variables/dev # Log in to Azure - uses: azure/login@v1 @@ -118,7 +118,7 @@ jobs: - name: Load Environment Variables uses: fredcicles/github-actions/.github/actions/set-variables@samples/variable-files with: - variableFileName: qa + variableFileName: ./variables/qa # Log in to Azure - uses: azure/login@v1 @@ -163,7 +163,7 @@ jobs: - name: Load Environment Variables uses: fredcicles/github-actions/.github/actions/set-variables@samples/variable-files with: - variableFileName: prod + variableFileName: ./variables/prod # Log in to Azure - uses: azure/login@v1 @@ -209,7 +209,7 @@ jobs: - name: Load Environment Variables uses: fredcicles/github-actions/.github/actions/set-variables@samples/variable-files with: - variableFileName: prod + variableFileName: ./variables/prod # Log in to Azure - uses: azure/login@v1 From 4d5bbd26196501371cf5a998cd879b885d658f41 Mon Sep 17 00:00:00 2001 From: Fred Gohsman Date: Thu, 26 Aug 2021 17:41:31 -0400 Subject: [PATCH 8/8] moved deploymentSlotName to variables file --- .github/variables/prod.json | 4 ++++ .github/workflows/continuous-delivery.yml | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/variables/prod.json b/.github/variables/prod.json index 5221d41..7d107d4 100644 --- a/.github/variables/prod.json +++ b/.github/variables/prod.json @@ -1,5 +1,9 @@ { "variables": [ + { + "name": "deploymentSlotName", + "value": "stage" + }, { "name": "resourceGroup", "value": "rg-prod" diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 75848a0..47d6254 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -12,10 +12,6 @@ on: pull_request: branches: [main] -env: - deploymentSlotName: stage - stageUrl: https://app-0a1b2c-stage.azurewebsites.net - jobs: # Build Application