From d31981bed2ae6febb224edaaa256d7464524fbd4 Mon Sep 17 00:00:00 2001 From: Connection Refused Date: Sat, 16 Oct 2021 09:40:51 +0800 Subject: [PATCH] [GitHub CI] Caching (#772) --- .github/workflows/build.yml | 56 ++++++++++++++++++++++++----- .github/workflows/release.yml | 60 ++++++++++++++++++++++++-------- Other/sha256.ps1 | 17 +++++++++ Redirector/sha256.ps1 | 13 +++++++ RouteHelper/sha256.ps1 | 13 +++++++ build.ps1 | 48 +++++++++++++++---------- deps.ps1 | 11 ------ scripts/deps/main/netch-data.ps1 | 14 -------- scripts/deps/main/netch-i18n.ps1 | 14 -------- scripts/deps/main/netch-mode.ps1 | 14 -------- 10 files changed, 165 insertions(+), 95 deletions(-) create mode 100644 Other/sha256.ps1 create mode 100644 Redirector/sha256.ps1 create mode 100644 RouteHelper/sha256.ps1 delete mode 100644 scripts/deps/main/netch-data.ps1 delete mode 100644 scripts/deps/main/netch-i18n.ps1 delete mode 100644 scripts/deps/main/netch-mode.ps1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ffb12b71..5b1da762 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,34 +6,72 @@ jobs: name: Build runs-on: windows-2022 steps: - - name: Go + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Checksum + shell: pwsh + run: | + $otherHash=$(.\Other\sha256.ps1) + $redirHash=$(.\Redirector\sha256.ps1) + $routeHash=$(.\RouteHelper\sha256.ps1) + + echo "OTHER_SHA256=$otherHash" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV + echo "REDIR_SHA256=$redirHash" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV + echo "ROUTE_SHA256=$routeHash" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV + + - name: Cache Other + uses: actions/cache@v2 + with: + key: Netch-${{ runner.os }}-Other-${{ env.OTHER_SHA256 }} + path: .\other\release + + - name: Cache Redirector + uses: actions/cache@v2 + with: + key: Netch-${{ runner.os }}-Redirector-${{ env.REDIR_SHA256 }} + path: .\Redirector\bin + + - name: Cache RouteHelper + uses: actions/cache@v2 + with: + key: Netch-${{ runner.os }}-RouteHelper-${{ env.ROUTE_SHA256 }} + path: .\RouteHelper\bin + + - name: Check Other + id: check_other + uses: andstor/file-existence-action@v1 + with: + files: .\other\release\aiodns.bin + + - name: Setup Go uses: actions/setup-go@v2 + if: steps.check_other.outputs.files_exists == 'false' with: go-version: 1.17.2 - - name: C++ + - name: Setup C++ uses: msys2/setup-msys2@v2 + if: steps.check_other.outputs.files_exists == 'false' with: update: true release: true install: base-devel git mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-libevent mingw-w64-x86_64-pcre2 mingw-w64-x86_64-freetype mingw-w64-x86_64-libpng mingw-w64-x86_64-bzip2 mingw-w64-x86_64-openssl mingw-w64-x86_64-mbedtls mingw-w64-x86_64-libsodium mingw-w64-x86_64-c-ares mingw-w64-x86_64-boost mingw-w64-x86_64-libmariadbclient unzip p7zip - - name: Rust + - name: Setup Rust uses: actions-rs/toolchain@v1 + if: steps.check_other.outputs.files_exists == 'false' with: toolchain: nightly profile: minimal - - name: MSBuild + - name: Setup MSBuild uses: microsoft/setup-msbuild@v1.0.3 with: vs-prerelease: true - - name: Checkout - uses: actions/checkout@v2 - with: - fetch-depth: 1 - - name: Build shell: pwsh run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9e4b431d..918a0b46 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,34 +9,67 @@ jobs: name: Build runs-on: windows-2022 steps: - - name: Go + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Checksum + shell: pwsh + run: | + $otherHash=$(.\Other\sha256.ps1) + $redirHash=$(.\Redirector\sha256.ps1) + $routeHash=$(.\RouteHelper\sha256.ps1) + + echo "OTHER_SHA256=$otherHash" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV + echo "REDIR_SHA256=$redirHash" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV + echo "ROUTE_SHA256=$routeHash" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV + + - name: Cache Other + uses: actions/cache@v2 + with: + key: Netch-${{ runner.os }}-Other-${{ env.OTHER_SHA256 }} + path: .\Other\release + + - name: Cache Redirector + uses: actions/cache@v2 + with: + key: Netch-${{ runner.os }}-Redirector-${{ env.REDIR_SHA256 }} + path: .\Redirector\bin + + - name: Cache RouteHelper + uses: actions/cache@v2 + with: + key: Netch-${{ runner.os }}-RouteHelper-${{ env.ROUTE_SHA256 }} + path: .\RouteHelper\bin + + - name: Check Other + id: check_other + uses: andstor/file-existence-action@v1 + with: + files: .\other\release\aiodns.bin + + - name: Setup Go uses: actions/setup-go@v2 + if: steps.check_other.outputs.files_exists == 'false' with: go-version: 1.17.2 - - name: C++ + - name: Setup C++ uses: msys2/setup-msys2@v2 + if: steps.check_other.outputs.files_exists == 'false' with: update: true release: true install: base-devel git mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-libevent mingw-w64-x86_64-pcre2 mingw-w64-x86_64-freetype mingw-w64-x86_64-libpng mingw-w64-x86_64-bzip2 mingw-w64-x86_64-openssl mingw-w64-x86_64-mbedtls mingw-w64-x86_64-libsodium mingw-w64-x86_64-c-ares mingw-w64-x86_64-boost mingw-w64-x86_64-libmariadbclient unzip p7zip - - name: Rust + - name: Setup Rust uses: actions-rs/toolchain@v1 + if: steps.check_other.outputs.files_exists == 'false' with: toolchain: nightly profile: minimal - - name: MSBuild - uses: microsoft/setup-msbuild@v1.0.3 - with: - vs-prerelease: true - - - name: Checkout - uses: actions/checkout@v2 - with: - fetch-depth: 1 - - name: Build shell: pwsh run: | @@ -52,7 +85,6 @@ jobs: shell: pwsh run: | $hash=(Get-FileHash Netch.7z -Algorithm SHA256).Hash.ToLower() - echo "$hash Netch.7z" echo "NETCH_SHA256=$hash" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV - name: Release diff --git a/Other/sha256.ps1 b/Other/sha256.ps1 new file mode 100644 index 00000000..313cffc6 --- /dev/null +++ b/Other/sha256.ps1 @@ -0,0 +1,17 @@ +Push-Location (Split-Path $MyInvocation.MyCommand.Path -Parent) + +$ms = [System.IO.MemoryStream]::new(); +$wr = [System.IO.StreamWriter]::new($ms); +Get-ChildItem -Path '.' -Directory | ForEach-Object { + $dirName=$_.Name + + Get-ChildItem -Path ".\$dirName" -File | ForEach-Object { + $fileName=$_.Name + + $wr.Write((Get-FileHash -Path ".\$dirName\$fileName" -Algorithm SHA256).Hash.ToLower()) + } +} +$ms.Position = 0 + +Write-Output (Get-FileHash -InputStream $ms).Hash.ToLower() +Pop-Location \ No newline at end of file diff --git a/Redirector/sha256.ps1 b/Redirector/sha256.ps1 new file mode 100644 index 00000000..3645671b --- /dev/null +++ b/Redirector/sha256.ps1 @@ -0,0 +1,13 @@ +Push-Location (Split-Path $MyInvocation.MyCommand.Path -Parent) + +$ms = [System.IO.MemoryStream]::new(); +$wr = [System.IO.StreamWriter]::new($ms); +Get-ChildItem -Path '.' -File | ForEach-Object { + $name=$_.Name + + $wr.Write((Get-FileHash -Path ".\$name" -Algorithm SHA256).Hash.ToLower()) +} +$ms.Position = 0 + +Write-Output (Get-FileHash -InputStream $ms).Hash.ToLower() +Pop-Location \ No newline at end of file diff --git a/RouteHelper/sha256.ps1 b/RouteHelper/sha256.ps1 new file mode 100644 index 00000000..3645671b --- /dev/null +++ b/RouteHelper/sha256.ps1 @@ -0,0 +1,13 @@ +Push-Location (Split-Path $MyInvocation.MyCommand.Path -Parent) + +$ms = [System.IO.MemoryStream]::new(); +$wr = [System.IO.StreamWriter]::new($ms); +Get-ChildItem -Path '.' -File | ForEach-Object { + $name=$_.Name + + $wr.Write((Get-FileHash -Path ".\$name" -Algorithm SHA256).Hash.ToLower()) +} +$ms.Position = 0 + +Write-Output (Get-FileHash -InputStream $ms).Hash.ToLower() +Pop-Location \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 95d3c748..e918a804 100644 --- a/build.ps1 +++ b/build.ps1 @@ -32,8 +32,12 @@ New-Item -ItemType Directory -Name "$OutputPath" | Out-Null .\deps.ps1 "$OutputPath" if ( -Not $? ) { exit $lastExitCode } -.\other\build.ps1 -if ( -Not $? ) { exit $lastExitCode } +if ( -Not (Test-Path '.\other\release\aiodns.bin') ) { + .\other\build.ps1 + if ( -Not $? ) { + exit $lastExitCode + } +} Write-Host Write-Host 'Building Netch' @@ -50,25 +54,31 @@ dotnet publish ` '.\Netch\Netch.csproj' if ( -Not $? ) { exit $lastExitCode } -Write-Host -Write-Host 'Building Redirector' -msbuild ` - -property:Configuration="$Configuration" ` - -property:Platform=x64 ` - '.\Redirector\Redirector.vcxproj' -if ( -Not $? ) { exit $lastExitCode } +if ( -Not (Test-Path ".\Redirector\bin\$Configuration\Redirector.bin" ) ) { + Write-Host + Write-Host 'Building Redirector' -Write-Host -Write-Host 'Building RouteHelper' -msbuild ` - -property:Configuration="$Configuration" ` - -property:Platform=x64 ` - '.\RouteHelper\RouteHelper.vcxproj' -if ( -Not $? ) { exit $lastExitCode } + msbuild ` + -property:Configuration="$Configuration" ` + -property:Platform=x64 ` + '.\Redirector\Redirector.vcxproj' + if ( -Not $? ) { exit $lastExitCode } +} -cp -Force '.\other\release\*.bin' "$OutputPath\bin" -cp -Force '.\other\release\*.dll' "$OutputPath\bin" -cp -Force '.\other\release\*.exe' "$OutputPath\bin" +if ( -Not (Test-Path ".\RouteHelper\bin\$Configuration\RouteHelper.bin" ) ) { + Write-Host + Write-Host 'Building RouteHelper' + + msbuild ` + -property:Configuration="$Configuration" ` + -property:Platform=x64 ` + '.\RouteHelper\RouteHelper.vcxproj' + if ( -Not $? ) { exit $lastExitCode } +} + +cp -Force '.\Other\release\*.bin' "$OutputPath\bin" +cp -Force '.\Other\release\*.dll' "$OutputPath\bin" +cp -Force '.\Other\release\*.exe' "$OutputPath\bin" cp -Force ".\Redirector\bin\$Configuration\nfapi.dll" "$OutputPath\bin" cp -Force ".\Redirector\bin\$Configuration\Redirector.bin" "$OutputPath\bin" cp -Force ".\RouteHelper\bin\$Configuration\RouteHelper.bin" "$OutputPath\bin" diff --git a/deps.ps1 b/deps.ps1 index b2895f51..7a5baea8 100644 --- a/deps.ps1 +++ b/deps.ps1 @@ -12,17 +12,6 @@ New-Item -ItemType Directory -Name 'bin' | Out-Null New-Item -ItemType Directory -Name 'mode' | Out-Null New-Item -ItemType Directory -Name 'i18n' | Out-Null -# Get-ChildItem -Path '..\scripts\deps\main' -File | ForEach-Object { -# $name=$_.Name - -# Write-Host "Executing $name" -# & "..\scripts\deps\base\$name" -# if ( -Not $? ) { -# Pop-Location -# exit $lastExitCode -# } -# } - Get-ChildItem -Path '..\scripts\deps' -File | ForEach-Object { $name=$_.Name diff --git a/scripts/deps/main/netch-data.ps1 b/scripts/deps/main/netch-data.ps1 deleted file mode 100644 index 64bbda39..00000000 --- a/scripts/deps/main/netch-data.ps1 +++ /dev/null @@ -1,14 +0,0 @@ -$name="data.zip" -$address="https://github.com/netchx/netch-data/archive/refs/heads/main.zip" - -..\scripts\download.ps1 $name $address -if (-Not $?) { exit $lastExitCode } - -..\scripts\extract.ps1 $name "bin" -if (-Not $?) { exit $lastExitCode } - -Copy-Item -Recurse -Force .\netch-data-main\* .\bin - -Remove-Item -Force $name -Remove-Item -Recurse -Force netch-data-main -exit 0 \ No newline at end of file diff --git a/scripts/deps/main/netch-i18n.ps1 b/scripts/deps/main/netch-i18n.ps1 deleted file mode 100644 index cc404cfa..00000000 --- a/scripts/deps/main/netch-i18n.ps1 +++ /dev/null @@ -1,14 +0,0 @@ -$name="i18n.zip" -$address="https://github.com/netchx/netch-i18n/archive/refs/heads/main.zip" - -..\scripts\download.ps1 $name $address -if (-Not $?) { exit $lastExitCode } - -..\scripts\extract.ps1 $name "i18n" -if (-Not $?) { exit $lastExitCode } - -Copy-Item -Recurse -Force .\netch-i18n-main\* .\i18n - -Remove-Item -Force $name -Remove-Item -Recurse -Force netch-i18n-main -exit 0 \ No newline at end of file diff --git a/scripts/deps/main/netch-mode.ps1 b/scripts/deps/main/netch-mode.ps1 deleted file mode 100644 index 20921f59..00000000 --- a/scripts/deps/main/netch-mode.ps1 +++ /dev/null @@ -1,14 +0,0 @@ -$name="mode.zip" -$address="https://github.com/netchx/netch-mode/archive/refs/heads/main.zip" - -..\scripts\download.ps1 $name $address -if (-Not $?) { exit $lastExitCode } - -..\scripts\extract.ps1 $name "mode" -if (-Not $?) { exit $lastExitCode } - -Copy-Item -Recurse -Force .\netch-mode-main\* .\mode - -Remove-Item -Force $name -Remove-Item -Recurse -Force netch-mode-main -exit 0 \ No newline at end of file