From 9a08da074ea72f63502eed09d91ae31c4db03045 Mon Sep 17 00:00:00 2001 From: Dan Hensby Date: Sun, 3 Sep 2023 22:28:42 +0100 Subject: [PATCH] ci: use sqlserver action in CI --- .github/workflows/nodejs.yml | 105 ++++++++++------------------- .releaserc | 2 - appveyor.yml | 39 ----------- test/scripts/appveyor-runtests.cmd | 20 ------ test/scripts/appveyor-setupsql.ps1 | 30 --------- 5 files changed, 36 insertions(+), 160 deletions(-) delete mode 100644 appveyor.yml delete mode 100644 test/scripts/appveyor-runtests.cmd delete mode 100644 test/scripts/appveyor-setupsql.ps1 diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 3688560e..be1a1ac3 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -12,7 +12,7 @@ permissions: jobs: commitlint: name: Lint commits - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout code uses: actions/checkout@v3 @@ -34,7 +34,7 @@ jobs: run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose codelint: name: Lint code - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout code uses: actions/checkout@v3 @@ -51,63 +51,41 @@ jobs: run: npm run lint test-linux: name: Run tests - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + services: + sqlserver: + image: mcr.microsoft.com/${{ matrix.sqlserver == 'edge' && 'azure-sql-edge' || 'mssql/server' }}:${{ matrix.sqlserver == 'edge' && 'latest' || format('{0}-latest', matrix.sqlserver ) }} + ports: + - 1433:1433 + env: + ACCEPT_EULA: Y + MSSQL_SA_PASSWORD: ${{ env.MSSQL_PASSWORD }} needs: - commitlint - codelint env: MSSQL_PASSWORD: 'yourStrong(!)Password' - IMAGE_NAME: ${{ matrix.sql-version == 'edge' && 'azure-sql-edge' || 'mssql/server' }} - IMAGE_TAG: ${{ matrix.sql-version == 'edge' && 'latest' || format('{0}-latest', matrix.sql-version) }} strategy: matrix: - node-version: [14.x, 16.x, 18.x] - sql-version: [2017, 2019, 2022] + os: [ubuntu-22.04] + node: [14.x, 16.x, 18.x] + sqlserver: [2017, 2019, 2022] steps: - name: Checkout code uses: actions/checkout@v3 with: persist-credentials: false - - name: Setup Node.js ${{ matrix.node-version }} + - name: Setup Node.js ${{ matrix.node }} uses: actions/setup-node@v3 with: - node-version: ${{ matrix.node-version }} + node-version: ${{ matrix.node }} cache: 'npm' - name: Install dependencies run: npm clean-install - name: Run unit tests run: npm run test-unit - - name: Setup docker cache - id: cache-docker - uses: actions/cache@v3 - with: - path: .docker - key: docker-cache-${{ runner.os }}-${{ matrix.sql-version }}-latest - - name: Save docker image - if: steps.cache-docker.outputs.cache-hit != 'true' - run: | - mkdir .docker - docker pull "mcr.microsoft.com/$IMAGE_NAME:$IMAGE_TAG" - docker image save "mcr.microsoft.com/$IMAGE_NAME:$IMAGE_TAG" -o "./.docker/${{ matrix.sql-version }}.tar" - - name: Load docker image - if: steps.cache-docker.outputs.cache-hit == 'true' - run: docker image load -i "./.docker/${{ matrix.sql-version }}.tar" - - name: Start docker container - run: docker run --name mssql -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=$MSSQL_PASSWORD" -p 1433:1433 -d "mcr.microsoft.com/$IMAGE_NAME:$IMAGE_TAG" - name: Store test config run: echo "{\"user\":\"sa\",\"password\":\"$MSSQL_PASSWORD\",\"server\":\"localhost\",\"port\":1433,\"database\":\"master\",\"options\":{\"trustServerCertificate\":true}}" > ./test/.mssql.json - - name: Wait for database to be ready - run: | - set +e - ATTEMPT=0 - while [ $ATTEMPT -le 10 ]; do - ATTEMPT=$(( ATTEMPT + 1 )) - docker exec mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U "sa" -P "$MSSQL_PASSWORD" -q 'SELECT 1;' | grep '1 rows affected' - if [ $? -eq 0 ]; then - break - fi - sleep 1 - done - name: Run tedious tests run: npm run test-tedious - name: Run cli tests @@ -125,75 +103,64 @@ jobs: # run: npm install --no-save msnodesqlv8@^2 # - name: Run msnodesqlv8 tests # run: npm run test-msnodesqlv8 - - name: Stop container - if: ${{ always() }} - run: docker rm -f -v mssql test-windows: - name: Run tests (Windows) + name: Run tests needs: - commitlint - codelint - test-linux - runs-on: 'windows-latest' + runs-on: ${{ matrix.os }} env: MSSQL_PASSWORD: 'yourStrong(!)Password' strategy: matrix: - arch: [x64, x86] - node-version: [14.x, 16.x, 18.x] - sql-version: [2017, 2019, 2022] + os: [windows-2019, windows-2022] + node: [14.x, 16.x, 18.x] + sqlserver: [2008, 2012, 2014, 2016, 2017, 2019, 2022] + # These sqlserver versions don't work on windows-2022 (at the moment) + exclude: + - os: windows-2022 + sqlserver: 2008 + - os: windows-2022 + sqlserver: 2012 + - os: windows-2022 + sqlserver: 2014 steps: - name: Checkout code uses: actions/checkout@v3 with: persist-credentials: false - - name: Setup Node.js ${{ matrix.node-version }} + - name: Setup Node.js ${{ matrix.node }} uses: actions/setup-node@v3 with: - architecture: ${{ matrix.arch }} - node-version: ${{ matrix.node-version }} + node-version: ${{ matrix.node }} cache: 'npm' - name: Install dependencies run: npm clean-install - name: Run unit tests run: npm run test-unit - name: Setup SQL Server - uses: potatoqualitee/mssqlsuite@v1.7 + uses: tediousjs/setup-sqlserver@v1 with: - install: sqlengine + sqlserver-version: ${{ matrix.sqlserver }} sa-password: ${{ env.MSSQL_PASSWORD }} - version: ${{ matrix.sql-version }} + native-client-version: 11 - name: Store test config shell: bash - run: echo "{\"user\":\"sa\",\"password\":\"$MSSQL_PASSWORD\",\"server\":\"localhost\",\"port\":1433,\"database\":\"master\",\"options\":{\"trustServerCertificate\":true}}" > ./test/.mssql.json - - name: Wait for database to be ready - shell: bash - run: | - set +e - ATTEMPT=0 - while [ $ATTEMPT -le 10 ]; do - ATTEMPT=$(( ATTEMPT + 1 )) - sqlcmd -S localhost -U "sa" -P "$MSSQL_PASSWORD" -q 'SELECT 1;' | grep '1 rows affected' - if [ $? -eq 0 ]; then - break - fi - sleep 1 - done + run: echo "{\"user\":\"sa\",\"password\":\"$MSSQL_PASSWORD\",\"server\":\"localhost\",\"port\":1433,\"database\":\"master\",\"requestTimeout\":30000,\"options\":{\"abortTransactionOnError\":true,\"encrypt\":false}}" > ./test/.mssql.json - name: Run tedious tests run: npm run test-tedious - name: Run cli tests run: npm run test-cli - name: Install msnodesqlv8 - if: ${{ matrix.sql-version != '2022' }} run: npm install --no-save msnodesqlv8@^2 - name: Run msnodesqlv8 tests - if: ${{ matrix.sql-version != '2022' }} run: npm run test-msnodesqlv8 release: name: Release concurrency: release if: ${{ github.repository_owner == 'tediousjs' && github.event_name == 'push' && github.actor != 'dependabot[bot]' }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: - commitlint - codelint diff --git a/.releaserc b/.releaserc index 37e95e92..dd6a2a2f 100644 --- a/.releaserc +++ b/.releaserc @@ -1,5 +1,3 @@ -branches: - - master plugins: - '@semantic-release/commit-analyzer' - '@semantic-release/release-notes-generator' diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 6b0f7ebb..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,39 +0,0 @@ -version: "{build}" - -branches: - except: - - '/^dependabot\/.*/' - -image: - - Visual Studio 2015 -environment: - matrix: - - nodejs_version: "14" - - nodejs_version: "16" - - nodejs_version: "18" - -install: - # https://www.appveyor.com/docs/lang/nodejs-iojs/#installing-any-version-of-nodejs-or-iojs - - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:PLATFORM - - npm install - - npm install msnodesqlv8@^2 - -platform: - - x86 - - x64 - -cache: - - node_modules - -build: off - -before_test: - - sc config sqlbrowser start= auto - - net start sqlbrowser - -test_script: - - node --version - - npm --version - - cmd: | - CALL %cd%\test\scripts\appveyor-runtests.cmd - EXIT /B %errorlevel% diff --git a/test/scripts/appveyor-runtests.cmd b/test/scripts/appveyor-runtests.cmd deleted file mode 100644 index 8be5cc02..00000000 --- a/test/scripts/appveyor-runtests.cmd +++ /dev/null @@ -1,20 +0,0 @@ -@echo on -SET EXITVAL=0 -echo %APPVEYOR_BUILD_WORKER_IMAGE% -CALL npm run-script test-unit || SET EXITVAL=1 -IF "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" ( - SET VERSIONS_TO_TEST=SQL2008R2SP2,SQL2012SP1,SQL2014,SQL2016 -) -IF NOT DEFINED VERSIONS_TO_TEST ( - SET EXITVAL=2 -) ELSE ( - FOR %%S IN ( %VERSIONS_TO_TEST% ) DO ( - echo Testing %%S - CALL powershell %cd%\test\scripts\appveyor-setupsql.ps1 %%S - CALL npm run-script test-cli || SET EXITVAL=1 - CALL npm run-script test-tedious || SET EXITVAL=1 - CALL npm run-script test-msnodesqlv8 || SET EXITVAL=1 - CALL net stop MSSQL$%%S - ) -) -EXIT /B %EXITVAL% diff --git a/test/scripts/appveyor-setupsql.ps1 b/test/scripts/appveyor-setupsql.ps1 deleted file mode 100644 index 3b24974e..00000000 --- a/test/scripts/appveyor-setupsql.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null; -[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | Out-Null; - -$instancename = $args[0]; - -$wmi = New-Object('Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer'); -$tcp = $wmi.GetSmoObject("ManagedComputer[@Name='${env:computername}']/ServerInstance[@Name='${instancename}']/ServerProtocol[@Name='Tcp']"); -$tcp.IsEnabled = $true; -$tcp.Alter(); - -Start-Service -Name "MSSQL`$$instancename"; - -$wmi = New-Object('Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer'); -$ipall = $wmi.GetSmoObject("ManagedComputer[@Name='${env:computername}']/ServerInstance[@Name='${instancename}']/ServerProtocol[@Name='Tcp']/IPAddress[@Name='IPAll']"); -$port = $ipall.IPAddressProperties.Item("TcpDynamicPorts").Value; - -$config = @{ - user = "sa"; - password = "Password12!"; - server = "localhost"; - port = $port; - database = "master"; - requestTimeout = 30000; - options = @{ - abortTransactionOnError = $true; - encrypt = $false; - } -} | ConvertTo-Json -Depth 3; - -[System.IO.File]::WriteAllLines("test\.mssql.json", $config);