Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions __tests__/dagger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ describe('install', () => {
expect(fs.existsSync(daggerBin)).toBe(true);
}, 100000);

it('acquires latest 0.1 version', async () => {
const daggerBin = await dagger.install('0.1');
console.log(daggerBin);
expect(fs.existsSync(daggerBin)).toBe(true);
}, 100000);

it('acquires 0.1.0-alpha.9 version of Dagger', async () => {
const daggerBin = await dagger.install('0.1.0-alpha.9');
console.log(daggerBin);
Expand Down
13 changes: 7 additions & 6 deletions dist/index.js

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

14 changes: 8 additions & 6 deletions src/dagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const osPlat: string = os.platform();
const osArch: string = os.arch();

export async function install(version: string): Promise<string> {
if (version == 'latest') {
version = await getLatestVersion();
}
version = await getVersionMapping(version);
version = version.replace(/^v/, '');

const downloadUrl: string = util.format('%s/releases/%s/%s', s3URL, version, getFilename(version));
Expand All @@ -38,17 +36,21 @@ export async function install(version: string): Promise<string> {
return path.join(cachePath, osPlat == 'win32' ? 'dagger.exe' : 'dagger');
}

async function getLatestVersion(): Promise<string> {
async function getVersionMapping(version: string): Promise<string> {
const _http = new http.HttpClient('dagger-for-github');
const res = await _http.get(`${s3URL}/latest_version`);
const res = await _http.get(`${s3URL}/versions/${version}`);
if (res.message.statusCode != 200) {
return version;
}

return await res.readBody().then(body => {
return body.trim();
});
}

const getFilename = (version: string): string => {
const platform: string = osPlat == 'win32' ? 'windows' : osPlat;
const arch: string = osArch == 'x64' ? 'amd64' : 'i386';
const arch: string = osArch == 'x64' ? 'amd64' : osArch;
const ext: string = osPlat == 'win32' ? '.zip' : '.tar.gz';
return util.format('dagger_v%s_%s_%s%s', version, platform, arch, ext);
};