-
Notifications
You must be signed in to change notification settings - Fork 8
141 lines (125 loc) · 4.88 KB
/
ci-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: CI/CD Pipeline
on: [push, pull_request, workflow_dispatch]
jobs:
ci:
name: Continuous Integration
runs-on: ubuntu-latest
outputs:
latest_version: ${{ steps.tag_generator.outputs.new_version }}
is_default_branch: ${{ steps.conditionals_handler.outputs.is_default_branch }}
env:
ARTIFACTS_FOLDER: ${{ github.workspace }}/Artifacts
GITHUB_RUN_NUMBER: ${{ github.run_number }}
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Data gatherer
id: data_gatherer
shell: pwsh
run: |
# Get default branch
$repo = 'microsoftgraph/kibali'
$defaultBranch = Invoke-RestMethod -Method GET -Uri https://api.github.com/repos/$repo | Select-Object -ExpandProperty default_branch
Write-Output "::set-output name=default_branch::$(echo $defaultBranch)"
- name: Conditionals handler
id: conditionals_handler
shell: pwsh
run: |
$defaultBranch = "${{ steps.data_gatherer.outputs.default_branch }}"
$githubRef = "${{ github.ref }}"
$isDefaultBranch = 'false'
if ( $githubRef -like "*$defaultBranch*" ) {
$isDefaultBranch = 'true'
}
Write-Output "::set-output name=is_default_branch::$(echo $isDefaultBranch)"
- name: Checkout repository
id: checkout_repo
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
# - if: steps.conditionals_handler.outputs.is_default_branch == 'true'
# name: Bump GH tag
# id: tag_generator
# uses: mathieudutour/[email protected]
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# default_bump: false
# release_branches: ${{ steps.data_gatherer.outputs.default_branch }}
- name: Build projects
id: build_projects
shell: pwsh
run: |
$projectsArray = @(
'.\src\kibali\Kibali.csproj',
'.\src\kibali\KibaliTool.csproj',
'.\test\kibaliTests\KibaliTests.csproj'
)
$gitNewVersion = if ("${{ steps.tag_generator.outputs.new_version }}") {"${{ steps.tag_generator.outputs.new_version }}"} else {$null}
$projectCurrentVersion = ([xml](Get-Content .\src\kibali\Kibali.csproj)).Project.PropertyGroup.Version
$projectNewVersion = $gitNewVersion ?? $projectCurrentVersion
$projectsArray | ForEach-Object {
dotnet build $PSItem `
-c Release # `
# -o $env:ARTIFACTS_FOLDER `
# /p:Version=$projectNewVersion
}
# Move NuGet packages to separate folder for pipeline convenience
# New-Item Artifacts/NuGet -ItemType Directory
# Get-ChildItem Artifacts/*.nupkg | Move-Item -Destination "Artifacts/NuGet"
- name: Run unit tests
id: run_unit_tests
shell: pwsh
run: |
$testProjectsArray = @(
'.\test\kibaliTests\KibaliTests.csproj'
)
$testProjectsArray | ForEach-Object {
dotnet test $PSItem `
-c Release
}
# - if: steps.tag_generator.outputs.new_version != ''
# name: Upload NuGet packages as artifacts
# id: ul_packages_artifact
# uses: actions/upload-artifact@v1
# with:
# name: NuGet packages
# path: Artifacts/NuGet/
# cd:
# if: needs.ci.outputs.is_default_branch == 'true' && needs.ci.outputs.latest_version != ''
# name: Continuous Deployment
# needs: ci
# runs-on: ubuntu-latest
# steps:
# - name: Download and extract NuGet packages
# id: dl_packages_artifact
# uses: actions/download-artifact@v2
# with:
# name: NuGet packages
# path: NuGet/
# - name: Push NuGet packages to NuGet.org
# id: push_nuget_packages
# continue-on-error: true
# shell: pwsh
# run: |
# Get-ChildItem NuGet/*.nupkg | ForEach-Object {
# nuget push $PSItem `
# -ApiKey $env:NUGET_API_KEY `
# -Source https://api.nuget.org/v3/index.json
# }
# env:
# NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
# - name: Create and publish release
# id: create_release
# uses: softprops/action-gh-release@v1
# with:
# name: Kibali v${{ needs.ci.outputs.latest_version }}
# tag_name: v${{ needs.ci.outputs.latest_version }}
# # files: |
# # NuGet/Microsoft.OpenApi.${{ needs.ci.outputs.latest_version }}.nupkg
# # NuGet/Microsoft.OpenApi.Readers.${{ needs.ci.outputs.latest_version }}.nupkg
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Built with ❤ by [Pipeline Foundation](https://pipeline.foundation)