Skip to content

Commit

Permalink
Merge pull request #27 from radu-matei/tarxz
Browse files Browse the repository at this point in the history
Add support for .tgz and .tar.xz archives
  • Loading branch information
Radu M authored Jun 4, 2021
2 parents adde765 + e861c57 commit 94e10ec
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 10 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
pathInArchive: "windows-amd64/helm.exe",
}
steps:
- uses: engineerd/configurator@v0.0.7
- uses: engineerd/configurator@v0.0.8
with:
name: ${{ matrix.config.name }}
url: ${{ matrix.config.url }}
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
pathInArchive: "windows-amd64/helm.exe",
}
steps:
- uses: engineerd/configurator@v0.0.7
- uses: engineerd/configurator@v0.0.8
with:
name: ${{ matrix.config.name }}
pathInArchive: ${{ matrix.config.pathInArchive }}
Expand All @@ -138,7 +138,7 @@ jobs:
kind:
runs-on: ubuntu-latest
steps:
- uses: engineerd/configurator@v0.0.7
- uses: engineerd/configurator@v0.0.8
with:
name: "kind"
fromGitHubReleases: "true"
Expand All @@ -165,7 +165,7 @@ jobs:
kind:
runs-on: ubuntu-latest
steps:
- uses: engineerd/configurator@v0.0.7
- uses: engineerd/configurator@v0.0.8
with:
name: "kind"
url: "https://github.com/kubernetes-sigs/kind/releases/download/v0.8.1/kind-linux-amd64"
Expand All @@ -185,7 +185,7 @@ jobs:
kind:
runs-on: ubuntu-latest
steps:
- uses: engineerd/configurator@v0.0.7
- uses: engineerd/configurator@v0.0.8
with:
name: "h3"
url: "https://get.helm.sh/helm-v3.3.0-linux-amd64.tar.gz"
Expand All @@ -206,7 +206,7 @@ jobs:
kind:
runs-on: windows-latest
steps:
- uses: engineerd/configurator@v0.0.7
- uses: engineerd/configurator@v0.0.8
with:
name: "h3.exe"
url: "https://get.helm.sh/helm-v3.3.0-windows-amd64.zip"
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "configurator",
"version": "0.0.7",
"version": "0.0.8",
"private": true,
"description": "A GitHub Action that configures statically compiled tools",
"main": "lib/main.js",
Expand Down
21 changes: 19 additions & 2 deletions src/configurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as path from "path";
import * as os from "os";
import { getTag } from "./release";
import Mustache from "mustache";
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from "uuid";

const NameInput: string = "name";
const URLInput: string = "url";
Expand Down Expand Up @@ -81,7 +81,10 @@ export class Configurator {
);

const rawVersion = tag.startsWith("v") ? tag.substr(1) : tag;
downloadURL = Mustache.render(this.urlTemplate, { version: tag, rawVersion: rawVersion });
downloadURL = Mustache.render(this.urlTemplate, {
version: tag,
rawVersion: rawVersion,
});
} else {
downloadURL = this.url;
}
Expand All @@ -105,6 +108,16 @@ export class Configurator {
await this.moveToPath(path.join(archivePath, this.pathInArchive));
break;

case ArchiveType.TarXz:
archivePath = await tc.extractTar(downloadPath, tempDir, "x");
await this.moveToPath(path.join(archivePath, this.pathInArchive));
break;

case ArchiveType.Tgz:
archivePath = await tc.extractTar(downloadPath, tempDir);
await this.moveToPath(path.join(archivePath, this.pathInArchive));
break;

case ArchiveType.Zip:
archivePath = await tc.extractZip(downloadPath, tempDir);
await this.moveToPath(path.join(archivePath, this.pathInArchive));
Expand Down Expand Up @@ -180,6 +193,8 @@ export class Configurator {

export function getArchiveType(downloadURL: string): ArchiveType {
if (downloadURL.endsWith(ArchiveType.TarGz)) return ArchiveType.TarGz;
if (downloadURL.endsWith(ArchiveType.TarXz)) return ArchiveType.TarXz;
if (downloadURL.endsWith(ArchiveType.Tgz)) return ArchiveType.Tgz;
if (downloadURL.endsWith(ArchiveType.Zip)) return ArchiveType.Zip;
if (downloadURL.endsWith(ArchiveType.SevenZ)) return ArchiveType.SevenZ;

Expand All @@ -205,6 +220,8 @@ export function binPath(): string {
export enum ArchiveType {
None = "",
TarGz = ".tar.gz",
TarXz = ".tar.xz",
Tgz = ".tgz",
Zip = ".zip",
SevenZ = ".7z",
}
Expand Down
54 changes: 54 additions & 0 deletions test/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ describe("test archive type", () => {
assert.equal(cfg.ArchiveType.TarGz, cfg.getArchiveType(c.url));
});

it("correctly chooses the TAR.XZ archive type", () => {
const archiveTypeTarInput = {
INPUT_NAME: "some-binary",
INPUT_PATHINARCHIVE: "some-path",
INPUT_URL:
"https://github.com/<some-repo>/releases/download/<release>/some-tar-archive.tar.xz",
};
for (const key in archiveTypeTarInput)
process.env[key] = archiveTypeTarInput[key];

let c = cfg.getConfig();
assert.equal(cfg.ArchiveType.TarXz, cfg.getArchiveType(c.url));
});

it("correctly chooses the ZIP archive type", () => {
const archiveTypeZipInput = {
INPUT_NAME: "some-binary",
Expand Down Expand Up @@ -116,6 +130,46 @@ describe("test URL download", async () => {
assert.equal(fs.existsSync(path.join(cfg.binPath(), c.name)), true);
});

it("correctly downloads .tar.xz files", async () => {
if (process.platform === "win32") {
// there seems to be an error with the tar utility on Windows - skipping the test for now
return;
}

const input = {
INPUT_URL:
"https://github.com/bytecodealliance/wasmtime/releases/download/v0.27.0/wasmtime-v0.27.0-x86_64-linux.tar.xz",
INPUT_NAME: "wasmtime",
INPUT_PATHINARCHIVE: "wasmtime-v0.27.0-x86_64-linux/wasmtime",
};
for (const key in input) process.env[key] = input[key];

let c = cfg.getConfig();
await c.configure();

assert.equal(fs.existsSync(path.join(cfg.binPath(), c.name)), true);
});

it("correctly downloads .tgz files", async () => {
if (process.platform === "win32") {
// there seems to be an error with the tar utility on Windows - skipping the test for now
return;
}

const input = {
INPUT_URL:
"https://github.com/vmware-tanzu/buildkit-cli-for-kubectl/releases/download/v0.1.3/linux-v0.1.3.tgz",
INPUT_NAME: "kubectl-buildkit",
INPUT_PATHINARCHIVE: "kubectl-buildkit",
};
for (const key in input) process.env[key] = input[key];

let c = cfg.getConfig();
await c.configure();

assert.equal(fs.existsSync(path.join(cfg.binPath(), c.name)), true);
});

it("correctly downloads .zip files", async () => {
const input = {
INPUT_URL: "https://get.helm.sh/helm-v3.0.0-beta.3-windows-amd64.zip",
Expand Down

0 comments on commit 94e10ec

Please sign in to comment.