Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add several syntactical, functional and logic improvements (#11) #595

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
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
100 changes: 42 additions & 58 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: CI/CD Pipeline

on: [push, pull_request, workflow_dispatch]
on: [ push, pull_request, workflow_dispatch ]
darrelmiller marked this conversation as resolved.
Show resolved Hide resolved

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 }}
darrelmiller marked this conversation as resolved.
Show resolved Hide resolved
env:
ARTIFACTS_FOLDER: ${{ github.workspace }}/Artifacts
GITHUB_RUN_NUMBER: ${{ github.run_number }}
Expand All @@ -18,82 +17,60 @@ jobs:
with:
dotnet-version: 6.0.x

- 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: 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@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- if: steps.conditionals_handler.outputs.is_default_branch == 'true'
- if: github.event_name == 'push' && github.ref == 'refs/heads/master'
baywet marked this conversation as resolved.
Show resolved Hide resolved
name: Bump GH tag
id: tag_generator
uses: mathieudutour/github-tag-action@v6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: false
release_branches: ${{ steps.data_gatherer.outputs.default_branch }}
release_branches: master
baywet marked this conversation as resolved.
Show resolved Hide resolved

- name: Build projects
id: build_projects
shell: pwsh
run: |
$projectsArray = @(
'.\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj',
'.\src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj',
'.\src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj'
)
$gitNewVersion = if ("${{ steps.tag_generator.outputs.new_version }}") {"${{ steps.tag_generator.outputs.new_version }}"} else {$null}
$projectCurrentVersion = ([xml](Get-Content .\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj)).Project.PropertyGroup.Version
$projectCurrentVersion = ([xml](Get-Content -Path .\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj)).Project.PropertyGroup.Version
darrelmiller marked this conversation as resolved.
Show resolved Hide resolved
$projectNewVersion = $gitNewVersion ?? $projectCurrentVersion

$projectsArray | ForEach-Object {
dotnet build $PSItem `
-c Release # `
# -o $env:ARTIFACTS_FOLDER `
# /p:Version=$projectNewVersion
Get-ChildItem -Path src/ -Filter *.csproj -Exclude *Workbench* -File -Recurse | ForEach-Object {
Copy link
Contributor Author

@aleks-ivanov aleks-ivanov May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced static array of project locations with a more elegant solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, any reason why you don't simply target the sln?

Copy link
Contributor Author

@aleks-ivanov aleks-ivanov May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just took the build.cmd file as an example and just never gave it a second thought, but now that you mention it unless there is a specific reason not to, we could change the build step to building only the solution instead 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't publish the Workbench tool, so I didn't bother building it for publishing nugets. I don't have a problem building it as part of the pipeline. However currently dotnet build can't build the Workbench project because of some error about the GenerateResource task. Not sure what that is about.

dotnet build $PSItem.FullName `
--configuration Release # `
# --output $env:ARTIFACTS_FOLDER `
# -property: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"
# New-Item -Name Artifacts/NuGet -ItemType Directory
# Get-ChildItem -Path Artifacts/ -Filter *.nupkg | Move-Item -Destination Artifacts/NuGet
darrelmiller marked this conversation as resolved.
Show resolved Hide resolved

- 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
Get-ChildItem -Path test/ -Filter *.csproj -File -Recurse | ForEach-Object {
$fileBaseName = $PSItem.Basename
dotnet test $PSItem.FullName `
--configuration Release `
--logger "trx;LogFileName=$fileBaseName.trx;verbosity=normal" `
--results-directory TestResults/
darrelmiller marked this conversation as resolved.
Show resolved Hide resolved
}

- name: Upload test results as artifacts
id: ul_testresults_artifact
uses: actions/upload-artifact@v1
with:
name: TestResults
path: TestResults/

darrelmiller marked this conversation as resolved.
Show resolved Hide resolved
# - if: steps.tag_generator.outputs.new_version != ''
# name: Upload NuGet packages as artifacts
# id: ul_packages_artifact
Expand All @@ -103,11 +80,18 @@ jobs:
# path: Artifacts/NuGet/

cd:
if: needs.ci.outputs.is_default_branch == 'true' && needs.ci.outputs.latest_version != ''
if: needs.ci.outputs.latest_version != ''
darrelmiller marked this conversation as resolved.
Show resolved Hide resolved
name: Continuous Deployment
needs: ci
runs-on: ubuntu-latest
steps:
- name: Checkout repository
id: checkout_repo
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

# - name: Download and extract NuGet packages
# id: dl_packages_artifact
# uses: actions/download-artifact@v2
Expand All @@ -120,8 +104,8 @@ jobs:
# continue-on-error: true
# shell: pwsh
# run: |
# Get-ChildItem NuGet/*.nupkg | ForEach-Object {
# nuget push $PSItem `
# Get-ChildItem -Path NuGet/ -Filter *.nupkg | ForEach-Object {
darrelmiller marked this conversation as resolved.
Show resolved Hide resolved
# nuget push $PSItem.FullName `
darrelmiller marked this conversation as resolved.
Show resolved Hide resolved
# -ApiKey $env:NUGET_API_KEY `
# -Source https://api.nuget.org/v3/index.json
# }
Expand All @@ -130,14 +114,14 @@ jobs:

- name: Create and publish release
id: create_release
uses: softprops/action-gh-release@v1
with:
name: OpenApi 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
shell: pwsh
run: |
$releaseTag = "v${{ needs.ci.outputs.latest_version }}"
$releaseTitle = "OpenApi v${{ needs.ci.outputs.latest_version }}"
# $releaseAssets = 'NuGet/Microsoft.OpenApi.${{ needs.ci.outputs.latest_version }}.nupkg', 'NuGet/Microsoft.OpenApi.Readers.${{ needs.ci.outputs.latest_version }}.nupkg'

gh release create $releaseTag -t $releaseTitle $releaseAssets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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