From cc4030577f8b22122b97ab2362c2e6698c00c388 Mon Sep 17 00:00:00 2001 From: Jadyn Date: Wed, 3 Mar 2021 16:09:49 +0800 Subject: [PATCH] Add release github action Update packages --- .actrc | 4 + .github/workflows/dotnetcore.yml | 4 +- .github/workflows/release.yml | 60 ++++++ .github/workflows/sync_qqwry.yml | 2 + .gitignore | 2 + .travis.yml | 14 -- Build.ps1 | 34 ++-- .../QQWry.DependencyInjection.csproj | 23 ++- QQWry/QQWry.csproj | 8 +- QQWryTest/QQWry.Test.csproj | 8 +- README.md | 182 +++++++++--------- Sample/Sample.csproj | 6 +- appveyor.yml | 26 --- 13 files changed, 205 insertions(+), 168 deletions(-) create mode 100644 .actrc create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml delete mode 100644 appveyor.yml diff --git a/.actrc b/.actrc new file mode 100644 index 0000000..a999e8b --- /dev/null +++ b/.actrc @@ -0,0 +1,4 @@ +-P ubuntu-latest=catthehacker/ubuntu:act-latest +-P ubuntu-20.04=catthehacker/ubuntu:act-20.04 +-P ubuntu-18.04=catthehacker/ubuntu:act-18.04 +ubuntu-16.04=catthehacker/ubuntu:act-16.04 \ No newline at end of file diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index e03918f..9a47f1f 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -12,8 +12,10 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.101 + dotnet-version: 5.0.103 - name: Build with dotnet run: dotnet build --configuration Release - name: Test with dotnet run: dotnet test --configuration Release + - name: Pack with dotnet + run: dotnet pack --configuration Release diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d3c1208 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,60 @@ +# This is a basic workflow to help you get started with Actions + +name: release + +# Controls when the action will run. +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - '*' # Push events to matching v*, i.e. v1.0, v20.15.10 + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: windows-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Get the version + id: get_version + shell: bash + run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.103 + + - name: Build project + run: | + .\Build.ps1 -version ${{ steps.get_version.outputs.VERSION }} -nugetKey ${{ secrets.NugetKey }} + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.get_version.outputs.VERSION }} + release_name: Release ${{ steps.get_version.outputs.VERSION }} + draft: false + prerelease: false + + - name: Upload Release Asset + id: action-gh-release + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + files: | + ./artifacts/QQWry.${{ steps.get_version.outputs.VERSION }}.nupkg + ./artifacts/QQWry.DependencyInjection.${{ steps.get_version.outputs.VERSION }}.nupkg diff --git a/.github/workflows/sync_qqwry.yml b/.github/workflows/sync_qqwry.yml index c5035ee..4be9ff9 100644 --- a/.github/workflows/sync_qqwry.yml +++ b/.github/workflows/sync_qqwry.yml @@ -33,6 +33,8 @@ jobs: # Runs a set of commands using the runners shell - name: Git push run: | + git config user.name github-actions + git config user.email github-actions@github.com git add . git commit -m 'sync qqwry' git push diff --git a/.gitignore b/.gitignore index 3e759b7..d6b7369 100644 --- a/.gitignore +++ b/.gitignore @@ -328,3 +328,5 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ +act/actions-setup-dotnet@v1 +act/actions-setup-dotnet@v1 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a4cbe64..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -dist: xenial -language: csharp -mono: none -dotnet: 3.1.101 -solution: ./QQWrySln.sln -script: - - dotnet restore - - dotnet build ./QQWrySln.sln - - dotnet test ./QQWryTest -c Release - - dotnet pack ./QQWry - - dotnet pack ./QQWry.DependencyInjection -global: - - DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true - - DOTNET_CLI_TELEMETRY_OPTOUT=1 \ No newline at end of file diff --git a/Build.ps1 b/Build.ps1 index 25b85f3..b0e8413 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -1,30 +1,28 @@ +param( + [Parameter(Mandatory = $true)][string]$version = $(throw "Parameter missing: -version Version"), + [string]$nugetKey +) + $rootFolder = (Get-Item -Path "./" -Verbose).FullName $outputFolder = (Join-Path $rootFolder "artifacts") -if(Test-Path $outputFolder) { Remove-Item $outputFolder -Force -Recurse } +if (Test-Path $outputFolder) { Remove-Item $outputFolder -Force -Recurse } -dotnet restore +Write-Output "Version:$version" -$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$NULL -ne $env:APPVEYOR_BUILD_NUMBER]; +dotnet build QQWrySln.sln --configuration Release -$revision = [convert]::ToInt32($revision, 10) +dotnet test QQWrySln.sln --configuration Release -Write-Output $revision + dotnet pack .\QQWry -o $outputFolder -p:Version=$version --configuration Release -$version = @{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "-1"}[$NULL -ne $env:APPVEYOR_BUILD_VERSION]; + dotnet pack .\QQWry.DependencyInjection -o $outputFolder -p:Version=$version --configuration Release -if($version -eq "-1"){ - throw "can't read version" +if ($nugetKey) { + dotnet nuget push "$outputFolder\*.nupkg" --source https://api.nuget.org/v3/index.json --skip-duplicate --api-key $nugetKey +} +else { + Write-Output "Skip nuget push" } - -Write-Output $version - -dotnet test .\QQWryTest -c Release - -dotnet build QQWrySln.sln - -dotnet pack .\QQWry -o $outputFolder -p:Version=$version --version-suffix=$revision - -dotnet pack .\QQWry.DependencyInjection -o $outputFolder -p:Version=$version --version-suffix=$revision Set-Location $outputFolder diff --git a/QQWry.DependencyInjection/QQWry.DependencyInjection.csproj b/QQWry.DependencyInjection/QQWry.DependencyInjection.csproj index 0e5258d..a5bc369 100644 --- a/QQWry.DependencyInjection/QQWry.DependencyInjection.csproj +++ b/QQWry.DependencyInjection/QQWry.DependencyInjection.csproj @@ -1,7 +1,7 @@  - netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1 + netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5; true JadynWong https://github.com/JadynWong/IP_qqwry @@ -13,32 +13,35 @@ - + - - + - + - + - + - + - + - + + + + + diff --git a/QQWry/QQWry.csproj b/QQWry/QQWry.csproj index 47114ea..808cb64 100644 --- a/QQWry/QQWry.csproj +++ b/QQWry/QQWry.csproj @@ -1,7 +1,7 @@  - netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net4.5 + netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5;net4.5 netstandard2.0 true JadynWong @@ -15,7 +15,7 @@ - + @@ -23,9 +23,7 @@ - - 4.7.0 - + diff --git a/QQWryTest/QQWry.Test.csproj b/QQWryTest/QQWry.Test.csproj index 0bd31d1..7eab41c 100644 --- a/QQWryTest/QQWry.Test.csproj +++ b/QQWryTest/QQWry.Test.csproj @@ -1,17 +1,17 @@  - netcoreapp3.1 + net5 false QQWry.Test QQWry.Test - - + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/README.md b/README.md index aa8f51c..6e05c5e 100644 --- a/README.md +++ b/README.md @@ -1,108 +1,116 @@ # IP_qqwry [纯真IP数据库](http://www.cz88.net/)操作 -appveyor [![Build status](https://ci.appveyor.com/api/projects/status/j89jp316jp1i8sg2?svg=true)](https://ci.appveyor.com/project/JadynWong/ip-qqwry) -travis-ci [![Build Status](https://travis-ci.com/JadynWong/IP_qqwry.svg?branch=master)](https://travis-ci.com/JadynWong/IP_qqwry) +[![.NET Core](https://github.com/JadynWong/IP_qqwry/actions/workflows/dotnetcore.yml/badge.svg)](https://github.com/JadynWong/IP_qqwry/actions/workflows/dotnetcore.yml) +[![release](https://github.com/JadynWong/IP_qqwry/actions/workflows/release.yml/badge.svg)](https://github.com/JadynWong/IP_qqwry/actions/workflows/release.yml) +[![sync_qqwry](https://github.com/JadynWong/IP_qqwry/actions/workflows/sync_qqwry.yml/badge.svg)](https://github.com/JadynWong/IP_qqwry/actions/workflows/sync_qqwry.yml) -QQWry [![NuGet](https://img.shields.io/nuget/v/QQWry.svg?style=flat)](https://www.nuget.org/packages/QQWry) - -QQWry.DependencyInjection [![NuGet](https://img.shields.io/nuget/v/QQWry.DependencyInjection.svg?style=flat)](https://www.nuget.org/packages/QQWry.DependencyInjection) +| Packages | Version | +| ---- | ---- | +|QQWry | [![NuGet](https://img.shields.io/nuget/v/QQWry.svg?style=flat)](https://www.nuget.org/packages/QQWry) | +| QQWry.DependencyInjection | [![NuGet](https://img.shields.io/nuget/v/QQWry.DependencyInjection.svg?style=flat)](https://www.nuget.org/packages/QQWry.DependencyInjection) | 支持在线更新数据库 ## QQWry - var config = new QQWryOptions() - { - DbPath = MapRootPath("~/IP/qqwry.dat") - }; +```csharp +var config = new QQWryOptions() +{ + DbPath = MapRootPath("~/IP/qqwry.dat") +}; - var ipSearch = new QQWryIpSearch(config); +var ipSearch = new QQWryIpSearch(config); - foreach (var ip in preSearchIpArray) - { - var ipLocation = ipSearch.GetIpLocation(ip); - Write(ipLocation); - } - Console.WriteLine("记录总数" + ipSearch.IpCount); - Console.WriteLine("版本" + ipSearch.Version); +foreach (var ip in preSearchIpArray) +{ + var ipLocation = ipSearch.GetIpLocation(ip); + Write(ipLocation); +} +Console.WriteLine("记录总数" + ipSearch.IpCount); +Console.WriteLine("版本" + ipSearch.Version); +``` ## QQWry.DependencyInjection - var service = new ServiceCollection(); +```csharp +var service = new ServiceCollection(); - service.AddQQWry(config); +service.AddQQWry(config); - var serviceProvider = service.BuildServiceProvider(); +var serviceProvider = service.BuildServiceProvider(); - using (var scope = serviceProvider.CreateScope()) +using (var scope = serviceProvider.CreateScope()) +{ + var ipSearchInterface = scope.ServiceProvider.GetRequiredService(); + foreach (var ip in preSearchIpArray) { - var ipSearchInterface = scope.ServiceProvider.GetRequiredService(); - foreach (var ip in preSearchIpArray) - { - var ipLocation = ipSearchInterface.GetIpLocation(ip); - Write(ipLocation); - } - Console.WriteLine("记录总数" + ipSearchInterface.IpCount); - Console.WriteLine("版本" + ipSearchInterface.Version); + var ipLocation = ipSearchInterface.GetIpLocation(ip); + Write(ipLocation); } + Console.WriteLine("记录总数" + ipSearchInterface.IpCount); + Console.WriteLine("版本" + ipSearchInterface.Version); +} +``` ## IIpSearch - /// - /// 数据库IP数量 - /// - int IpCount { get; } - - /// - /// 数据库版本 - /// - string Version { get; } - - /// - /// 检查是否是IP地址 - /// - /// - /// - bool CheckIp(string ip); - - /// - /// 获取IP信息 - /// - /// - /// - IpLocation GetIpLocation(string strIp); - - /// - /// 检查是否是IP地址 - /// - /// - /// - /// - Task GetIpLocationAsync(string strIp, CancellationToken token = default(CancellationToken)); - - /// - /// 获取QQWry CopyWrite - /// - /// - QQWryCopyWrite GetCopyWrite(); - - /// - /// 获取QQWry CopyWrite - /// - /// - Task GetCopyWriteAsync(); - - /// - /// 获取IP信息 - /// - /// 获取新数据库 - /// - bool Init(bool getNewDb = false); - - /// - /// 获取IP信息 - /// - /// - /// - /// - Task InitAsync(bool getNewDb = false, CancellationToken token = default(CancellationToken)); +```csharp +/// +/// 数据库IP数量 +/// +int IpCount { get; } + +/// +/// 数据库版本 +/// +string Version { get; } + +/// +/// 检查是否是IP地址 +/// +/// +/// +bool CheckIp(string ip); + +/// +/// 获取IP信息 +/// +/// +/// +IpLocation GetIpLocation(string strIp); + +/// +/// 检查是否是IP地址 +/// +/// +/// +/// +Task GetIpLocationAsync(string strIp, CancellationToken token = default(CancellationToken)); + +/// +/// 获取QQWry CopyWrite +/// +/// +QQWryCopyWrite GetCopyWrite(); + +/// +/// 获取QQWry CopyWrite +/// +/// +Task GetCopyWriteAsync(); + +/// +/// 获取IP信息 +/// +/// 获取新数据库 +/// +bool Init(bool getNewDb = false); + +/// +/// 获取IP信息 +/// +/// +/// +/// +Task InitAsync(bool getNewDb = false, CancellationToken token = default(CancellationToken)); +``` diff --git a/Sample/Sample.csproj b/Sample/Sample.csproj index 567da98..9fe9f2a 100644 --- a/Sample/Sample.csproj +++ b/Sample/Sample.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net5 @@ -14,8 +14,8 @@ - - + + diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 7f196f9..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,26 +0,0 @@ -version: '1.1.{build}' -image: Visual Studio 2019 -skip_non_tags: true -branches: - only: - - master -build_script: -- ps: .\Build.ps1 -artifacts: -- path: .\artifacts\*.nupkg - name: NuGet -deploy: -- provider: NuGet - name: production - api_key: - secure: 3BkRUkvxXQyC77E+MAlJiZLODsf/C1Rd4qMsvkEqyize/uYYc+hhvEW5OBCDezjK - skip_symbols: true - on: - branch: master -- provider: GitHub - auth_token: - secure: sogLxB371IAfeh6vsGSybVS74vlINbMqOEbf0dSWKP42flC5vt2Pw9OREJNY4Nl3 - artifact: NuGet - draft: true - on: - branch: master \ No newline at end of file