From 24d4e8aa6aa4a87448ef728901aafe0539143bc7 Mon Sep 17 00:00:00 2001 From: Dave Skender <8432125+DaveSkender@users.noreply.github.com> Date: Thu, 9 Nov 2023 11:32:47 -0500 Subject: [PATCH] chore: migrate build to GitHub Actions (#1112) --- .github/build.main.yml | 105 ----------------- .../{codeql.yml => build-codeql.yml} | 8 +- .github/workflows/build-examples.yml | 30 +++++ .github/workflows/build-indicators.yml | 80 +++++++++++++ .github/workflows/deploy-staging.yml | 109 ++++++++++++++++++ .../{a11y.yml => docs-test-a11y.yml} | 7 +- .../{links.yml => docs-test-links.yml} | 7 +- .vscode/settings.json | 6 +- Stock.Indicators.sln | 4 +- .../{external => other}/Convergence.Tests.cs | 0 .../CustomIndicator.Tests.cs | 0 tests/{external => other}/PublicApi.Tests.cs | 0 tests/{external => other}/Tests.Other.csproj | 0 13 files changed, 242 insertions(+), 114 deletions(-) delete mode 100644 .github/build.main.yml rename .github/workflows/{codeql.yml => build-codeql.yml} (90%) create mode 100644 .github/workflows/build-examples.yml create mode 100644 .github/workflows/build-indicators.yml create mode 100644 .github/workflows/deploy-staging.yml rename .github/workflows/{a11y.yml => docs-test-a11y.yml} (92%) rename .github/workflows/{links.yml => docs-test-links.yml} (94%) rename tests/{external => other}/Convergence.Tests.cs (100%) rename tests/{external => other}/CustomIndicator.Tests.cs (100%) rename tests/{external => other}/PublicApi.Tests.cs (100%) rename tests/{external => other}/Tests.Other.csproj (100%) diff --git a/.github/build.main.yml b/.github/build.main.yml deleted file mode 100644 index f82a1585d..000000000 --- a/.github/build.main.yml +++ /dev/null @@ -1,105 +0,0 @@ -trigger: - - main - -pr: - - main - -pool: - name: Azure Pipelines - vmImage: "ubuntu-latest" - -workspace: - clean: all - -variables: - BuildConfiguration: "Release" - -steps: - - task: gitversion/setup@0 - displayName: use GitVersion 5.x - inputs: - versionSpec: "5.x" - - - task: gitversion/execute@0 - displayName: get GitVersion - inputs: - useConfigFile: true - configFilePath: "gitversion.yml" - updateAssemblyInfo: true - - - task: UseDotNet@2 - displayName: "use .NET SDK 7.0.x" - inputs: - version: 7.0.x - includePreviewVersions: false - - - task: DotNetCoreCLI@2 - displayName: build - inputs: - command: "build" - projects: "**/*.csproj" - arguments: > - --configuration $(BuildConfiguration) - /p:Version=$(GitVersion.NuGetVersion) - /p:ContinuousIntegrationBuild=true - /warnaserror - - - task: DotNetCoreCLI@2 - displayName: "test indicators" - inputs: - command: test - testRunTitle: "Indicator Tests" - projects: "tests/indicators/Tests.Indicators.csproj" - arguments: > - --configuration $(BuildConfiguration) - --no-restore - --no-build - --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura - publishTestResults: true - - - task: DotNetCoreCLI@2 - displayName: "test external/other" - inputs: - command: test - testRunTitle: "External Tests" - projects: "tests/external/Tests.Other.csproj" - arguments: > - --configuration $(BuildConfiguration) - --no-restore - --no-build - /p:CollectCoverage=false - publishTestResults: true - - - task: PublishCodeCoverageResults@1 - displayName: "publish code coverage" - inputs: - codeCoverageTool: Cobertura - summaryFileLocation: "$(Agent.TempDirectory)/**/coverage.cobertura.xml" - - - task: DotNetCoreCLI@2 - displayName: "pack for NuGet" - inputs: - command: "pack" - packagesToPack: "src/Indicators.csproj" - nobuild: true - versioningScheme: "byEnvVar" - versionEnvVar: "GitVersion.NuGetVersion" - - - task: CopyFiles@2 - displayName: "stage artifacts" - inputs: - SourceFolder: "src" - Contents: | - "**/*.nupkg" - "**/*.snupkg" - TargetFolder: "$(Pipeline.Workspace)/a" - CleanTargetFolder: true - OverWrite: true - flattenFolders: true - - - task: PublishPipelineArtifact@1 - displayName: "save artifacts" - inputs: - targetPath: "$(Pipeline.Workspace)/a" - artifact: "packages" - publishLocation: "pipeline" diff --git a/.github/workflows/codeql.yml b/.github/workflows/build-codeql.yml similarity index 90% rename from .github/workflows/codeql.yml rename to .github/workflows/build-codeql.yml index 883da569c..506fda4b6 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/build-codeql.yml @@ -1,4 +1,5 @@ -name: "CodeQL" +name: "build" +run-name: Test CodeQL on: push: @@ -6,17 +7,20 @@ on: paths: - 'src/**' - 'tests/**' + pull_request: branches: ["main"] paths: - 'src/**' - 'tests/**' + - ".github/workflows/build-codeql.yml" + schedule: - cron: "16 12 * * 3" jobs: analyze: - name: analyze + name: CodeQL runs-on: ubuntu-latest permissions: actions: read diff --git a/.github/workflows/build-examples.yml b/.github/workflows/build-examples.yml new file mode 100644 index 000000000..0052caa5a --- /dev/null +++ b/.github/workflows/build-examples.yml @@ -0,0 +1,30 @@ +name: "build" +run-name: Build examples + +on: + push: + branches: ["main"] + paths: + - docs/examples/** + + pull_request: + branches: ["main"] + paths: + - docs/examples/** + - ".github/workflows/build-examples.yml" + +jobs: + build: + name: examples + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Build examples + run: > + dotnet build docs/examples/Examples.sln + --configuration Release + --property:ContinuousIntegrationBuild=true + -warnAsError diff --git a/.github/workflows/build-indicators.yml b/.github/workflows/build-indicators.yml new file mode 100644 index 000000000..bdbe2ad9d --- /dev/null +++ b/.github/workflows/build-indicators.yml @@ -0,0 +1,80 @@ +name: "build" +run-name: Test indicators + +on: + push: + branches: ["main"] + paths: + - "src/**" + + pull_request: + branches: ["main"] + paths: + - "src/**" + - ".github/workflows/build-indicators.yml" + +jobs: + + testing: + name: test indicators + runs-on: ubuntu-latest + + steps: + + - name: Clean workspace + run: | + rm -rf ./* || true + rm -rf ./.??* || true + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install .NET SDK + uses: actions/setup-dotnet@v3 + with: + dotnet-version: "7.x" + dotnet-quality: "ga" + + - name: Build solution + run: > + dotnet build + --configuration Release + --property:ContinuousIntegrationBuild=true + -warnAsError + + - name: Test indicators + run: > + dotnet test tests/indicators/Tests.Indicators.csproj + --configuration Release + --no-build + --verbosity normal + --logger trx + --collect:"XPlat Code Coverage" + --results-directory ./test-indicators + + - name: Test other items + run: > + dotnet test tests/other/Tests.Other.csproj + --configuration Release + --no-build + --verbosity normal + --logger trx + --results-directory ./test-other + + - name: Update tests summary + uses: bibipkins/dotnet-test-reporter@v1.3.3 + if: github.event_name == 'pull_request' + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + comment-title: "" + results-path: ./test-indicators/**/*.trx + coverage-path: ./test-indicators/**/coverage.cobertura.xml + coverage-type: cobertura + coverage-threshold: 95 + + - name: Save test results + uses: actions/upload-artifact@v3 + with: + name: test-results + path: ./test-indicators + if: ${{ always() }} \ No newline at end of file diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml new file mode 100644 index 000000000..0ee337e79 --- /dev/null +++ b/.github/workflows/deploy-staging.yml @@ -0,0 +1,109 @@ +name: "deploy" +run-name: Deploy to staging + +concurrency: + group: staging + cancel-in-progress: true + +on: [workflow_dispatch] + +jobs: + build: + runs-on: ubuntu-latest + outputs: + nuget-version: "${{ steps.gitversion.outputs.nuGetVersion }}" + filename-nupkg: "Skender.Stock.Indicators.${{ steps.gitversion.outputs.nuGetVersion }}.nupkg" + filename-snupkg: "Skender.Stock.Indicators.${{ steps.gitversion.outputs.nuGetVersion }}.snupkg" + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v0 + with: + versionSpec: "5.x" + preferLatestVersion: true + + - name: Determine version + id: gitversion + uses: gittools/actions/gitversion/execute@v0 + with: + updateAssemblyInfo: true + useConfigFile: true + configFilePath: gitversion.yml + + - name: Install .NET SDK + uses: actions/setup-dotnet@v3 + with: + dotnet-version: "7.x" + dotnet-quality: "ga" + + - name: Build library + run: > + dotnet build src/Indicators.csproj + --configuration Release + --property:Version=${{ steps.gitversion.outputs.nuGetVersion }} + --property:ContinuousIntegrationBuild=true + -warnAsError + + - name: Pack for NuGet + run: > + dotnet pack src/Indicators.csproj + --configuration Release + --no-build + --include-symbols + --output NuGet + -p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersion }} + + - name: Save NuGet package + uses: actions/upload-artifact@v3 + with: + name: packages + path: NuGet + + - name: Show version + run: | + { + echo "### Identified semantic version" + echo "| Variable | Value |" + echo "| --------------- | ----------------------------------------------- |" + echo "| Major | ${{ steps.gitversion.outputs.major }} |" + echo "| Minor | ${{ steps.gitversion.outputs.minor }} |" + echo "| Patch | ${{ steps.gitversion.outputs.patch }} |" + echo "| PreReleaseTag | ${{ steps.gitversion.outputs.preReleaseTag }} |" + echo "| MajorMinorPatch | ${{ steps.gitversion.outputs.majorMinorPatch }} |" + echo "| SemVer | ${{ steps.gitversion.outputs.semVer }} |" + echo "| NuGetVersion | ${{ steps.gitversion.outputs.nuGetVersion }} |" + } >> $GITHUB_STEP_SUMMARY + + deploy: + needs: build + runs-on: ubuntu-latest + + environment: + name: staging + url: "${{ vars.NUGET_DOWNLOAD_PREFIX }}${{ needs.build.outputs.nuget-version }}" + + steps: + - uses: actions/setup-dotnet@v3 + with: + source-url: ${{ vars.NUGET_PUBLISH_URL }} + env: + NUGET_AUTH_TOKEN: ${{secrets.NUGET_TOKEN}} + + - name: Download NuGet package + uses: actions/download-artifact@v3 + with: + name: packages + path: NuGet + + - name: Show publish preview + run: | + echo ${{ vars.NUGET_PUBLISH_URL }} + echo ${{ vars.NUGET_DOWNLOAD_PREFIX }} + echo "dotnet nuget push NuGet/*.nupkg" + echo ${{ needs.build.outputs.filename-nupkg }} + echo ${{ needs.build.outputs.filename-snupkg }} diff --git a/.github/workflows/a11y.yml b/.github/workflows/docs-test-a11y.yml similarity index 92% rename from .github/workflows/a11y.yml rename to .github/workflows/docs-test-a11y.yml index a54af08ac..3572f29cd 100644 --- a/.github/workflows/a11y.yml +++ b/.github/workflows/docs-test-a11y.yml @@ -1,16 +1,19 @@ -name: test docs +name: docs +run-name: Test doc site a11y + on: pull_request: branches: [main] paths: - 'docs/**' + - ".github/workflows/docs-test-a11y.yml" env: JEKYLL_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: testing: - name: a11y + name: test a11y runs-on: ubuntu-latest steps: diff --git a/.github/workflows/links.yml b/.github/workflows/docs-test-links.yml similarity index 94% rename from .github/workflows/links.yml rename to .github/workflows/docs-test-links.yml index da381e961..06d721fb2 100644 --- a/.github/workflows/links.yml +++ b/.github/workflows/docs-test-links.yml @@ -1,16 +1,19 @@ -name: test docs +name: docs +run-name: Test doc site URLs + on: pull_request: branches: [main] paths: - 'docs/**' + - ".github/workflows/docs-test-links.yml" env: JEKYLL_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: testing: - name: URLs + name: test URLs runs-on: ubuntu-latest steps: diff --git a/.vscode/settings.json b/.vscode/settings.json index f2081afa8..a42950c62 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -65,6 +65,7 @@ "FAMA", "forex", "Ginley", + "gittools", "Goichi", "gstatic", "Heikin", @@ -192,5 +193,8 @@ "pivottrend", "trendline", "webp" - ] + ], + "yaml.schemas": { + "https://json.schemastore.org/github-workflow.json": "file:///c%3A/Users/daves/Repos/Forks/Stock.Indicators/daveskender/.github/workflows/build.yml" + } } \ No newline at end of file diff --git a/Stock.Indicators.sln b/Stock.Indicators.sln index 77aa0aea6..0337bb528 100644 --- a/Stock.Indicators.sln +++ b/Stock.Indicators.sln @@ -15,14 +15,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Indicators", "src\Indicator EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Indicators", "tests\indicators\Tests.Indicators.csproj", "{11CD6C7E-871F-4903-AEAD-58E034C6521D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Other", "tests\external\Tests.Other.csproj", "{97905D26-4854-41FF-A4F7-CE042B2ACD02}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Other", "tests\other\Tests.Other.csproj", "{97905D26-4854-41FF-A4F7-CE042B2ACD02}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Performance", "tests\performance\Tests.Performance.csproj", "{3BD4837B-D197-41FD-A286-A3256D0770E1}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{3A4158F9-4165-4823-9526-0CFAACCF1ACC}" ProjectSection(SolutionItems) = preProject - .lgtm.yml = .lgtm.yml .github\build.main.yml = .github\build.main.yml + .github\workflows\build.yml = .github\workflows\build.yml .github\dependabot.yml = .github\dependabot.yml EndProjectSection EndProject diff --git a/tests/external/Convergence.Tests.cs b/tests/other/Convergence.Tests.cs similarity index 100% rename from tests/external/Convergence.Tests.cs rename to tests/other/Convergence.Tests.cs diff --git a/tests/external/CustomIndicator.Tests.cs b/tests/other/CustomIndicator.Tests.cs similarity index 100% rename from tests/external/CustomIndicator.Tests.cs rename to tests/other/CustomIndicator.Tests.cs diff --git a/tests/external/PublicApi.Tests.cs b/tests/other/PublicApi.Tests.cs similarity index 100% rename from tests/external/PublicApi.Tests.cs rename to tests/other/PublicApi.Tests.cs diff --git a/tests/external/Tests.Other.csproj b/tests/other/Tests.Other.csproj similarity index 100% rename from tests/external/Tests.Other.csproj rename to tests/other/Tests.Other.csproj