diff --git a/dist/versions.js b/dist/versions.js index c5a7ae6..f01d5ea 100644 --- a/dist/versions.js +++ b/dist/versions.js @@ -38,11 +38,10 @@ async function selectBranch(branch) { throw new Error(`Branch ${branch} not found`); } async function selectPr(pr) { - var _a; const versions = await git_1.lsRemote(); if (pr in versions.pull) { const prheads = versions.pull[pr]; - const sha = (_a = prheads.merge) !== null && _a !== void 0 ? _a : prheads.head; + const sha = prheads.head; if (sha) { return new VersionImpl(`#${pr}`, sha, 'pull', `pull request #${pr}`); } diff --git a/dist/win-install.js b/dist/win-install.js index fe1c8e0..ef85613 100644 --- a/dist/win-install.js +++ b/dist/win-install.js @@ -7,27 +7,30 @@ const toolCache = require("@actions/tool-cache"); const os = require("os"); const path = require("path"); const semver = require("semver"); +function getInstallerUrl(version) { + const ver = version.version; + if (version.type === 'heads') { + // we only use appveyor ci artifacts for branch version + const arch = os.arch() === 'x64' ? 'x64' : 'x86'; + return `https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=${ver}&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+${arch}`; + } + else if (version.type === 'pull') { + throw new Error('PR builds for windows is not supported'); + } + else { + // we cannot use appveyor ci artifacts, the old version links may be broken. + const arch = os.arch() === 'x64' ? 'win64' : 'win32'; + return semver.gt(ver, '2.2.6') + ? `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.${arch}.exe` + : `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.exe`; + } +} async function winInstall(version) { const ver = version.version; let toolDir = toolCache.find('xmake', ver); if (!toolDir) { const installer = await core.group(`download xmake ${version}`, async () => { - let url = ''; - if (version.type === 'heads') { - // we only use appveyor ci artifacts for branch version - const arch = os.arch() === 'x64' ? 'x64' : 'x86'; - url = `https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=${ver}&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+${arch}`; - } - else if (version.type === 'pull') { - throw new Error('PR builds for windows is not supported'); - } - else { - // we cannot use appveyor ci artifacts, the old version links may be broken. - const arch = os.arch() === 'x64' ? 'win64' : 'win32'; - url = semver.gt(ver, '2.2.6') - ? `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.${arch}.exe` - : `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.exe`; - } + const url = getInstallerUrl(version); core.info(`downloading from ${url}`); const file = await toolCache.downloadTool(url); const exe = path.format({ ...path.parse(file), ext: '.exe', base: undefined }); diff --git a/src/git.ts b/src/git.ts index c058651..3571c64 100644 --- a/src/git.ts +++ b/src/git.ts @@ -8,9 +8,22 @@ function makeOpt(ref: string): { cwd: string } { } export type RefDic = { + /** branches */ heads: Record; + /** tags */ tags: Record; - pull: Record; + /** pull requests */ + pull: Record< + number, + { + /** the current state of the pull request */ + head: string; + /** the current branch we're merging onto */ + base?: string; + /** merge result */ + merge?: string; + } + >; }; export async function lsRemote(): Promise { diff --git a/src/versions.ts b/src/versions.ts index db69ec6..e315560 100644 --- a/src/versions.ts +++ b/src/versions.ts @@ -30,7 +30,7 @@ async function selectPr(pr: number): Promise { const versions = await lsRemote(); if (pr in versions.pull) { const prheads = versions.pull[pr]; - const sha = prheads.merge ?? prheads.head; + const sha = prheads.head; if (sha) { return new VersionImpl(`#${pr}`, sha, 'pull', `pull request #${pr}`); } diff --git a/src/win-install.ts b/src/win-install.ts index 2507db0..ee45fa6 100644 --- a/src/win-install.ts +++ b/src/win-install.ts @@ -7,25 +7,29 @@ import * as path from 'path'; import * as semver from 'semver'; import { Version } from './versions'; +function getInstallerUrl(version: Version): string { + const ver = version.version; + if (version.type === 'heads') { + // we only use appveyor ci artifacts for branch version + const arch = os.arch() === 'x64' ? 'x64' : 'x86'; + return `https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=${ver}&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+${arch}`; + } else if (version.type === 'pull') { + throw new Error('PR builds for windows is not supported'); + } else { + // we cannot use appveyor ci artifacts, the old version links may be broken. + const arch = os.arch() === 'x64' ? 'win64' : 'win32'; + return semver.gt(ver, '2.2.6') + ? `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.${arch}.exe` + : `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.exe`; + } +} + export async function winInstall(version: Version): Promise { const ver = version.version; let toolDir = toolCache.find('xmake', ver); if (!toolDir) { const installer = await core.group(`download xmake ${version}`, async () => { - let url = ''; - if (version.type === 'heads') { - // we only use appveyor ci artifacts for branch version - const arch = os.arch() === 'x64' ? 'x64' : 'x86'; - url = `https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=${ver}&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+${arch}`; - } else if (version.type === 'pull') { - throw new Error('PR builds for windows is not supported'); - } else { - // we cannot use appveyor ci artifacts, the old version links may be broken. - const arch = os.arch() === 'x64' ? 'win64' : 'win32'; - url = semver.gt(ver, '2.2.6') - ? `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.${arch}.exe` - : `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.exe`; - } + const url = getInstallerUrl(version); core.info(`downloading from ${url}`); const file = await toolCache.downloadTool(url); const exe = path.format({ ...path.parse(file), ext: '.exe', base: undefined });