From 5491bbb58a910c0d1e185ccd08b603612a06ab9d Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 5 Jun 2024 09:41:04 +0200 Subject: [PATCH] Merge specialized PR workflows back into one configuration file (#2363) * Attempt to simply docs only CI runs * fix embedded yaml hopefully * fix embedded yaml strings * fix variable subs * fix output check * use output * no negate * jobs => needs * see if negate works * remove -docs for test-linux * format should need changeset * make heavy integration tests dependend on unit tests * undo negate again * Move windows over to new checks * pass secret explicitly since composite cannot inherit * remove echo * format needs to run on windows * re-enable IIS and make it docs aware as well * remove echo * Apply suggestions from code review Co-authored-by: Victor Martinez * separate unit and integrations, since integrations currently has a rogue wait causing mayhem * revert back to -docs.yml to follow established company wide patterns * remove changeset composite action * merge -iis and -windows * fix yml indentation * Update .github/workflows/test-windows.yml Co-authored-by: Victor Martinez --------- Co-authored-by: Victor Martinez --- .github/workflows/bootstrap/action.yml | 10 +- .../workflows/install-dependencies/action.yml | 27 +++- .github/workflows/test-linux.yml | 57 +++++--- .github/workflows/test-windows-iis.yml | 110 --------------- .github/workflows/test-windows.yml | 127 +++++++++++++++--- 5 files changed, 183 insertions(+), 148 deletions(-) delete mode 100644 .github/workflows/test-windows-iis.yml diff --git a/.github/workflows/bootstrap/action.yml b/.github/workflows/bootstrap/action.yml index 4446c068d..88c6f40a0 100644 --- a/.github/workflows/bootstrap/action.yml +++ b/.github/workflows/bootstrap/action.yml @@ -11,6 +11,10 @@ inputs: description: 'Install azure functions tool chain ("true" or "false")' required: false default: "false" + tc-cloud: + description: 'Bootstrap TestContainers Cloud (TOKEN or "false")' + required: false + default: "false" outputs: agent-version: description: "The current agent version number" @@ -18,6 +22,7 @@ outputs: major-version: description: "The current major version number, semver" value: ${{ steps.dotnet.outputs.major-version }} + runs: using: "composite" @@ -27,7 +32,7 @@ runs: run: | git fetch --prune --unshallow --tags git tag --list - + - uses: actions/cache@v4 with: path: ~/.nuget/packages @@ -56,10 +61,11 @@ runs: # Setup git config - uses: elastic/apm-pipeline-library/.github/actions/setup-git@current - + # install common dependencies - name: Install common dependencies uses: ./.github/workflows/install-dependencies with: rust: '${{ inputs.rust }}' azure: '${{ inputs.azure }}' + tc-cloud: '${{ inputs.tc-cloud }}' diff --git a/.github/workflows/install-dependencies/action.yml b/.github/workflows/install-dependencies/action.yml index cc3e300fe..10552af91 100644 --- a/.github/workflows/install-dependencies/action.yml +++ b/.github/workflows/install-dependencies/action.yml @@ -8,9 +8,13 @@ inputs: required: false default: "false" azure: - description: 'Install azure functions tool chain ("true" or "false")' - required: false - default: "false" + description: 'Install azure functions tool chain ("true" or "false")' + required: false + default: "false" + tc-cloud: + description: 'Bootstrap TestContainers Cloud (TOKEN or "false")' + required: false + default: "false" runs: using: "composite" @@ -55,3 +59,20 @@ runs: shell: cmd run: choco install azure-functions-core-tools -y --no-progress -r --version 4.0.4829 + # TEST CONTAINERS CLOUD + # If no PR event or if a PR event that's caused by a non-fork and non dependabot actor + - name: Setup TestContainers Cloud Client + if: | + inputs.tc-cloud != 'false' + && (github.event_name != 'pull_request' + || (github.event_name == 'pull_request' + && github.event.pull_request.head.repo.fork == false + && github.actor != 'dependabot[bot]' + ) + ) + uses: atomicjar/testcontainers-cloud-setup-action@c335bdbb570ec7c48f72c7d450c077f0a002293e # v1.3.0 + with: + token: ${{ inputs.tc-cloud }} + + + diff --git a/.github/workflows/test-linux.yml b/.github/workflows/test-linux.yml index 4298e4b9e..73b291dad 100644 --- a/.github/workflows/test-linux.yml +++ b/.github/workflows/test-linux.yml @@ -18,16 +18,38 @@ permissions: contents: read concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: '${{ github.workflow }}-${{ github.ref }}' cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +defaults: + run: + shell: bash env: NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages + +# 'pack' & 'tests' are required checks in this workflow. + +# To not burn unneeded CI cycles: +# - Our required checks will always succeed if doc only changes are detected. +# - all jobs depend on 'format' to not waste cycles on quickly fixable errors. + jobs: + + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Bootstrap Action Workspace + uses: ./.github/workflows/bootstrap + - name: Format + run: ./build.sh format + + #required step pack: runs-on: ubuntu-latest - + needs: [ 'format' ] steps: - uses: actions/checkout@v4 - name: Bootstrap Action Workspace @@ -35,31 +57,26 @@ jobs: with: rust: 'true' - - name: Format - run: ./build.sh format - - name: Package run: ./build.sh pack + #required step tests: runs-on: ubuntu-latest + needs: [ 'format' ] timeout-minutes: 30 steps: - uses: actions/checkout@v4 - name: Bootstrap Action Workspace uses: ./.github/workflows/bootstrap - + - name: 'Tests: Unit' - shell: bash run: ./build.sh test --test-suite unit - - name: 'Tests: Integrations' - shell: bash - run: ./build.sh test --test-suite integrations - azure-tests: runs-on: ubuntu-latest + needs: [ 'format', 'tests' ] if: ${{ false }} #if: | # github.event_name != 'pull_request' @@ -91,7 +108,6 @@ jobs: echo "AZURE_RESOURCE_GROUP_PREFIX=ci-dotnet-${GITHUB_RUN_ID}" >> ${GITHUB_ENV} - name: 'Tests: Azure' - shell: bash run: ./build.sh test --test-suite azure - name: 'Teardown tests infra' @@ -100,22 +116,32 @@ jobs: for group in $(az group list --query "[?name | starts_with(@,'${{ env.AZURE_RESOURCE_GROUP_PREFIX }}')]" --out json | jq .[].name --raw-output); do az group delete --name "${group}" --no-wait --yes done + + integration-tests: + runs-on: ubuntu-latest + needs: [ 'format', 'tests' ] + steps: + - uses: actions/checkout@v4 + - name: Bootstrap Action Workspace + uses: ./.github/workflows/bootstrap + - name: 'Tests: Integrations' + run: ./build.sh test --test-suite integrations + startup-hook-tests: runs-on: ubuntu-latest - + needs: [ 'format', 'tests' ] steps: - uses: actions/checkout@v4 - name: Bootstrap Action Workspace uses: ./.github/workflows/bootstrap - name: 'Tests: StartupHooks' - shell: bash run: ./build.sh test --test-suite startuphooks profiler-tests: runs-on: ubuntu-latest - + needs: [ 'format', 'tests' ] steps: - uses: actions/checkout@v4 - name: Bootstrap Action Workspace @@ -125,7 +151,6 @@ jobs: rust: 'true' - name: 'Tests: Profiler' - shell: bash run: ./build.sh test --test-suite profiler - name: Build Profiler Docker Image diff --git a/.github/workflows/test-windows-iis.yml b/.github/workflows/test-windows-iis.yml deleted file mode 100644 index cc799068e..000000000 --- a/.github/workflows/test-windows-iis.yml +++ /dev/null @@ -1,110 +0,0 @@ -name: test-windows-iis - -on: - push: - branches: - - main - - 1.* - paths-ignore: - - '*.md' - - '*.asciidoc' - - 'docs/**' - pull_request: - paths-ignore: - - '*.md' - - '*.asciidoc' - - 'docs/**' - -permissions: - contents: read - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} - -env: - ELASTIC_STACK_VERSION: '8.4.0' - NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages - -jobs: - - test-iis: - runs-on: windows-latest - - steps: - - uses: actions/checkout@v4 - - name: Bootstrap Action Workspace - uses: ./.github/workflows/bootstrap - - - uses: actions/cache@v4 - with: - path: ~/.nuget/packages - key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.[cf]sproj*') }} - - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v2 - - - - name: Clean the application - shell: cmd - run: msbuild /t:Clean /p:Configuration=Release - - - name: Restore the application - shell: cmd - run: msbuild /t:Restore /p:Configuration=Release - - - name: Build the application - shell: cmd - run: | - set INCLUDE_CSHARP_TARGETS=true - msbuild ^ - /p:EnforceCodeStyleInBuild=false /p:_SkipUpgradeNetAnalyzersNuGetWarning=true /p:EnableNETAnalyzers=false ^ - -clp:ForceConsoleColor -clp:Summary -verbosity:minimal ^ - /t:Build /p:Configuration=Release /restore - - #- name: Discover Windows Features - # shell: cmd - # run: | - # DISM /online /get-features /format:table - - # TODO See if this really needed - - name: Enable Windows Features - shell: cmd - run: | - DISM /online /enable-feature /featurename:IIS-HttpErrors - DISM /online /enable-feature /featurename:IIS-HttpRedirect - - - name: Ensure AppPool Permissions - shell: cmd - run: | - REM enable permissions for the Application Pool Identity group - icacls C:\Windows\Temp /grant "IIS_IUSRS:(OI)(CI)F" /T - icacls "c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files" /grant "IIS_IUSRS:(OI)(CI)F" /T - icacls %cd% /t /q /grant "IIS_IUSRS:(OI)(CI)(IO)(RX)" - REM enable permissions for the anonymous access group - icacls %cd% /t /q /grant "IUSR:(OI)(CI)(IO)(RX)" - icacls C:\Windows\Temp /grant "IUSR:(OI)(CI)F" /T - icacls "c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files" /grant "IUSR:(OI)(CI)F" /T - - - name: Run tests - shell: cmd - run: | - set ELASTIC_APM_TESTS_FULL_FRAMEWORK_ENABLED=true - set sample_app_log_dir=C:\Elastic_APM_TEMP - if not exist "%sample_app_log_dir%" mkdir "%sample_app_log_dir%" - icacls %sample_app_log_dir% /t /q /grant Everyone:F - set ELASTIC_APM_ASP_NET_FULL_FRAMEWORK_SAMPLE_APP_LOG_FILE=%sample_app_log_dir%\Elastic.Apm.AspNetFullFramework.Tests.SampleApp.log - - dotnet test -c Release test\iis\Elastic.Apm.AspNetFullFramework.Tests --no-build ^ - --verbosity normal ^ - --results-directory build/output ^ - --diag build/output/diag-iis.log ^ - --filter "FullyQualifiedName=Elastic.Apm.AspNetFullFramework.Tests.CustomServiceNodeNameSetViaSettings.Test" ^ - --logger:"junit;LogFilePath=%cd%\build\output\junit-{framework}-{assembly}.xml;MethodFormat=Class;FailureBodyFormat=Verbose" - - - name: Store test results - if: success() || failure() - uses: actions/upload-artifact@v3 - with: - name: test-results-iis - path: build/output/junit-*.xml \ No newline at end of file diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index b7cadf4f6..64ed6fbe5 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -18,7 +18,7 @@ permissions: contents: read concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: '${{ github.workflow }}-${{ github.ref }}' cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} defaults: @@ -28,32 +28,56 @@ defaults: env: NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages +# 'tests' is a required check in this workflow. + +# To not burn unneeded CI cycles: +# - Our required checks will always succeed if doc only changes are detected. +# - all jobs depend on 'format' to not waste cycles on quickly fixable errors. + jobs: + + format: + runs-on: windows-2022 + steps: + - uses: actions/checkout@v4 + - name: Bootstrap Action Workspace + uses: ./.github/workflows/bootstrap + - name: Format + run: ./build.bat format + + #required step tests: runs-on: windows-2022 + needs: [ 'format' ] timeout-minutes: 30 steps: - uses: actions/checkout@v4 - name: Bootstrap Action Workspace uses: ./.github/workflows/bootstrap - - - name: Setup Testcontainers Cloud Client - if: github.event_name != 'pull_request' || github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false - uses: atomicjar/testcontainers-cloud-setup-action@v1 - with: - token: ${{ secrets.TC_CLOUD_TOKEN }} + with: + tc-cloud: ${{ secrets.TC_CLOUD_TOKEN }} - name: 'Tests: Unit' run: ./build.bat test --test-suite unit - name: 'Tests: Integrations' - shell: bash run: ./build.bat test --test-suite integrations + integrations-tests: + runs-on: windows-2022 + needs: [ 'format', 'tests' ] + steps: + - uses: actions/checkout@v4 + - name: Bootstrap Action Workspace + uses: ./.github/workflows/bootstrap + + - name: 'Tests: Integrations' + run: ./build.bat test --test-suite integrations + startup-hook-tests: runs-on: windows-2022 - + needs: [ 'format', 'tests' ] steps: - uses: actions/checkout@v4 - name: Bootstrap Action Workspace @@ -64,20 +88,89 @@ jobs: profiler-tests: runs-on: windows-2022 - # Disable profiler tests for now - if: ${{ false }} + needs: [ 'format', 'tests' ] steps: - uses: actions/checkout@v4 - name: Bootstrap Action Workspace uses: ./.github/workflows/bootstrap with: rust: 'true' + tc-cloud: ${{ secrets.TC_CLOUD_TOKEN }} + + - name: 'Tests: Profiler' + run: ./build.bat test --test-suite profiler + + test-iis: + runs-on: windows-latest + needs: [ 'format', 'tests' ] + + steps: + - uses: actions/checkout@v4 + - name: Bootstrap Action Workspace + uses: ./.github/workflows/bootstrap - - name: Setup Testcontainers Cloud Client - if: github.event_name != 'pull_request' || github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false - uses: atomicjar/testcontainers-cloud-setup-action@v1 + - uses: actions/cache@v4 with: - token: ${{ secrets.TC_CLOUD_TOKEN }} + path: ~/.nuget/packages + key: "${{ runner.os }}-nuget-${{ hashFiles('**/*.[cf]sproj*') }}" - - name: 'Tests: Profiler' - run: ./build.bat test --test-suite profiler \ No newline at end of file + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2 + + + - name: Clean the application + run: msbuild /t:Clean /p:Configuration=Release + + - name: Restore the application + run: msbuild /t:Restore /p:Configuration=Release + + - name: Build the application + run: | + set INCLUDE_CSHARP_TARGETS=true + msbuild ^ + /p:EnforceCodeStyleInBuild=false /p:_SkipUpgradeNetAnalyzersNuGetWarning=true /p:EnableNETAnalyzers=false ^ + -clp:ForceConsoleColor -clp:Summary -verbosity:minimal ^ + /t:Build /p:Configuration=Release /restore + + #- name: Discover Windows Features + # run: | + # DISM /online /get-features /format:table + + # TODO See if this really needed + - name: Enable Windows Features + run: | + DISM /online /enable-feature /featurename:IIS-HttpErrors + DISM /online /enable-feature /featurename:IIS-HttpRedirect + + - name: Ensure AppPool Permissions + run: | + REM enable permissions for the Application Pool Identity group + icacls C:\Windows\Temp /grant "IIS_IUSRS:(OI)(CI)F" /T + icacls "c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files" /grant "IIS_IUSRS:(OI)(CI)F" /T + icacls %cd% /t /q /grant "IIS_IUSRS:(OI)(CI)(IO)(RX)" + REM enable permissions for the anonymous access group + icacls %cd% /t /q /grant "IUSR:(OI)(CI)(IO)(RX)" + icacls C:\Windows\Temp /grant "IUSR:(OI)(CI)F" /T + icacls "c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files" /grant "IUSR:(OI)(CI)F" /T + + - name: Run tests + run: | + set ELASTIC_APM_TESTS_FULL_FRAMEWORK_ENABLED=true + set sample_app_log_dir=C:\Elastic_APM_TEMP + if not exist "%sample_app_log_dir%" mkdir "%sample_app_log_dir%" + icacls %sample_app_log_dir% /t /q /grant Everyone:F + set ELASTIC_APM_ASP_NET_FULL_FRAMEWORK_SAMPLE_APP_LOG_FILE=%sample_app_log_dir%\Elastic.Apm.AspNetFullFramework.Tests.SampleApp.log + + dotnet test -c Release test\iis\Elastic.Apm.AspNetFullFramework.Tests --no-build ^ + --verbosity normal ^ + --results-directory build/output ^ + --diag build/output/diag-iis.log ^ + --filter "FullyQualifiedName=Elastic.Apm.AspNetFullFramework.Tests.CustomServiceNodeNameSetViaSettings.Test" ^ + --logger:"junit;LogFilePath=%cd%\build\output\junit-{framework}-{assembly}.xml;MethodFormat=Class;FailureBodyFormat=Verbose" + + - name: Store test results + if: success() || failure() + uses: actions/upload-artifact@v3 + with: + name: test-results-iis + path: build/output/junit-*.xml