Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/actions/set-variables/action.yml
Original file line number Diff line number Diff line change
@@ -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)
39 changes: 39 additions & 0 deletions .github/actions/set-variables/readme.md
Original file line number Diff line number Diff line change
@@ -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 }}
```
12 changes: 12 additions & 0 deletions .github/variables/dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"variables": [
{
"name": "resourceGroup",
"value": "rg-dev"
},
{
"name": "webAppName",
"value": "app-0a1b2c-dev"
}
]
}
16 changes: 16 additions & 0 deletions .github/variables/prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"variables": [
{
"name": "deploymentSlotName",
"value": "stage"
},
{
"name": "resourceGroup",
"value": "rg-prod"
},
{
"name": "webAppName",
"value": "app-0a1b2c"
}
]
}
12 changes: 12 additions & 0 deletions .github/variables/qa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"variables": [
{
"name": "resourceGroup",
"value": "rg-qa"
},
{
"name": "webAppName",
"value": "app-0a1b2c-dev"
}
]
}
79 changes: 47 additions & 32 deletions .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ on:
pull_request:
branches: [main]

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:

# Build Application
Expand All @@ -32,10 +22,8 @@ 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
- name: Upload ARM Templates as Artifact
continue-on-error: false
Expand All @@ -44,7 +32,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
Expand All @@ -53,6 +40,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: .github/variables


# Deploy to the Development servers
DeployDev:
Expand All @@ -62,13 +57,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: fredcicles/github-actions/.github/actions/set-variables@samples/variable-files
with:
variableFileName: ./variables/dev

# Log in to Azure
- uses: azure/login@v1
Expand All @@ -80,15 +80,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
Expand All @@ -103,13 +103,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: fredcicles/github-actions/.github/actions/set-variables@samples/variable-files
with:
variableFileName: ./variables/qa

# Log in to Azure
- uses: azure/login@v1
Expand All @@ -121,15 +126,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
Expand All @@ -143,15 +148,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: fredcicles/github-actions/.github/actions/set-variables@samples/variable-files
with:
variableFileName: ./variables/prod

# Log in to Azure
- uses: azure/login@v1
Expand All @@ -163,15 +171,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

Expand All @@ -186,11 +194,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: fredcicles/github-actions/.github/actions/set-variables@samples/variable-files
with:
variableFileName: ./variables/prod

# Log in to Azure
- uses: azure/login@v1
Expand All @@ -202,4 +217,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 }}
2 changes: 1 addition & 1 deletion infra/azuredeploy.dev.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"value": "asp-0a1b2c-dev"
},
"webAppName": {
"value": "app-0a1b2c-dev"
"value": "web-app-dev"
}
}
}
2 changes: 1 addition & 1 deletion infra/azuredeploy.prod.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"value": "asp-0a1b2c"
},
"webAppName": {
"value": "app-0a1b2c"
"value": "web-app-prod"
}
}
}
2 changes: 1 addition & 1 deletion infra/azuredeploy.qa.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"value": "asp-0a1b2c-qa"
},
"webAppName": {
"value": "app-0a1b2c-qa"
"value": "web-app-qa"
}
}
}