diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a25afeb87..d54ed303c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ env: mariadbSqlMode: STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION maxConnections: 512 DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - DOTNET_CLI_TELEMETRY_OPTOUT: 1 + DOTNET_CLI_TELEMETRY_OPTOUT: true skipAllTests: false skipWindowsTests: false jobs: @@ -39,9 +39,7 @@ jobs: - 10.4.31-mariadb os: - ubuntu-latest - include: - - os: windows-latest - dbVersion: 8.0.31-mysql + - windows-latest runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -59,12 +57,17 @@ jobs: $databaseServerVersion = $dbVersionParts[0] echo "databaseServerVersion=$databaseServerVersion" >> $env:GITHUB_ENV - $skipTests = '${{ env.skipAllTests }}' -eq 'true' -or $os -eq 'windows' -and '${{ env.skipWindowsTests }}' -eq 'true' + # The parenthesis around the right OR argument are mandatory for the expression to work correctly, because in PowerShell, AND and OR + # operators have the SAME precedence. + $skipTests = '${{ env.skipAllTests }}' -eq 'true' -or ($os -eq 'windows' -and '${{ env.skipWindowsTests }}' -eq 'true') echo "skipTests=$skipTests" >> $env:GITHUB_ENV $sqlMode = $databaseServerType -eq 'mariadb' ? '${{ env.mariadbSqlMode }}' : $databaseServerType -eq 'mysql' -and $databaseServerVersion.Split('.')[0] -lt 8 ? '${{ env.mysqlLegacySqlMode }}' : '${{ env.mysqlCurrentSqlMode }}' echo "sqlMode=$sqlMode" >> $env:GITHUB_ENV + $serverExecutable = $databaseServerType -eq 'mariadb' -and $databaseServerVersion.Split('.')[0] -ge 11 ? 'mariadbd' : 'mysqld' + echo "serverExecutable=$serverExecutable" >> $env:GITHUB_ENV + $clientExecutable = $databaseServerType -eq 'mariadb' -and $databaseServerVersion.Split('.')[0] -ge 11 ? 'mariadb' : 'mysql' echo "clientExecutable=$clientExecutable" >> $env:GITHUB_ENV @@ -85,6 +88,7 @@ jobs: echo "skipTests: ${{ env.skipTests }}" echo "skipAllTests: ${{ env.skipAllTests }}" echo "skipWindowsTests: ${{ env.skipWindowsTests }}" + echo "serverExecutable: ${{ env.serverExecutable }}" echo "clientExecutable: ${{ env.clientExecutable }}" echo "clientCommandPrefix: ${{ env.clientCommandPrefix }}" echo "windowsUserTempLocation: ${{ env.windowsUserTempLocation }}" @@ -113,8 +117,8 @@ jobs: uses: actions/cache@v3 if: ${{ env.os == 'windows' }} with: - path: ${{ env.windowsUserTempLocation }}\${{ env.databaseServerType }} - key: database-windows-${{ env.databaseServerType }}-${{ env.databaseServerVersion }}-v2 + path: ${{ env.windowsUserTempLocation }}\Pomelo.Chocolatey.${{ env.databaseServerType }}.Server + key: database-windows-${{ env.databaseServerType }}-${{ env.databaseServerVersion }}-v3 - name: Install Database Server - Linux if: ${{ env.os == 'linux' }} shell: pwsh @@ -163,9 +167,10 @@ jobs: run: | $mySqlServiceName = '${{ env.databaseServerType }}_${{ env.databaseServerVersion }}' $lowerCaseTableNames = 2 - $mySqlBinPath = 'C:\tools\mysql\current\bin' - $mySqlIniPath = 'C:\tools\mysql\current\my.ini' - $mySqlDataPath = 'C:\ProgramData\MySQL\data' + $packageName = 'Pomelo.Chocolatey.${{ env.databaseServerType }}.Server' + $mySqlBinPath = "C:\tools\${packageName}\current\bin" + $mySqlIniPath = "C:\tools\${packageName}\current\my.ini" + $mySqlDataPath = 'C:\ProgramData\${{ env.databaseServerType }}\data' dir "$env:Temp\${{ env.databaseServerType }}\${{ env.databaseServerVersion }}" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName @@ -177,14 +182,14 @@ jobs: } # choco config set cacheLocation '$(Pipeline.Workspace)/cache/database' - echo "Chocolatey command: choco install '${{ env.databaseServerType }}' '--version=${{ env.databaseServerVersion }}' --params `"/serviceName:$mySqlServiceName`"" - choco install '${{ env.databaseServerType }}' '--version=${{ env.databaseServerVersion }}' --params "/serviceName:$mySqlServiceName" + choco install $packageName '--version=${{ env.databaseServerVersion }}' --ignore-dependencies --source 'https://www.myget.org/F/pomelo/api/v2;https://community.chocolatey.org/api/v2' --params "/serviceName:$mySqlServiceName" Get-Service '*${{ env.databaseServerType }}*' -ErrorAction SilentlyContinue Stop-Service $mySqlServiceName -Verbose echo "Update PATH environment variable" $env:PATH = "$mySqlBinPath;$env:PATH" + echo "PATH=$env:PATH" >> $env:GITHUB_ENV echo "Update configuration file" "lower_case_table_names=$lowerCaseTableNames" >> $mySqlIniPath @@ -192,7 +197,15 @@ jobs: Remove-Item $mySqlDataPath/* -Recurse -Force -Verbose echo "Reinitialize database server" - mysqld --defaults-file="$mySqlIniPath" --initialize-insecure + + if ('${{ env.databaseServerType }}' -eq 'mysql') + { + ${{ env.serverExecutable }} --defaults-file="$mySqlIniPath" --initialize-insecure + } + else + { + mysql_install_db --datadir="$mySqlDataPath" + } Start-Service $mySqlServiceName -Verbose @@ -200,7 +213,7 @@ jobs: ${{ env.clientCommandPrefix }} -h localhost -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password12!';" ${{ env.clientCommandPrefix }} -h localhost -u root -pPassword12! -e "SELECT @@version;" - dir "$env:Temp\${{ env.databaseServerType }}\${{ env.databaseServerVersion }}" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName + dir "$env:Temp\${packageName}\${{ env.databaseServerVersion }}" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName - name: Setup Database shell: pwsh run: ${{ env.clientCommandPrefix }} -u root -pPassword12! -e "SET GLOBAL sql_mode = '${{ env.sqlMode }}'; SET GLOBAL max_connections = ${{ env.maxConnections }};"