Fix asset downloading during build (#185)

This commit is contained in:
Mikunj Varsani 2020-09-18 14:59:42 +10:00 committed by GitHub
parent 5157c767f5
commit fa83971353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 65 deletions

View File

@ -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

View File

@ -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'

3
.gitignore vendored
View File

@ -28,6 +28,7 @@ bin/*
.env
/downloads
downloads/*
!downloads/*.sh
dev-app-update.yml

View File

@ -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();

40
downloads/download-asset.sh Executable file
View File

@ -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"

View File

@ -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"]
}