Skip to content

Commit

Permalink
change tar type
Browse files Browse the repository at this point in the history
  • Loading branch information
crcn committed Sep 26, 2022
1 parent 613f787 commit d7a6893
Show file tree
Hide file tree
Showing 4 changed files with 272 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
RUSTTARGET: ${{ matrix.target }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TOOLCHAIN_VERSION: nightly
ARCHIVE_TYPES: tar.gz
# UPLOAD_MODE: none
# - name: Upload artifact
# uses: actions/upload-artifact@v3
Expand Down
5 changes: 5 additions & 0 deletions libs/releases/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"author": "",
"license": "ISC",
"dependencies": {
"fs-extra": "^10.1.0",
"got": "11.8.5",
"node-fetch": "^2.6.7"
},
"devDependencies": {
"@types/fs-extra": "^9.0.13"
}
}
76 changes: 68 additions & 8 deletions libs/releases/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,72 @@
import fetch from "node-fetch";
const pkg = require("../../package.json");
import got from "got";
import fs from "fs";
import fsa from "fs-extra";
import * as os from "node:os";
const pkg = require("../package.json");
import path from "path";

export const downloadRelease = async () => {
const releases = await fetch(
`https://api.github.com/repos/paperclip-ui/paperclip/releases`
).then((response) => response.json());
// paperclip_test2_x86_64-pc-windows-gnu.zip

console.log(releases);
const OS_VENDOR = {
win32: "windows",
darwin: "apple",
linux: "linux",
}[os.platform as any];

export const downloadRelease = async (releaseDir: string) => {
const currentVersion = extractVersionParts(pkg.version);
const releases = (await got
.get(`https://api.github.com/repos/paperclip-ui/paperclip/releases`)
.json()) as any[];

const matchingRelease =
releases
.filter((release) => {
const releaseVersion = extractVersionParts(release.tag_name);
return (
releaseVersion.major === currentVersion.major &&
release.minor == releaseVersion.minor
);
})
.sort((a, b) => {
return Number(extractVersionParts(a.tag_name).patch) >
Number(extractVersionParts(b.tag_name).patch)
? -1
: 1;
})[0] || releases[0];

if (!matchingRelease) {
throw new Error(
`No matching release for ${currentVersion.major}.${currentVersion.major}`
);
}

const asset = matchingRelease.assets.find((asset) => {
return asset.name.includes(OS_VENDOR);
});

if (!asset) {
throw new Error(`${os.platform} is not currently supported`);
}

try {
fsa.mkdirSync(releaseDir);
} catch (e) {}
const zipPath = path.join(
releaseDir,
path.basename(asset.browser_download_url)
);

(await got.get(asset.browser_download_url)).pipe(
fs.createWriteStream(zipPath)
);

console.log(zipPath);
};

const extractVersionParts = (version: string) => {
const [major, minor, patch] = version.split(".");
return { major, minor, patch };
};

downloadRelease();
downloadRelease("/tmp/releases");
Loading

0 comments on commit d7a6893

Please sign in to comment.