-
Notifications
You must be signed in to change notification settings - Fork 1
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 logical improvements #11
Changes from all commits
44ff419
89725d9
04952d5
fa6afee
5766fc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 ] | ||
|
||
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 }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed unnecessary value. |
||
env: | ||
ARTIFACTS_FOLDER: ${{ github.workspace }}/Artifacts | ||
GITHUB_RUN_NUMBER: ${{ github.run_number }} | ||
|
@@ -23,7 +22,7 @@ jobs: | |
shell: pwsh | ||
run: | | ||
# Get default branch | ||
$repo = 'microsoft/OpenAPI.NET' | ||
$repo = "${{ github.repository }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace static value with more elegant dynamic value - |
||
$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)" | ||
|
||
|
@@ -33,11 +32,22 @@ jobs: | |
run: | | ||
$defaultBranch = "${{ steps.data_gatherer.outputs.default_branch }}" | ||
$githubRef = "${{ github.ref }}" | ||
$githubEventName = "${{ github.event_name }}" | ||
$isDefaultBranch = 'false' | ||
$isPush = 'false' | ||
$isPushToDefaultBranch = 'false' | ||
if ( $githubRef -like "*$defaultBranch*" ) { | ||
$isDefaultBranch = 'true' | ||
} | ||
if ( $githubEventName -eq 'push' ) { | ||
$isPush = 'true' | ||
} | ||
if ( $githubRef -like "*$defaultBranch*" -and $githubEventName -eq 'push' ) { | ||
$isPushToDefaultBranch = 'true' | ||
} | ||
Write-Output "::set-output name=is_default_branch::$(echo $isDefaultBranch)" | ||
Write-Output "::set-output name=is_push::$(echo $isPush)" | ||
Write-Output "::set-output name=is_push_to_default_branch::$(echo $isPushToDefaultBranch)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added two more conditional statements:
|
||
|
||
- name: Checkout repository | ||
id: checkout_repo | ||
|
@@ -46,7 +56,7 @@ jobs: | |
token: ${{ secrets.GITHUB_TOKEN }} | ||
fetch-depth: 0 | ||
|
||
- if: steps.conditionals_handler.outputs.is_default_branch == 'true' | ||
- if: steps.conditionals_handler.outputs.is_push_to_default_branch == 'true' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used the newly added |
||
name: Bump GH tag | ||
id: tag_generator | ||
uses: mathieudutour/github-tag-action@v5.4 | ||
|
@@ -59,41 +69,40 @@ jobs: | |
id: build_projects | ||
shell: pwsh | ||
run: | | ||
$projectsArray = @( | ||
'.\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj', | ||
'.\src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj', | ||
'.\src\Microsoft.OpenApi.Tool\Microsoft.OpenApi.Tool.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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add argument as best practice. (writing scripts in PowerShell is all cmdlets and arguments should be written and with their full name for optimal legibility) |
||
$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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace static array of project locations with a more elegant solution. |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add arguments as best practice. |
||
|
||
- 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/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced static array of test project locations with a more elegant solution. |
||
} | ||
|
||
- name: Upload test results as artifacts | ||
id: ul_testresults_artifact | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: TestResults | ||
path: TestResults/ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Upload test results as pipeline artifact. |
||
# - if: steps.tag_generator.outputs.new_version != '' | ||
# name: Upload NuGet packages as artifacts | ||
# id: ul_packages_artifact | ||
|
@@ -103,7 +112,7 @@ jobs: | |
# path: Artifacts/NuGet/ | ||
|
||
cd: | ||
if: needs.ci.outputs.is_default_branch == 'true' && needs.ci.outputs.latest_version != '' | ||
if: needs.ci.outputs.latest_version != '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
name: Continuous Deployment | ||
needs: ci | ||
runs-on: ubuntu-latest | ||
|
@@ -120,8 +129,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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add arguments as best practice |
||
# nuget push $PSItem.FullName ` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
# -ApiKey $env:NUGET_API_KEY ` | ||
# -Source https://api.nuget.org/v3/index.json | ||
# } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosmetic change for better visibility.