Skip to content

Commit

Permalink
Merge branch 'master' into v0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihails Strasuns committed Sep 17, 2019
2 parents 835e55a + 9a5b454 commit 3ca55b2
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 162 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
name: Test the action
on: [push]
on: [push, pull_request]

jobs:
test:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- run: npm install
- run: npm test

verify:
name: Verify install
strategy:
max-parallel: 4
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
dc: [dmd-2.088.0, ldc-1.17.0]
dc: [dmd-2.088.0, ldc-1.17.0, ldc-latest, ldc-beta, dmd-latest, dmd-beta, '']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master

- name: Install action dependencies
if: github.ref == 'master'
if: (! startsWith(github.ref, 'v'))
run: npm install --production

- name: Install D compiler
Expand Down
51 changes: 0 additions & 51 deletions __tests__/main.test.ts

This file was deleted.

151 changes: 95 additions & 56 deletions lib/compiler.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,104 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
function compiler(description) {
const matches = description.match(/(\w+)-(.+)/);
if (!matches)
throw new Error("invalid compiler string: " + description);
switch (matches[1]) {
case "dmd": return dmd(matches[2]);
case "ldc": return ldc(matches[2]);
default: throw new Error("unrecognized compiler: " + matches[1]);
}
return __awaiter(this, void 0, void 0, function* () {
const matches = description.match(/(\w+)-(.+)/);
if (!matches)
throw new Error("invalid compiler string: " + description);
switch (matches[1]) {
case "dmd": return dmd(matches[2]);
case "ldc": return yield ldc(matches[2]);
default: throw new Error("unrecognized compiler: " + matches[1]);
}
});
}
exports.compiler = compiler;
function dmd(version) {
if (!version.match(/2.(\d+).(\d+)/))
throw new Error("unrecognized DMD version:" + version);
switch (process.platform) {
case "win32": return {
name: "dmd",
version: version,
url: `http://downloads.dlang.org/releases/2.x/${version}/dmd.${version}.windows.7z`,
binpath: "\\dmd2\\windows\\bin"
};
case "linux": return {
name: "dmd",
version: version,
url: `http://downloads.dlang.org/releases/2.x/${version}/dmd.${version}.linux.tar.xz`,
binpath: "/dmd2/linux/bin64"
};
case "darwin": return {
name: "dmd",
version: version,
url: `http://downloads.dlang.org/releases/2.x/${version}/dmd.${version}.osx.tar.xz`,
binpath: "/dmd2/osx/bin/"
};
default:
throw new Error("unsupported platform: " + process.platform);
}
return __awaiter(this, void 0, void 0, function* () {
let beta = false;
switch (version) {
case "latest":
version = yield utils_1.body_as_text("http://downloads.dlang.org/releases/LATEST");
break;
case "beta":
version = yield utils_1.body_as_text("http://downloads.dlang.org/pre-releases/LATEST");
beta = true;
break;
}
const matches = version.match(/(2.\d+.\d+)(-.+)?/);
if (!matches)
throw new Error("unrecognized DMD version: " + version);
const base_url = beta ?
`http://downloads.dlang.org/pre-releases/2.x/${matches[1]}/dmd.${version}`
: `http://downloads.dlang.org/releases/2.x/${version}/dmd.${version}`;
switch (process.platform) {
case "win32": return {
name: "dmd",
version: version,
url: `${base_url}.windows.7z`,
binpath: "\\dmd2\\windows\\bin"
};
case "linux": return {
name: "dmd",
version: version,
url: `${base_url}.linux.tar.xz`,
binpath: "/dmd2/linux/bin64"
};
case "darwin": return {
name: "dmd",
version: version,
url: `${base_url}.osx.tar.xz`,
binpath: "/dmd2/osx/bin/"
};
default:
throw new Error("unsupported platform: " + process.platform);
}
});
}
function ldc(version) {
if (!version.match(/(\d+).(\d+).(\d+)/))
throw new Error("unrecognized DMD version:" + version);
switch (process.platform) {
case "win32": return {
name: "ldc2",
version: version,
url: `https://github.com/ldc-developers/ldc/releases/download/v${version}/ldc2-${version}-windows-multilib.7z`,
binpath: `\\ldc2-${version}-windows-multilib\\bin`
};
case "linux": return {
name: "ldc2",
version: version,
url: `https://github.com/ldc-developers/ldc/releases/download/v${version}/ldc2-${version}-linux-x86_64.tar.xz`,
binpath: `/ldc2-${version}-linux-x86_64/bin`
};
case "darwin": return {
name: "ldc2",
version: version,
url: `https://github.com/ldc-developers/ldc/releases/download/v${version}/ldc2-${version}-osx-x86_64.tar.xz`,
binpath: `/ldc2-${version}-osx-x86_64/bin`
};
default:
throw new Error("unsupported platform: " + process.platform);
}
return __awaiter(this, void 0, void 0, function* () {
switch (version) {
case "latest":
version = yield utils_1.body_as_text("https://ldc-developers.github.io/LATEST");
break;
case "beta":
version = yield utils_1.body_as_text("https://ldc-developers.github.io/LATEST_BETA");
break;
}
if (!version.match(/(\d+).(\d+).(\d+)/))
throw new Error("unrecognized LDC version: " + version);
const base_url = `https://github.com/ldc-developers/ldc/releases/download/v${version}/ldc2-${version}`;
switch (process.platform) {
case "win32": return {
name: "ldc2",
version: version,
url: `${base_url}-windows-multilib.7z`,
binpath: `\\ldc2-${version}-windows-multilib\\bin`
};
case "linux": return {
name: "ldc2",
version: version,
url: `${base_url}-linux-x86_64.tar.xz`,
binpath: `/ldc2-${version}-linux-x86_64/bin`
};
case "darwin": return {
name: "ldc2",
version: version,
url: `${base_url}-osx-x86_64.tar.xz`,
binpath: `/ldc2-${version}-osx-x86_64/bin`
};
default:
throw new Error("unsupported platform: " + process.platform);
}
});
}
6 changes: 2 additions & 4 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function run() {
try {
if (process.arch != "x64")
throw new Error("Only x64 arch is supported by all platforms");
const input = core.getInput('compiler');
const descr = compiler_1.compiler(input);
const input = core.getInput('compiler') || "dmd-latest";
const descr = yield compiler_1.compiler(input);
console.log(`Enabling ${input}`);
let cached = tc.find('dc', input);
if (cached) {
Expand All @@ -34,9 +34,7 @@ function run() {
else {
console.log(`Downloading ${descr.url}`);
const archive = yield tc.downloadTool(descr.url);
core.debug("downloaded");
const dc_path = yield extract(archive);
core.debug("extracted");
cached = yield tc.cacheDir(dc_path, 'dc', input);
}
core.addPath(cached + descr.binpath);
Expand Down
26 changes: 26 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const httpm = __importStar(require("typed-rest-client/HttpClient"));
function body_as_text(url) {
return __awaiter(this, void 0, void 0, function* () {
let client = new httpm.HttpClient("mihails-strasuns/setup-dlang");
return (yield (yield client.get(url)).readBody()).trim();
});
}
exports.body_as_text = body_as_text;
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"description": "Installation of the requested D compiler",
"main": "lib/main.js",
"scripts": {
"build": "tsc",
"test": "jest"
"build": "tsc"
},
"repository": {
"type": "git",
Expand All @@ -25,11 +24,7 @@
"@actions/io": "^1.0.0"
},
"devDependencies": {
"@types/jest": "^24.0.13",
"@types/node": "^12.7.4",
"jest": "^24.8.0",
"jest-circus": "^24.7.1",
"ts-jest": "^24.0.2",
"typescript": "^3.5.1"
}
}
Loading

0 comments on commit 3ca55b2

Please sign in to comment.