|
| 1 | +# This workflow will build a .NET project |
| 2 | +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net |
| 3 | + |
| 4 | +name: build-and-test (reusable workflow) |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_call: |
| 8 | + inputs: |
| 9 | + dotnet-version: |
| 10 | + description: "required dotnet version. The default is '8.0.x'." |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + default: '8.0.x' |
| 14 | + dotnet-framework: |
| 15 | + description: "target framework for dotnet test. The default is 'net8.0'." |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + default: 'net8.0' |
| 19 | + configuration: |
| 20 | + description: "The configuration to use for building the package. The default is 'Release'." |
| 21 | + required: true |
| 22 | + type: string |
| 23 | + default: 'Release' |
| 24 | + |
| 25 | +jobs: |
| 26 | + build-and-test: |
| 27 | + runs-on: ubuntu-22.04 |
| 28 | + env: |
| 29 | + NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages |
| 30 | + steps: |
| 31 | + - run: echo "The inputs.dotnet version is ${{ inputs.dotnet-version }}, framework is ${{ inputs.dotnet-framework }}." |
| 32 | + - run: echo "The inputs.configuration is ${{ inputs.configuration }}." |
| 33 | + - run: echo "The job was automatically triggered by a ${{ github.event_name }} event." |
| 34 | + - run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub!" |
| 35 | + - run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." |
| 36 | + |
| 37 | + - name: Check out repository code |
| 38 | + uses: actions/checkout@v4 |
| 39 | + - run: echo "The ${{ github.repository }} repository has been cloned to the runner." |
| 40 | + - run: echo "The workflow is now ready to test your code on the runner." |
| 41 | + - name: List files in the repository |
| 42 | + run: | |
| 43 | + ls -la ${{ github.workspace }} |
| 44 | + sudo cat ./.github/workflows/build-and-test.yml |
| 45 | + |
| 46 | + - name: Setup dotnet |
| 47 | + uses: actions/setup-dotnet@v4 |
| 48 | + with: |
| 49 | + dotnet-version: ${{ inputs.dotnet-version }} |
| 50 | + global-json-file: global.json |
| 51 | + cache: false |
| 52 | + |
| 53 | + - name: Display dotnet version |
| 54 | + run: | |
| 55 | + DOTNET_VERSION=$(dotnet --version) |
| 56 | + echo "DOTNET_VERSION=$DOTNET_VERSION" >> $GITHUB_ENV |
| 57 | + DOTNET_VERSION_MAJOR=$(echo $DOTNET_VERSION | cut -d '.' -f 1) |
| 58 | + DOTNET_VERSION_MINOR=$(echo $DOTNET_VERSION | cut -d '.' -f 2) |
| 59 | + echo "DOTNET_VERSION_MAJOR=$DOTNET_VERSION_MAJOR" >> $GITHUB_ENV |
| 60 | + echo "DOTNET_VERSION_MINOR=$DOTNET_VERSION_MINOR" >> $GITHUB_ENV |
| 61 | + echo "DOTNET_VERSION_MAJOR_MINOR=$DOTNET_VERSION_MAJOR.$DOTNET_VERSION_MINOR" >> $GITHUB_ENV |
| 62 | + echo "dotnet ${{ env.DOTNET_VERSION }} is installed." |
| 63 | + |
| 64 | + - name: Fixing error 'No usable version of libssl was found' for dotnet 3.1.x |
| 65 | + if: ${{ env.DOTNET_VERSION_MAJOR_MINOR == '3.1' }} |
| 66 | + run: | |
| 67 | + sudo apt-get update |
| 68 | + sudo apt-get install -y libssl-dev libssl1.1 |
| 69 | + |
| 70 | + - name: Install dependencies |
| 71 | + run: dotnet restore |
| 72 | + - name: Build |
| 73 | + run: dotnet build --no-restore --configuration ${{ inputs.configuration }} |
| 74 | + |
| 75 | + - name: Test with the dotnet CLI |
| 76 | + run: dotnet test --no-build --framework ${{ inputs.dotnet-framework }} --configuration ${{ inputs.configuration }} --verbosity normal --logger trx --results-directory "TestResults-${{ inputs.configuration }}-${{ inputs.dotnet-framework }}" |
| 77 | + - name: Upload dotnet test results |
| 78 | + uses: actions/upload-artifact@v4 |
| 79 | + with: |
| 80 | + name: dontet-results-${{ inputs.configuration }}-${{ inputs.dotnet-framework }} |
| 81 | + path: TestResults-${{ inputs.configuration }}-${{ inputs.dotnet-framework }} |
| 82 | + if: ${{ always() }} |
| 83 | + |
| 84 | + - run: echo "This job's status is ${{ job.status }}." |
| 85 | + |
0 commit comments