Skip to content

Commit a65052d

Browse files
committed
ci: restore per project approach
1 parent 451125d commit a65052d

1 file changed

Lines changed: 118 additions & 15 deletions

File tree

‎.github/workflows/ci-cd.yml‎

Lines changed: 118 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ name: CI/CD Pipeline
33
on: [push, pull_request, workflow_dispatch]
44

55
permissions:
6-
contents: read
6+
contents: write
77

88
jobs:
99
ci:
1010
name: Continuous Integration
1111
runs-on: ubuntu-latest
12+
outputs:
13+
latest_version: ${{ steps.tag_generator.outputs.new_version }}
14+
is_default_branch: ${{ steps.conditionals_handler.outputs.is_default_branch }}
1215
env:
1316
ARTIFACTS_FOLDER: ${{ github.workspace }}/Artifacts
1417
GITHUB_RUN_NUMBER: ${{ github.run_number }}
@@ -23,43 +26,143 @@ jobs:
2326
with:
2427
dotnet-version: 10.0.x
2528

29+
- name: Data gatherer
30+
id: data_gatherer
31+
shell: pwsh
32+
run: |
33+
# Get default branch
34+
$repo = 'microsoft/OpenAPI.NET.OData'
35+
$defaultBranch = Invoke-RestMethod -Method GET -Uri https://api.github.com/repos/$repo | Select-Object -ExpandProperty default_branch
36+
Write-Output "default_branch=$(echo $defaultBranch) >> $GITHUB_OUTPUT"
37+
38+
- name: Conditionals handler
39+
id: conditionals_handler
40+
shell: pwsh
41+
run: |
42+
$defaultBranch = "${{ steps.data_gatherer.outputs.default_branch }}"
43+
$githubRef = "${{ github.ref }}"
44+
$isDefaultBranch = 'false'
45+
if ( $githubRef -like "*$defaultBranch*" ) {
46+
$isDefaultBranch = 'true'
47+
}
48+
Write-Output "is_default_branch=$(echo $isDefaultBranch) >> $GITHUB_OUTPUT"
49+
2650
- name: Checkout repository
2751
id: checkout_repo
2852
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2953
with:
3054
token: ${{ secrets.GITHUB_TOKEN }}
3155
fetch-depth: 0
3256

