From e265cb43a8362fbba4159b9450da5c15458a2931 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sat, 15 Aug 2020 14:49:58 +0800 Subject: [PATCH] refactor build steps --- .github/workflows/Publish.yml | 10 ++- build.ps1 | 143 ---------------------------------- download-nano.ps1 | 7 ++ 3 files changed, 15 insertions(+), 145 deletions(-) delete mode 100644 build.ps1 create mode 100644 download-nano.ps1 diff --git a/.github/workflows/Publish.yml b/.github/workflows/Publish.yml index 76ab603..e8251b9 100644 --- a/.github/workflows/Publish.yml +++ b/.github/workflows/Publish.yml @@ -14,9 +14,15 @@ jobs: uses: actions/checkout@v2 - name: Install dependencies run: yarn - - name: Build - run: ./build.ps1 + - name: Download nano + run: ./download-nano.ps1 shell: pwsh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Build + run: ./nano + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Publish run: ./publish.ps1 shell: pwsh diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index 04efcd3..0000000 --- a/build.ps1 +++ /dev/null @@ -1,143 +0,0 @@ -Install-Module powershell-yaml -Force - -function Get-Trans { - param ( - # Plugin name - [Parameter(Mandatory = $false)] - [string] - $Plugin, - - # L10n key - [Parameter(Mandatory)] - [string] - $Key, - - # Language - [Parameter(Mandatory)] - [string] - $Lang - ) - - process { - $realKey = $Key.Split("::")[1] - $segment = $realKey.Split(".") - $head = $segment[0] - $filePath = if ($Plugin) { - "./plugins/$Plugin/lang/$Lang/$head.yml" - } - else { - "./lang/$Lang/$head.yml" - } - $obj = Get-Content $filePath -Raw | ConvertFrom-Yaml - - $temp = "" - for ($i = 0; $i -lt $segment.Count; $i++) { - if ($i -eq 0) { - continue - } - - if ($obj[$segment[$i]]) { - $temp = $obj[$segment[$i]] - } - else { - return $Key - } - } - - return $temp - } -} - -Write-Host 'Marketplace Builder' -$env:NODE_ENV = 'production' - -git clone "https://github.com/bs-community/plugins-dist.git" .dist -$registry = Get-Content '.dist/registry_zh_CN.json' | ConvertFrom-Json -$packages = $registry.packages -$plugins = Get-ChildItem -Path ./plugins -Directory | ForEach-Object { $_.Name } - -yarn build - -[PSCustomObject[]]$updated = @() - -foreach ($plugin in $plugins) { - Set-Location "./plugins/$plugin" - $manifest = Get-Content "package.json" | ConvertFrom-Json - $version = $manifest.version - - if ($packages | Where-Object { $_.name -eq $plugin -and $_.version -eq $version }) { - Set-Location '../../' - continue - } - - $updated += @{ - name = if ($manifest.title.Contains('::')) { - Get-Trans -Key $manifest.title -Lang zh_CN - } - else { - $manifest.title - } - version = $manifest.version - } - - Write-Host "[$plugin] Bump to $version" - - if (Test-Path 'node_modules') { - Remove-Item 'node_modules' -Recurse -Force - } - if (Test-Path '.gitignore') { - Remove-Item '.gitignore' -Force - } - Get-ChildItem ./assets -Recurse | ForEach-Object { - if ($_.Name.EndsWith('.ts')) { - Remove-Item $_ - } - } - - if (Test-Path 'composer.json') { - composer install - Remove-Item 'composer.json' -Force - Remove-Item 'composer.lock' -Force - } - - Set-Location '..' - - zip -9 -r "../.dist/${plugin}_$version.zip" $plugin - Set-Location '..' -} -ConvertTo-Json $updated | Out-File -FilePath 'updated.json' - -foreach ($lang in 'en', 'zh_CN') { - $packages = $plugins | ForEach-Object { - $manifest = Get-Content "./plugins/${_}/package.json" | ConvertFrom-Json - $name = $manifest.name - $version = $manifest.version - $url = "https://cdn.jsdelivr.net/gh/bs-community/plugins-dist/${name}_$version.zip" - [PSCustomObject]@{ - name = $name - version = $version - title = if ($manifest.title.Contains('::')) { - Get-Trans -Plugin $_ -Key $manifest.title -Lang $lang - } - else { - $manifest.title - } - description = if ($manifest.title.Contains('::')) { - Get-Trans -Plugin $_ -Key $manifest.description -Lang $lang - } - else { - $manifest.description - } - author = $manifest.author - require = $manifest.require - dist = [PSCustomObject]@{ - type = 'zip' - url = $url - shasum = (Get-FileHash -Path ".dist/${name}_$version.zip" -Algorithm SHA256).Hash.ToLower() - } - } - } - $registry.packages = $packages - ConvertTo-Json $registry -Depth 10 | Out-File -FilePath ".dist/registry_$lang.json" -} -Copy-Item -Path '.dist/registry_zh_CN.json' -Destination '.dist/registry.json' diff --git a/download-nano.ps1 b/download-nano.ps1 new file mode 100644 index 0000000..251aca9 --- /dev/null +++ b/download-nano.ps1 @@ -0,0 +1,7 @@ +$token = 'Bearer ' + $env:GITHUB_TOKEN +$headers = @{"authorization"=$token} +$nanoRelease = (Invoke-WebRequest 'https://api.github.com/repos/bs-community/nano/releases/latest' -Headers $headers).Content | ConvertFrom-Json +$nanoBinUrl = ((Invoke-WebRequest $nanoRelease.assets_url -Headers $headers).Content | ConvertFrom-Json).browser_download_url + +bash -c "curl -fSL $nanoBinUrl --header 'authorization: $token' -o nano" +chmod +x ./nano