Skip to content
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f919d99
run build and tests
aleks-ivanov Apr 12, 2021
a9a119c
create all artifacts and move them
aleks-ivanov Apr 12, 2021
97dd94c
test dotnet build cmdlet
aleks-ivanov Apr 12, 2021
0b3de5e
test dotnet build cmdlet
aleks-ivanov Apr 12, 2021
56c8624
test pl on ubuntu
aleks-ivanov Apr 12, 2021
577ec96
test pl on ubuntu
aleks-ivanov Apr 12, 2021
48a1860
improve build script
aleks-ivanov Apr 12, 2021
7154ea3
test nuget push
aleks-ivanov Apr 12, 2021
3cd23e7
add CD job
aleks-ivanov Apr 12, 2021
8617f1e
add CD job
aleks-ivanov Apr 12, 2021
15a1d7d
add CD job
aleks-ivanov Apr 12, 2021
ba7178f
add create release
aleks-ivanov Apr 12, 2021
5a9f6af
feat: add automatic versioning
aleks-ivanov Apr 12, 2021
2967818
fix: add automatic versioning
aleks-ivanov Apr 12, 2021
8895eb3
fix: add automatic versioning
aleks-ivanov Apr 12, 2021
47f6365
Feature/ci cd (#10)
aleks-ivanov Apr 12, 2021
09bc3a9
fix: add automatic versioning
aleks-ivanov Apr 12, 2021
e941de9
Merge branch 'vnext' into feature/ci-cd
aleks-ivanov Apr 12, 2021
4cc50c9
fix: add automatic versioning
aleks-ivanov Apr 12, 2021
f8af653
Merge branch 'feature/ci-cd' of https://github.com/aleks-ivanov/OpenA…
aleks-ivanov Apr 12, 2021
e04b950
test autoversion
aleks-ivanov Apr 12, 2021
be76dfa
revert autoversion
aleks-ivanov Apr 12, 2021
386ba2b
finish autoversioning
aleks-ivanov Apr 12, 2021
d306074
add conditionals to autoversioning and CD
aleks-ivanov Apr 13, 2021
7499bfb
check default branch and apply to conditionals
aleks-ivanov Apr 13, 2021
77bc430
add conditionals handler
aleks-ivanov Apr 13, 2021
ded0868
add conditionals handler
aleks-ivanov Apr 13, 2021
13654f1
add conditionals handler
aleks-ivanov Apr 13, 2021
fab202e
Merge branch 'vnext' of https://github.com/aleks-ivanov/OpenAPI.NET i…
aleks-ivanov Apr 13, 2021
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
162 changes: 162 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
name: OpenAPI.NET 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 }}
env:
ARTIFACTS_FOLDER: ${{ github.workspace }}/Artifacts
GITHUB_RUN_NUMBER: ${{ github.run_number }}
steps:
- name: Conditionals handler
id: conditionals_handler
shell: pwsh
run: |
$defaultBranch = 'vnext'
$githubRef = "${{ github.ref }}"
$isDefaultBranch = 'false'
if ( $githubRef -like "*$defaultBranch*" ) {
$isDefaultBranch = 'true'
}
Write-Output "::set-output name=is_default_branch::$(echo $isDefaultBranch)"

- name: Data gatherer
id: data_gatherer
shell: pwsh
run: |
# Get default branch
$repo = 'microsoft/OpenAPI.NET'
$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: Checkout repository
id: checkout_repo
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- if: steps.step_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: |
$newVersion = "${{ steps.tag_generator.outputs.new_version }}"
$projectsArray = @(
'.\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj',
'.\src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj',
'.\src\Microsoft.OpenApi.Tool\Microsoft.OpenApi.Tool.csproj'
)

if ($newVersion) {
$projectsArray | ForEach-Object {
dotnet build $PSItem `
-c Release `
-o $env:ARTIFACTS_FOLDER `
/p:Version=$newVersion
}
}
else {
$projectsArray | ForEach-Object {
dotnet build $PSItem `
-c Release `
-o $env:ARTIFACTS_FOLDER
}
}

# 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\Microsoft.OpenApi.Tests\Microsoft.OpenApi.Tests.csproj',
'.\test\Microsoft.OpenApi.Readers.Tests\Microsoft.OpenApi.Readers.Tests.csproj',
'.\test\Microsoft.OpenApi.SmokeTests\Microsoft.OpenApi.SmokeTests.csproj'
)

$testProjectsArray | ForEach-Object {
dotnet test $PSItem `
-c Release
}

- name: Upload NuGet packages as artifacts
id: ul_packages_artifact
uses: actions/upload-artifact@v1
with:
name: NuGet packages
path: Artifacts/NuGet/

cd:
if: github.ref == 'refs/heads/vnext' && 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: actions/create-release@v1
with:
tag_name: v${{ needs.ci.outputs.latest_version }}
release_name: OpenApi v${{ needs.ci.outputs.latest_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload OpenAPI package as release asset
id: upload_openapi_pckg
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: NuGet/Microsoft.OpenApi.${{ needs.ci.outputs.latest_version }}.nupkg
asset_name: Microsoft.OpenApi.${{ needs.ci.outputs.latest_version }}.nupkg
asset_content_type: application/zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload OpenAPI.Readers package as release asset
id: upload_openapi_readers_pckg
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: NuGet/Microsoft.OpenApi.Readers.${{ needs.ci.outputs.latest_version }}.nupkg
asset_name: Microsoft.OpenApi.Readers.${{ needs.ci.outputs.latest_version }}.nupkg
asset_content_type: application/zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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