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 logical improvements #11

Conversation

aleks-ivanov
Copy link
Collaborator

No description provided.

@@ -1,14 +1,13 @@
name: CI/CD Pipeline

on: [push, pull_request, workflow_dispatch]
on: [ push, pull_request, workflow_dispatch ]
Copy link
Collaborator Author

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 }}
Copy link
Collaborator 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.

Removed unnecessary value.

@@ -23,7 +22,7 @@ jobs:
shell: pwsh
run: |
# Get default branch
$repo = 'microsoft/OpenAPI.NET'
$repo = "${{ github.repository }}"
Copy link
Collaborator 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.

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)"
Copy link
Collaborator 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.

added two more conditional statements:

  1. is_push = when the workflow is triggered by a push commit
  2. is_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'
Copy link
Collaborator 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.

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
Copy link
Collaborator 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.

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
Copy link
Collaborator 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.

Add arguments as best practice.

dotnet test $PSItem.FullName `
--configuration Release `
--logger "trx;LogFileName=$fileBaseName.trx;verbosity=normal" `
--results-directory TestResults/
Copy link
Collaborator 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 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/

Copy link
Collaborator Author

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 != ''
Copy link
Collaborator Author

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 `
Copy link
Collaborator Author

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 {
Copy link
Collaborator 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.

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 {
Copy link
Collaborator Author

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.

@aleks-ivanov aleks-ivanov merged commit 91e27bd into pipeline-foundation:feature/improve-ci-cd May 20, 2021
@aleks-ivanov aleks-ivanov deleted the feature/improve-ci-cd branch June 21, 2021 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant