-
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
Add several syntactical, functional logical improvements #11
Conversation
@@ -1,14 +1,13 @@ | |||
name: CI/CD Pipeline | |||
|
|||
on: [push, pull_request, workflow_dispatch] | |||
on: [ push, pull_request, workflow_dispatch ] |
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.
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Removed unnecessary value.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Replace static value with more elegant dynamic value - ${{ github.repository }}
.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
added two more conditional statements:
is_push
= when the workflow is triggered by a push commitis_push_to_default_branch
= when the workflow is triggered by the a push commit in the default branch
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Used the newly added is_push_to_default_branch
condition, instead of the is_default_branch
, to further restrict the new tag generating step to only execute when a push commit to the default branch is made.
$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 comment
The 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)
# 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Add arguments as best practice.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced static array of test project locations with a more elegant solution.
Add test logger, which generates test results with normal verbosity in the root/TestResults/ folder.
with: | ||
name: TestResults | ||
path: TestResults/ | ||
|
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.
Upload test results as pipeline 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Removed is_default_branch
condition, because it is logically unnecessary, since the step that dictates if the other condition needs.ci.outputs.latest_version
is true or false, only executes when the workflow is triggered by a push commit in the default branch.
# Get-ChildItem NuGet/*.nupkg | ForEach-Object { | ||
# nuget push $PSItem ` | ||
# Get-ChildItem -Path NuGet/ -Filter *.nupkg | ForEach-Object { | ||
# nuget push $PSItem.FullName ` |
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.
Add .FullName
to ensure the command always takes the file path as value.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Add arguments as best practice
-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 comment
The reason will be displayed to describe this comment to others. Learn more.
Replace static array of project locations with a more elegant solution.
No description provided.