From 493476522d601bf884464711d4ea0bddbe2493e1 Mon Sep 17 00:00:00 2001 From: Connection Refused Date: Sat, 16 Oct 2021 10:56:03 +0800 Subject: [PATCH] [GitHub CI] Update build.yml --- .github/workflows/build.yml | 31 +++++++++++++++++++------------ .github/workflows/release.yml | 31 +++++++++++++++++++------------ Redirector/sha256.ps1 | 13 ------------- RouteHelper/sha256.ps1 | 13 ------------- sha256.ps1 | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 50 deletions(-) delete mode 100644 Redirector/sha256.ps1 delete mode 100644 RouteHelper/sha256.ps1 create mode 100644 sha256.ps1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5b1da762..ed368439 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,34 +11,41 @@ jobs: with: fetch-depth: 1 - - name: Checksum + - name: Checksum Other shell: pwsh run: | - $otherHash=$(.\Other\sha256.ps1) - $redirHash=$(.\Redirector\sha256.ps1) - $routeHash=$(.\RouteHelper\sha256.ps1) + echo "OTHER_SHA256=$(.\Other\sha256.ps1)" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV - 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: Checksum Redirector + shell: pwsh + run: | + echo "REDIRECTOR_SHA256=$(.\sha256.ps1 .\Redirector)" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV + + - name: Checksum RouteHelper + shell: pwsh + run: | + echo "ROUTEHELPER_SHA256=$(.\sha256.ps1 .\RouteHelper)" | 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 + path: | + .\Other\release - name: Cache Redirector uses: actions/cache@v2 with: - key: Netch-${{ runner.os }}-Redirector-${{ env.REDIR_SHA256 }} - path: .\Redirector\bin + key: Netch-${{ runner.os }}-Redirector-${{ env.REDIRECTOR_SHA256 }} + path: | + .\Redirector\bin - name: Cache RouteHelper uses: actions/cache@v2 with: - key: Netch-${{ runner.os }}-RouteHelper-${{ env.ROUTE_SHA256 }} - path: .\RouteHelper\bin + key: Netch-${{ runner.os }}-RouteHelper-${{ env.ROUTEHELPER_SHA256 }} + path: | + .\RouteHelper\bin - name: Check Other id: check_other diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 918a0b46..72580d9a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,34 +14,41 @@ jobs: with: fetch-depth: 1 - - name: Checksum + - name: Checksum Other shell: pwsh run: | - $otherHash=$(.\Other\sha256.ps1) - $redirHash=$(.\Redirector\sha256.ps1) - $routeHash=$(.\RouteHelper\sha256.ps1) + echo "OTHER_SHA256=$(.\Other\sha256.ps1)" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV - 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: Checksum Redirector + shell: pwsh + run: | + echo "REDIRECTOR_SHA256=$(.\sha256.ps1 .\Redirector)" | Out-File -Append -Encoding UTF8 -FilePath $Env:GITHUB_ENV + + - name: Checksum RouteHelper + shell: pwsh + run: | + echo "ROUTEHELPER_SHA256=$(.\sha256.ps1 .\RouteHelper)" | 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 + path: | + .\Other\release - name: Cache Redirector uses: actions/cache@v2 with: - key: Netch-${{ runner.os }}-Redirector-${{ env.REDIR_SHA256 }} - path: .\Redirector\bin + key: Netch-${{ runner.os }}-Redirector-${{ env.REDIRECTOR_SHA256 }} + path: | + .\Redirector\bin - name: Cache RouteHelper uses: actions/cache@v2 with: - key: Netch-${{ runner.os }}-RouteHelper-${{ env.ROUTE_SHA256 }} - path: .\RouteHelper\bin + key: Netch-${{ runner.os }}-RouteHelper-${{ env.ROUTEHELPER_SHA256 }} + path: | + .\RouteHelper\bin - name: Check Other id: check_other diff --git a/Redirector/sha256.ps1 b/Redirector/sha256.ps1 deleted file mode 100644 index 3645671b..00000000 --- a/Redirector/sha256.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 3645671b..00000000 --- a/RouteHelper/sha256.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -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/sha256.ps1 b/sha256.ps1 new file mode 100644 index 00000000..c962fe64 --- /dev/null +++ b/sha256.ps1 @@ -0,0 +1,35 @@ +param ( + [string] + $Location = '' +) + +Push-Location $Location + +$ms = [System.IO.MemoryStream]::new(); +$wr = [System.IO.StreamWriter]::new($ms); + +function Scan { + param ( + [string] + $path = '' + ) + + foreach ( $item in ( Get-ChildItem -Path $path ) ) { + $name = $item.Name + + if ( Test-Path -Path ".\$path\$name" -PathType Container ) { + Scan -Path ".\$path\$name" + continue + } + + if ( Test-Path -Path ".\$path\$name" -PathType Leaf ) { + $wr.Write((Get-FileHash -Path ".\$path\$name" -Algorithm SHA256).Hash.ToLower()) + } + } +} + +Scan -Path '.' +Write-Output (Get-FileHash -InputStream $ms).Hash.ToLower() + +Pop-Location +exit 0 \ No newline at end of file