From 91e27bdac2a216e0c0ba67a3817189fc131befe8 Mon Sep 17 00:00:00 2001 From: Aleksandar Ivanov <74899441+aleks-ivanov@users.noreply.github.com> Date: Thu, 20 May 2021 16:17:28 +0300 Subject: [PATCH 1/3] Add several syntactical, functional and logical improvements (#11) * add several improvements and simplifications * add a few script improvements * add tests logger and upload results as artifact * add path to source project files search in build step * add path to project files search in test step --- .github/workflows/ci-cd.yml | 67 +++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 4ab9ed7c3..8ec8f920e 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -1,6 +1,6 @@ name: CI/CD Pipeline -on: [push, pull_request, workflow_dispatch] +on: [ push, pull_request, workflow_dispatch ] jobs: ci: @@ -8,7 +8,6 @@ jobs: runs-on: ubuntu-latest outputs: latest_version: ${{ steps.tag_generator.outputs.new_version }} - is_default_branch: ${{ steps.conditionals_handler.outputs.is_default_branch }} 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 }}" $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)" - 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' 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 $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 { + 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 - 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/ } + - name: Upload test results as artifacts + id: ul_testresults_artifact + uses: actions/upload-artifact@v1 + with: + name: TestResults + path: TestResults/ + # - 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 != '' 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 { + # nuget push $PSItem.FullName ` # -ApiKey $env:NUGET_API_KEY ` # -Source https://api.nuget.org/v3/index.json # } From 97b2a50fceb1ea119f7d9ae4226dc4a746b858b0 Mon Sep 17 00:00:00 2001 From: Aleksandar Ivanov <74899441+aleks-ivanov@users.noreply.github.com> Date: Mon, 21 Jun 2021 15:03:48 +0300 Subject: [PATCH 2/3] Replace release action with GH CLI (#17) --- .github/workflows/ci-cd.yml | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 8ec8f920e..44bc55244 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -117,6 +117,13 @@ jobs: 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 @@ -139,14 +146,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) \ No newline at end of file From 7f9e6b89f58e066e2a3d8f839e7bf87ed7924688 Mon Sep 17 00:00:00 2001 From: Aleksandar Ivanov <74899441+aleks-ivanov@users.noreply.github.com> Date: Mon, 28 Jun 2021 18:46:17 +0300 Subject: [PATCH 3/3] switch release branch to master (#19) --- .github/workflows/ci-cd.yml | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 44bc55244..5cb12e734 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -17,38 +17,6 @@ jobs: with: dotnet-version: 5.0.x - - name: Data gatherer - id: data_gatherer - shell: pwsh - run: | - # Get default branch - $repo = "${{ github.repository }}" - $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 }}" - $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)" - - name: Checkout repository id: checkout_repo uses: actions/checkout@v2 @@ -56,14 +24,14 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} fetch-depth: 0 - - if: steps.conditionals_handler.outputs.is_push_to_default_branch == 'true' + - if: github.event_name == 'push' && github.ref == 'refs/heads/master' name: Bump GH tag id: tag_generator uses: mathieudutour/github-tag-action@v5.4 with: github_token: ${{ secrets.GITHUB_TOKEN }} default_bump: false - release_branches: ${{ steps.data_gatherer.outputs.default_branch }} + release_branches: master - name: Build projects id: build_projects