Skip to content

Commit 5e0ea48

Browse files
committed
Initial version
0 parents  commit 5e0ea48

File tree

116 files changed

+7786
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+7786
-0
lines changed

.github/workflows/ci.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-test:
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
actions: write
14+
checks: write
15+
16+
name: Build and Test
17+
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: 'Checkout'
21+
uses: actions/checkout@v3
22+
23+
- name: Setup DotNet
24+
uses: actions/setup-dotnet@v3
25+
with:
26+
global-json-file: global.json
27+
28+
- name: Restore dependencies
29+
run: dotnet restore src/GitHubActions.Gates.Samples.sln
30+
31+
- name: Build
32+
run: dotnet build src/GitHubActions.Gates.Samples.sln --no-restore /p:TreatWarningsAsErrors=true
33+
34+
- name: Unit Tests
35+
run: dotnet test src/GitHubActions.Gates.Samples.sln --no-build --verbosity normal --logger:"junit;LogFilePath=unit-tests.xml" --collect:"XPlat Code Coverage" --results-directory ./coverage
36+
37+
- name: Publish Unit Test Results
38+
uses: EnricoMi/publish-unit-test-result-action@v2
39+
if: always() && github.actor != 'dependabot[bot]'
40+
with:
41+
github_token: ${{ secrets.GITHUB_TOKEN }}
42+
check_name: Tests Results
43+
files: '**/unit-tests.xml'
44+
report_individual_runs: true
45+
deduplicate_classes_by_file_name: false
46+
47+
- name: Merge coverage reports
48+
run: |
49+
dotnet tool install --global dotnet-coverage
50+
cd coverage
51+
dotnet-coverage merge -o ${{github.workspace}}/coverage/coverage-merged.xml -f cobertura -r coverage.cobertura.xml
52+
53+
- name: Code Coverage Summary Report
54+
uses: irongut/[email protected]
55+
if: always() && github.actor != 'dependabot[bot]'
56+
with:
57+
filename: coverage/coverage-merged.xml
58+
badge: true
59+
format: 'markdown'
60+
output: 'both'
61+
62+
- name: Add code coverage to summary
63+
if: always() && github.actor != 'dependabot[bot]'
64+
run: |
65+
echo "## Code Coverage Summary" >> $GITHUB_STEP_SUMMARY
66+
cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
67+
68+
- name: Add Coverage PR Comment
69+
uses: marocchino/sticky-pull-request-comment@v2
70+
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'
71+
with:
72+
recreate: true
73+
path: code-coverage-results.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Deploy-DeployHours-Gate
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types: [published]
7+
8+
permissions:
9+
contents: read
10+
id-token: write
11+
12+
jobs:
13+
build-and-deploy:
14+
name: Build and Deploy
15+
uses: ./.github/workflows/deploy-reusable.yml
16+
with:
17+
gate-project-folder: 'DeployHours.Gate'
18+
function-name: ${{ vars.DEPLOYHOURS_GATE_APP_NAME }}
19+
function-version: ${{ github.event.release.name }}
20+
client-id: ${{ vars.DEPLOYHOURS_GATE_CLIENT_ID }}
21+
secrets:
22+
tenant-id: ${{ secrets.DEPLOYHOURS_GATE_TENANT_ID }}
23+
subscription-id: ${{ secrets.DEPLOYHOURS_GATE_SUBSCRIPTION_ID }}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Deploy-Issues Gate
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types: [published]
7+
8+
permissions:
9+
contents: read
10+
id-token: write
11+
12+
jobs:
13+
build-and-deploy:
14+
name: Build and Deploy
15+
uses: ./.github/workflows/deploy-reusable.yml
16+
with:
17+
gate-project-folder: 'Issues.Gate'
18+
function-name: ${{ vars.ISSUES_GATE_APP_NAME }}
19+
function-version: ${{ github.event.release.name }}
20+
client-id: ${{ vars.ISSUES_GATE_CLIENT_ID }}
21+
secrets:
22+
tenant-id: ${{ secrets.ISSUES_GATE_TENANT_ID }}
23+
subscription-id: ${{ secrets.ISSUES_GATE_SUBSCRIPTION_ID }}

