|
| 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: .NET Publish |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: ["master", "main"] |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + dotnet-version: |
| 12 | + description: ".NET SDK version" |
| 13 | + required: false |
| 14 | + default: "10.0.x" |
| 15 | + solution: |
| 16 | + description: "Solution or project path to build/test" |
| 17 | + required: false |
| 18 | + default: "Inflatable.sln" |
| 19 | + test-filter: |
| 20 | + description: "Optional dotnet test filter" |
| 21 | + required: false |
| 22 | + default: "" |
| 23 | + coveralls-upload: |
| 24 | + description: "Optional lcov path for Coveralls" |
| 25 | + required: false |
| 26 | + default: "" |
| 27 | + user-email: |
| 28 | + description: "Git identity email used for release commit" |
| 29 | + required: false |
| 30 | + default: "JaCraig@users.noreply.github.com" |
| 31 | + user: |
| 32 | + description: "Git identity name used for release commit" |
| 33 | + required: false |
| 34 | + default: "JaCraig" |
| 35 | + |
| 36 | +concurrency: |
| 37 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 38 | + cancel-in-progress: false |
| 39 | + |
| 40 | +jobs: |
| 41 | + build: |
| 42 | + if: "!startsWith(github.event.head_commit.message, 'chore(release):')" |
| 43 | + timeout-minutes: 45 |
| 44 | + permissions: |
| 45 | + contents: write |
| 46 | + env: |
| 47 | + BUILD_CONFIG: "Release" |
| 48 | + SOLUTION_FILE: "${{ inputs.solution || 'SQLHelper.sln' }}" |
| 49 | + TEST_FILTER: "${{ inputs.test-filter || '' }}" |
| 50 | + COVERALLS_UPLOAD: "${{ inputs.coveralls-upload || '' }}" |
| 51 | + GIT_USER_EMAIL: "${{ inputs.user-email || 'JaCraig@users.noreply.github.com' }}" |
| 52 | + GIT_USER_NAME: "${{ inputs.user || 'JaCraig' }}" |
| 53 | + |
| 54 | + SQL_HOST: "127.0.0.1" |
| 55 | + SQL_PORT: "1433" |
| 56 | + SQLHELPER_SQL_SERVER: "127.0.0.1,1433" |
| 57 | + SQLHELPER_SQL_PASSWORD: "${{ secrets.SQLHELPER_SQL_PASSWORD }}" |
| 58 | + |
| 59 | + runs-on: ubuntu-latest |
| 60 | + services: |
| 61 | + sqlserver: |
| 62 | + image: mcr.microsoft.com/mssql/server:2022-latest |
| 63 | + env: |
| 64 | + ACCEPT_EULA: "Y" |
| 65 | + MSSQL_PID: "Developer" |
| 66 | + SA_PASSWORD: "${{ secrets.SQLHELPER_SQL_PASSWORD }}" |
| 67 | + ports: |
| 68 | + - 1433:1433 |
| 69 | + |
| 70 | + strategy: |
| 71 | + matrix: |
| 72 | + dotnet-version: ["${{ inputs.dotnet-version || '10.0.x' }}"] |
| 73 | + |
| 74 | + steps: |
| 75 | + - uses: actions/checkout@v6 |
| 76 | + with: |
| 77 | + fetch-depth: 0 |
| 78 | + persist-credentials: false |
| 79 | + |
| 80 | + - name: Setup .NET SDK ${{ matrix.dotnet-version }} |
| 81 | + uses: actions/setup-dotnet@v5.2.0 |
| 82 | + with: |
| 83 | + dotnet-version: ${{ matrix.dotnet-version }} |
| 84 | + |
| 85 | + - name: Wait for SQL Server |
| 86 | + shell: bash |
| 87 | + run: | |
| 88 | + for i in {1..60}; do |
| 89 | + if timeout 1 bash -c "</dev/tcp/$SQL_HOST/$SQL_PORT" 2>/dev/null; then |
| 90 | + echo "SQL Server port is reachable." |
| 91 | + exit 0 |
| 92 | + fi |
| 93 | + echo "Waiting for SQL Server... attempt $i" |
| 94 | + sleep 2 |
| 95 | + done |
| 96 | + echo "SQL Server did not become reachable in time." |
| 97 | + exit 1 |
| 98 | +
|
| 99 | + - name: Create test databases |
| 100 | + shell: bash |
| 101 | + run: | |
| 102 | + docker exec "${{ job.services.sqlserver.id }}" /opt/mssql-tools18/bin/sqlcmd \ |
| 103 | + -S localhost \ |
| 104 | + -U sa \ |
| 105 | + -P "$SQLHELPER_SQL_PASSWORD" \ |
| 106 | + -C \ |
| 107 | + -Q "IF DB_ID(N'TestDatabase') IS NULL CREATE DATABASE [TestDatabase]; IF DB_ID(N'TestDatabase2') IS NULL CREATE DATABASE [TestDatabase2]; IF DB_ID(N'MockDatabase') IS NULL CREATE DATABASE [MockDatabase]; IF DB_ID(N'MockDatabaseForMockMapping') IS NULL CREATE DATABASE [MockDatabaseForMockMapping];" |
| 108 | +
|
| 109 | + - name: Cache NuGet packages |
| 110 | + uses: actions/cache@v4 |
| 111 | + with: |
| 112 | + path: ~/.nuget/packages |
| 113 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Packages.props', '**/packages.lock.json', 'global.json', '**/nuget.config', '**/NuGet.Config') }} |
| 114 | + restore-keys: | |
| 115 | + ${{ runner.os }}-nuget- |
| 116 | +
|
| 117 | + - name: Install Versionize |
| 118 | + run: dotnet tool install --global Versionize |
| 119 | + |
| 120 | + - name: Setup git |
| 121 | + run: | |
| 122 | + git config --local user.email "$GIT_USER_EMAIL" |
| 123 | + git config --local user.name "$GIT_USER_NAME" |
| 124 | +
|
| 125 | + - name: Versionize Release |
| 126 | + id: versionize |
| 127 | + run: versionize --exit-insignificant-commits |
| 128 | + continue-on-error: true |
| 129 | + |
| 130 | + - name: Restore dependencies |
| 131 | + run: dotnet restore "$SOLUTION_FILE" |
| 132 | + |
| 133 | + - name: Build |
| 134 | + run: dotnet build "$SOLUTION_FILE" --no-restore --configuration $BUILD_CONFIG |
| 135 | + |
| 136 | + - name: Test |
| 137 | + run: dotnet test "$SOLUTION_FILE" /p:CollectCoverage=true /p:CoverletOutput=TestResults-${{ matrix.dotnet-version }}/ /p:CoverletOutputFormat=lcov /p:Configuration=$BUILD_CONFIG --no-build --verbosity normal --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" $TEST_FILTER |
| 138 | + |
| 139 | + - name: Upload test results |
| 140 | + uses: actions/upload-artifact@v7 |
| 141 | + with: |
| 142 | + name: dotnet-results-${{ matrix.dotnet-version }} |
| 143 | + path: TestResults-${{ matrix.dotnet-version }} |
| 144 | + if: ${{ always() }} |
| 145 | + |
| 146 | + - name: Publish coverage report to coveralls.io |
| 147 | + uses: coverallsapp/github-action@v2 |
| 148 | + if: ${{ env.COVERALLS_UPLOAD != '' }} |
| 149 | + with: |
| 150 | + path-to-lcov: ${{ env.COVERALLS_UPLOAD }} |
| 151 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 152 | + format: lcov |
| 153 | + fail-on-error: false |
| 154 | + |
| 155 | + - name: Upload NuGet package |
| 156 | + uses: actions/upload-artifact@v7 |
| 157 | + with: |
| 158 | + name: NugetPackage |
| 159 | + path: ./**/*.nupkg |
| 160 | + if: steps.versionize.outcome == 'success' |
| 161 | + |
| 162 | + - name: Upload Symbol package |
| 163 | + uses: actions/upload-artifact@v7 |
| 164 | + with: |
| 165 | + name: SymbolPackage |
| 166 | + path: ./**/*.snupkg |
| 167 | + if: steps.versionize.outcome == 'success' |
| 168 | + |
| 169 | + - name: Push changes to Github |
| 170 | + if: steps.versionize.outcome == 'success' |
| 171 | + uses: ad-m/github-push-action@v1.0.0 |
| 172 | + with: |
| 173 | + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 174 | + branch: ${{ github.ref }} |
| 175 | + force: true |
| 176 | + tags: true |
| 177 | + |
| 178 | + - name: Upload package to NuGet |
| 179 | + if: steps.versionize.outcome == 'success' |
| 180 | + run: dotnet nuget push "**/*.nupkg" -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate |
0 commit comments