From fa83971353e5afd4067eee08a1a86cbe883a3ad1 Mon Sep 17 00:00:00 2001 From: Mikunj Varsani Date: Fri, 18 Sep 2020 14:59:42 +1000 Subject: [PATCH] Fix asset downloading during build (#185) --- .github/workflows/build.yml | 18 ++++++++---- .github/workflows/release.yml | 14 +++++++-- .gitignore | 3 +- build/download-binaries.js | 54 ----------------------------------- downloads/download-asset.sh | 40 ++++++++++++++++++++++++++ quasar.conf.js | 11 +++++-- 6 files changed, 75 insertions(+), 65 deletions(-) delete mode 100644 build/download-binaries.js create mode 100755 downloads/download-asset.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 112ce62..10e438f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,28 +17,36 @@ jobs: - name: Checkout git repo uses: actions/checkout@v1 + # Read node version from `.nvmrc` file + - name: Read nvm rc + id: nvmrc + uses: browniebroke/read-nvmrc-action@v1 + - name: Install node uses: actions/setup-node@v1 with: - node-version: "11.9.0" + node-version: ${{ steps.nvmrc.outputs.node_version }} - name: Install dependencies run: npm install - name: Download lokid binaries - run: node ./build/download-binaries.js + run: ./download-asset.sh env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OS: ${{ runner.os }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash + working-directory: ./downloads - name: Extract zip binaries if: runner.os != 'Linux' - run: unzip latest.zip + run: unzip latest shell: bash working-directory: ./downloads - name: Extract xz binaries if: runner.os == 'Linux' - run: tar -xf latest.xz + run: tar -xf latest shell: bash working-directory: ./downloads diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f38c54d..8cd5679 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,18 +16,26 @@ jobs: - name: Checkout git repo uses: actions/checkout@v1 + # Read node version from `.nvmrc` file + - name: Read nvm rc + id: nvmrc + uses: browniebroke/read-nvmrc-action@v1 + - name: Install node uses: actions/setup-node@v1 with: - node-version: "11.9.0" + node-version: ${{ steps.nvmrc.outputs.node_version }} - name: Install dependencies run: npm install - name: Download lokid binaries - run: node ./build/download-binaries.js + run: ./download-asset.sh env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OS: ${{ runner.os }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash + working-directory: ./downloads - name: Extract zip binaries if: runner.os != 'Linux' diff --git a/.gitignore b/.gitignore index e3ab8b5..a25455d 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ bin/* .env -/downloads +downloads/* +!downloads/*.sh dev-app-update.yml diff --git a/build/download-binaries.js b/build/download-binaries.js deleted file mode 100644 index e2aa287..0000000 --- a/build/download-binaries.js +++ /dev/null @@ -1,54 +0,0 @@ -const axios = require("axios").default; -const fs = require("fs-extra"); -const path = require("path"); - -async function download() { - const { platform, env } = process; - const repoUrl = "https://api.github.com/repos/loki-project/loki-core/releases/latest"; - try { - const pwd = process.cwd(); - const downloadDir = path.join(pwd, "downloads"); - await fs.ensureDir(downloadDir); - - const headers = { - "Content-Type": "application/json", - "User-Agent": "Loki-Electron-Wallet" - }; - if (env.GH_TOKEN) { - headers.Authorisation = `Bearer ${env.GH_TOKEN}`; - } - - const { data } = await axios.get(repoUrl, { headers }); - const { name } = data; - console.log("Latest release: " + name); - - const url = (data.assets || []) - .map(asset => asset["browser_download_url"]) - .find(url => { - if (platform === "darwin") { - return url.includes("osx") || url.includes("mac"); - } else if (platform === "win32") { - return url.includes("win") || url.includes("windows"); - } - return url.includes("linux"); - }); - - if (!url) { - throw new Error("Download url not found for " + process); - } - console.log("Downloading binary at url: " + url); - - const extension = path.extname(url); - const filePath = path.join(downloadDir, "latest" + extension); - const { data: artifact } = await axios.get(url, { - responseType: "stream" - }); - artifact.pipe(fs.createWriteStream(filePath)); - console.log("Downloaded binary to: " + filePath); - } catch (err) { - console.error("Failed to download file: " + err); - process.exit(1); - } -} - -download(); diff --git a/downloads/download-asset.sh b/downloads/download-asset.sh new file mode 100755 index 0000000..34a8c68 --- /dev/null +++ b/downloads/download-asset.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Source from: https://github.com/houqp/download-release-assets-action + +set -e + +if [ -z "$OS" ]; then + echo "OS must be set" + exit 1 +fi + +if [ -z "$RENAME" ]; then + RENAME="latest" +fi + +REPO="loki-project/loki-core" +RELEASE="latest" + +if [ "$OS" == "Linux" ]; then + FILE_NAME_REGEX="linux" +elif [ "$OS" == "Windows" ]; then + FILE_NAME_REGEX="win" +elif [ "$OS" == "macOS" ]; then + FILE_NAME_REGEX="osx" +else + echo "OS must be Linux, Windows or macOS" + exit 1 +fi + + +ASSET_URL=$(curl -sL --fail \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + "https://api.github.com/repos/${REPO}/releases/${RELEASE}" \ + | jq -r ".assets | .[] | select(.name | test(\"${FILE_NAME_REGEX}\")) | .url") + +curl -sL --fail \ + -H "Accept: application/octet-stream" \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + -o "${RENAME}" \ + "$ASSET_URL" diff --git a/quasar.conf.js b/quasar.conf.js index 68a3131..5c0b89f 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -158,7 +158,8 @@ module.exports = function() { appId: "com.loki-project.electron-wallet", productName: "Loki Electron Wallet", - copyright: "Copyright © 2018-2019 Loki Project, 2018 Ryo Currency Project", + copyright: + "Copyright © 2018-2020 Loki Project, 2018 Ryo Currency Project", afterSign: "build/notarize.js", artifactName: "loki-electron-wallet-${version}-${os}.${ext}", publish: "github", @@ -192,7 +193,13 @@ module.exports = function() { allowToChangeInstallationDirectory: true }, - files: ["!build/*.js", "!.env", "!dev-app-update.yml"], + files: [ + "!build/*.js", + "!.env", + "!dev-app-update.yml", + "!downloads/**", + "!dist/**" + ], extraResources: ["bin"] }