.github/workflows/deploy-reusable.yml

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Deploy Gate (Reusable)
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
function-name:
7+
description: 'The function name to deploy the app to'
8+
required: true
9+
type: string
10+
gate-project-folder:
11+
description: 'The folder where the gate project is located (in the src folder) Eg: DeployHours.Gate'
12+
required: true
13+
type: string
14+
function-version:
15+
description: 'The version of the function to deploy'
16+
required: false
17+
type: string
18+
default: '${{ github.repository }}-${{ github.sha }}'
19+
client-id:
20+
description: 'The client id of the service principal to use for deployment'
21+
required: true
22+
type: string
23+
secrets:
24+
tenant-id:
25+
description: 'The tenant id of the service principal to use for deployment'
26+
required: true
27+
subscription-id:
28+
description: 'The subscription id of the service principal to use for deployment'
29+
required: true
30+
31+
env:
32+
CONFIGURATION: Release
33+
FUNCTION_APP_NAME: '${{ inputs.function-name }}'
34+
AZURE_FUNCTIONAPP_PACKAGE_PATH: src/${{ inputs.gate-project-folder}}/published
35+
WORKING_DIRECTORY: src/${{ inputs.gate-project-folder}}
36+
37+
jobs:
38+
build-and-deploy:
39+
permissions:
40+
contents: read
41+
id-token: write
42+
43+
name: Build and Deploy
44+
45+
environment:
46+
name: Prod-${{ inputs.function-name}}
47+
url: ${{ steps.deployFunction.outputs.app-url }}
48+
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: 'Checkout'
52+
uses: actions/checkout@v3
53+
54+
- name: Setup DotNet
55+
uses: actions/setup-dotnet@v2
56+
with:
57+
global-json-file: global.json
58+
59+
- name: Restore
60+
run: dotnet restore "${{ env.WORKING_DIRECTORY }}"
61+
- name: Build
62+
run: |
63+
version=${{ inputs.function-version }}
64+
if [ -z "$version" ]; then
65+
version="${{ github.repository }}-${{ github.sha }}"
66+
fi
67+
echo "building version $version"
68+
dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore /p:InformationalVersion="$version"
69+
- name: Publish
70+
run: |
71+
dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}"
72+
73+
- name: Login to azure
74+
uses: azure/login@v1
75+
with:
76+
client-id: ${{ inputs.client-id }}
77+
tenant-id: ${{ secrets.tenant-id }}
78+
subscription-id: ${{ secrets.subscription-id }}
79+
80+
# The next 2 steps are a workaround for:
81+
# https://github.com/Azure/functions-action/issues/116
82+
- name: Get ${{ env.FUNCTION_APP_NAME }} Id
83+
id: getFunctionID
84+
run: |
85+
functionId=$(az resource list --resource-type Microsoft.Web/sites --query "[?kind=='functionapp' && name=='${{ env.FUNCTION_APP_NAME }}']|[0].id" --output tsv)
86+
if [ -z "$functionId" ]; then
87+
echo "Function App ${{ env.FUNCTION_APP_NAME }} not found"
88+
echo "These are the available resources to the service principal:"
89+
az resource list
90+
exit 1
91+
fi
92+
echo "functionId=$functionId" >> $GITHUB_OUTPUT
93+
- name: Retrieve publish profile for deployment
94+
id: getPublishProfile
95+
run: |
96+
functionId="${{ steps.getFunctionID.outputs.functionId }}"
97+
echo "getting publish profile for $functionId"
98+
publishProfiles=$(az webapp deployment list-publishing-profiles --ids "$functionId" --xml)
99+
echo "::add-mask::$publishProfiles"
100+
echo "publishProfiles<<EOF" >> $GITHUB_OUTPUT
101+
echo "$publishProfiles" >> $GITHUB_OUTPUT
102+
echo "EOF" >> $GITHUB_OUTPUT
103+
cat $GITHUB_OUTPUT
104+
105+
- name: Deploy Function ${{ env.FUNCTION_APP_NAME }}
106+
uses: Azure/functions-action@v1
107+
id: deployFunction
108+
with:
109+
publish-profile: ${{ steps.getPublishProfile.outputs.publishProfiles }}
110+
app-name: ${{ env.FUNCTION_APP_NAME }}
111+
package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
112+

0 commit comments

Comments
 (0)