57+
- if: steps.conditionals_handler.outputs.is_default_branch == 'true'
58+
name: Bump GH tag
59+
id: tag_generator
60+
uses: mathieudutour/github-tag-action@a22cf08638b34d5badda920f9daf6e72c477b07b # v6.2
61+
with:
62+
github_token: ${{ secrets.GITHUB_TOKEN }}
63+
default_bump: false
64+
release_branches: ${{ steps.data_gatherer.outputs.default_branch }}
65+
3366
- name: Build projects
3467
id: build_projects
3568
shell: pwsh
3669
run: |
37-
dotnet build .\Microsoft.OpenApi.OData.sln -c Release
70+
$projectsArray = @(
71+
'./src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj',
72+
'./src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj'
73+
)
74+
$gitNewVersion = if ("${{ steps.tag_generator.outputs.new_version }}") {"${{ steps.tag_generator.outputs.new_version }}"} else {$null}
75+
$projectCurrentVersion = ([xml](Get-Content ./src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj)).Project.PropertyGroup.Version
76+
$projectNewVersion = $gitNewVersion ?? $projectCurrentVersion
77+
78+
$projectsArray | ForEach-Object {
79+
dotnet build $PSItem `
80+
-c Release # `
81+
# -o $env:ARTIFACTS_FOLDER `
82+
# /p:Version=$projectNewVersion
83+
}
3884
39-
- name: Run OData unit tests
40-
id: run_odata_unit_tests
85+
# Move NuGet packages to separate folder for pipeline convenience
86+
# New-Item Artifacts/NuGet -ItemType Directory
87+
# Get-ChildItem Artifacts/*.nupkg | Move-Item -Destination "Artifacts/NuGet"
88+
89+
- name: Run unit tests
90+
id: run_unit_tests
4191
shell: pwsh
4292
run: |
43-
dotnet test .\test\Microsoft.OpenAPI.OData.Reader.Tests\Microsoft.OpenAPI.OData.Reader.Tests.csproj -c Release --no-build
93+
$testProjectsArray = @(
94+
'./test/Microsoft.OpenAPI.OData.Reader.Tests/Microsoft.OpenAPI.OData.Reader.Tests.csproj'
95+
)
96+
97+
$testProjectsArray | ForEach-Object {
98+
dotnet test $PSItem `
99+
-c Release
100+
}
44101
45102
- name: Run Hidi unit tests
46103
id: run_hidi_unit_tests
47104
working-directory: test/Microsoft.OpenApi.Hidi.Tests
48105
shell: pwsh
49106
run: |
50-
dotnet test -c Release --no-build
107+
dotnet test -c Release
51108
52109
- name: Smoke test Hidi package
53110
shell: pwsh
54111
run: |
55-
$hidiVersion = ([xml](Get-Content .\src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj)).Project.PropertyGroup.Version
56-
$inputDocument = '.\test\Microsoft.OpenApi.Hidi.Tests\UtilityFiles\SampleOpenApi.yml'
57-
dotnet pack .\src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj -c Release --no-build -o .\Artifacts
58-
dotnet tool install --tool-path .\.hidi-smoke --source .\Artifacts --version $hidiVersion Microsoft.OpenApi.Hidi
59-
.\.hidi-smoke\hidi --help
60-
.\.hidi-smoke\hidi validate --openapi $inputDocument
61-
.\.hidi-smoke\hidi transform --openapi $inputDocument --output .\Artifacts\transformed.json --format json --version 3.0 --clean-output
62-
.\.hidi-smoke\hidi show --openapi $inputDocument --output .\Artifacts\paths.txt --clean-output
63-
.\.hidi-smoke\hidi plugin --help
112+
$hidiVersion = ([xml](Get-Content ./src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj)).Project.PropertyGroup.Version
113+
$inputDocument = './test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/SampleOpenApi.yml'
114+
dotnet pack ./src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj -c Release --no-build -o ./Artifacts
115+
dotnet tool install --tool-path ./.hidi-smoke --source ./Artifacts --version $hidiVersion Microsoft.OpenApi.Hidi
116+
./.hidi-smoke/hidi --help
117+
./.hidi-smoke/hidi validate --openapi $inputDocument
118+
./.hidi-smoke/hidi transform --openapi $inputDocument --output ./Artifacts/transformed.json --format json --version 3.0 --clean-output
119+
./.hidi-smoke/hidi show --openapi $inputDocument --output ./Artifacts/paths.txt --clean-output
120+
./.hidi-smoke/hidi plugin --help
121+
122+
# - if: steps.tag_generator.outputs.new_version != ''
123+
# name: Upload NuGet packages as artifacts
124+
# id: ul_packages_artifact
125+
# uses: actions/upload-artifact@v1
126+
# with:
127+
# name: NuGet packages
128+
# path: Artifacts/NuGet/
129+
130+
cd:
131+
if: needs.ci.outputs.is_default_branch == 'true' && needs.ci.outputs.latest_version != ''
132+
name: Continuous Deployment
133+
needs: ci
134+
runs-on: ubuntu-latest
135+
steps:
136+
# - name: Download and extract NuGet packages
137+
# id: dl_packages_artifact
138+
# uses: actions/download-artifact@v2
139+
# with:
140+
# name: NuGet packages
141+
# path: NuGet/
142+
143+
# - name: Push NuGet packages to NuGet.org
144+
# id: push_nuget_packages
145+
# continue-on-error: true
146+
# shell: pwsh
147+
# run: |
148+
# Get-ChildItem NuGet/*.nupkg | ForEach-Object {
149+
# nuget push $PSItem `
150+
# -ApiKey $env:NUGET_API_KEY `
151+
# -Source https://api.nuget.org/v3/index.json
152+
# }
153+
# env:
154+
# NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
155+
156+
- name: Create and publish release
157+
id: create_release
158+
uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3
159+
with:
160+
name: OpenAPI.Net.OData v${{ needs.ci.outputs.latest_version }}
161+
tag_name: v${{ needs.ci.outputs.latest_version }}
162+
# files: |
163+
# NuGet/Microsoft.OpenApi.${{ needs.ci.outputs.latest_version }}.nupkg
164+
# NuGet/Microsoft.OpenApi.Readers.${{ needs.ci.outputs.latest_version }}.nupkg
165+
env:
166+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64167

65168
# Built with ❤ by [Pipeline Foundation](https://pipeline.foundation)

0 commit comments

Comments
 (0)