diff --git a/__tests__/dagger.test.ts b/__tests__/dagger.test.ts index 5632504..70918ee 100644 --- a/__tests__/dagger.test.ts +++ b/__tests__/dagger.test.ts @@ -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); diff --git a/dist/index.js b/dist/index.js index 39d2204..d0cf58d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -101,9 +101,7 @@ const osPlat = os.platform(); const osArch = os.arch(); function install(version) { return __awaiter(this, void 0, void 0, function* () { - if (version == 'latest') { - version = yield getLatestVersion(); - } + version = yield getVersionMapping(version); version = version.replace(/^v/, ''); const downloadUrl = util.format('%s/releases/%s/%s', s3URL, version, getFilename(version)); core.info(`Downloading ${downloadUrl}`); @@ -126,10 +124,13 @@ function install(version) { }); } exports.install = install; -function getLatestVersion() { +function getVersionMapping(version) { return __awaiter(this, void 0, void 0, function* () { const _http = new http.HttpClient('dagger-for-github'); - const res = yield _http.get(`${s3URL}/latest_version`); + const res = yield _http.get(`${s3URL}/versions/${version}`); + if (res.message.statusCode != 200) { + return version; + } return yield res.readBody().then(body => { return body.trim(); }); @@ -137,7 +138,7 @@ function getLatestVersion() { } const getFilename = (version) => { const platform = osPlat == 'win32' ? 'windows' : osPlat; - const arch = osArch == 'x64' ? 'amd64' : 'i386'; + const arch = osArch == 'x64' ? 'amd64' : osArch; const ext = osPlat == 'win32' ? '.zip' : '.tar.gz'; return util.format('dagger_v%s_%s_%s%s', version, platform, arch, ext); }; diff --git a/src/dagger.ts b/src/dagger.ts index 39be0f4..4be48cd 100644 --- a/src/dagger.ts +++ b/src/dagger.ts @@ -10,9 +10,7 @@ const osPlat: string = os.platform(); const osArch: string = os.arch(); export async function install(version: string): Promise { - 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)); @@ -38,9 +36,13 @@ export async function install(version: string): Promise { return path.join(cachePath, osPlat == 'win32' ? 'dagger.exe' : 'dagger'); } -async function getLatestVersion(): Promise { +async function getVersionMapping(version: string): Promise { 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(); }); @@ -48,7 +50,7 @@ async function getLatestVersion(): Promise { 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); };