Skip to content
Open
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ The default value is `any`.
You can disable installing an additional `dub` by passing an empty string.
Note that this does not affect the `dub` executable that comes packaged with `dmd` and `ldc2`.

### redub

Selecting a version of redub makes it being installed
You can specify the version as:
- `latest` - install the latest version from https://github.com/MrcSnm/redub/releases.
This may require an api token.
- `master` - Installs the master/nightly version from https://github.com/MrcSnm/redub/releases/nightly
- `1.24.13` - install https://github.com/MrcSnm/redub/releases/tag/v1.24.13

### gh_token

A github token used to perform queries to https://api.github.com.
Expand Down
32 changes: 18 additions & 14 deletions __tests__/action_input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ describe('Testing compiler when...', function(){
test('it is unspecified', () => {
Object.defineProperty(process, 'arch', { value: 'x64' })
expect(main.getActionInputs()).toStrictEqual({
d_compiler: 'dmd-latest', gh_token: '', dub_version: '', gdmd_sha: '',})
d_compiler: 'dmd-latest', gh_token: '', dub_version: '', gdmd_sha: '', redub_version: ''})

Object.defineProperty(process, 'arch', { value: 'arm64' })
expect(main.getActionInputs()).toStrictEqual({
d_compiler: 'ldc-latest', gh_token: '', dub_version: '', gdmd_sha: '',})
d_compiler: 'ldc-latest', gh_token: '', dub_version: '', gdmd_sha: '', redub_version: ''})
})

function mockCompiler(compiler: string) {
Expand All @@ -30,12 +30,12 @@ describe('Testing compiler when...', function(){
Object.defineProperty(process, 'arch', { value: 'x64' })
mockCompiler('ldc')
expect(main.getActionInputs()).toStrictEqual({
d_compiler: 'ldc', gh_token: '', dub_version: '', gdmd_sha: '',})
d_compiler: 'ldc', gh_token: '', dub_version: '', gdmd_sha: '', redub_version: ''})

Object.defineProperty(process, 'arch', { value: 'x64' })
mockCompiler('invalid text')
expect(main.getActionInputs()).toStrictEqual({
d_compiler: 'invalid text', gh_token: '', dub_version: '', gdmd_sha: '',})
d_compiler: 'invalid text', gh_token: '', dub_version: '', gdmd_sha: '', redub_version: ''})
})

// https://github.com/dlang-community/setup-dlang/issues/78
Expand All @@ -57,13 +57,15 @@ test('All action inputs', () => {
return "z"
case "gdmd_sha":
return "t"
case "redub":
return "h"
default:
throw new Error(`Unknown key '${key}'`)
}
})

expect(main.getActionInputs()).toStrictEqual({
d_compiler: 'x', dub_version: 'y', gh_token: 'z', gdmd_sha: 't'
d_compiler: 'x', dub_version: 'y', gh_token: 'z', gdmd_sha: 't', redub_version: 'h'
})
})

Expand Down Expand Up @@ -99,10 +101,11 @@ describe('Action messages', () => {
await main.run()

expect(nopTool.makeAvailable).toHaveBeenCalledTimes(2)
expect(consoleSpy.mock.calls.length).toBe(2)
expect(consoleSpy.mock.calls[0][0]).toMatch(compString)
expect(consoleSpy.mock.calls[0][0]).toMatch(dubString)
expect(consoleSpy.mock.calls[1][0]).toMatch('Done')
expect(consoleSpy.mock.calls.length).toBe(4)
expect(consoleSpy.mock.calls[0][0]).toMatch('Enabling')
expect(consoleSpy.mock.calls[1][0]).toMatch(compString)
expect(consoleSpy.mock.calls[2][0]).toMatch(dubString)
expect(consoleSpy.mock.calls[3][0]).toMatch('Done')
})

test('Specifying only the compiler', async () => {
Expand All @@ -111,10 +114,11 @@ describe('Action messages', () => {
await main.run()

expect(nopTool.makeAvailable).toHaveBeenCalledTimes(1)
expect(consoleSpy.mock.calls.length).toBe(2)
expect(consoleSpy.mock.calls[0][0]).toMatch(compString)
expect(consoleSpy.mock.calls[0][0]).not.toMatch('dub')
expect(consoleSpy.mock.calls[1][0]).toMatch('Done')
expect(consoleSpy.mock.calls.length).toBe(3)
expect(consoleSpy.mock.calls[0][0]).toMatch('Enabling')
expect(consoleSpy.mock.calls[1][0]).toMatch(compString)
expect(consoleSpy.mock.calls[1][0]).not.toMatch('dub')
expect(consoleSpy.mock.calls[2][0]).toMatch('Done')
})

test('Specifying an invalid compiler', async () => {
Expand All @@ -133,7 +137,7 @@ describe('Action messages', () => {
mockInputs(comp)
await main.run()
expect(nopTool.makeAvailable).toHaveBeenCalled()
expect(consoleSpy).toHaveBeenCalledTimes(2)
expect(consoleSpy).toHaveBeenCalledTimes(3)
nopTool.makeAvailable.mockClear()
consoleSpy.mockClear()
}
Expand Down
21 changes: 21 additions & 0 deletions __tests__/d-redub.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { exeExt, Redub } from '../src/d'
import * as testUtils from './test-helpers.test'
import * as utils from '../src/utils'

testUtils.saveProcessRestorePoint()
testUtils.disableNetwork()
testUtils.hideConsoleLogs()

function init (version: string) { return Redub.initialize(version, '') }

test('Test that redub uses osx-universal for macOS', async () => {
Object.defineProperty(process, 'platform', { value: 'darwin' })

Object.defineProperty(process, 'arch', { value: 'arm64' })
await expect(init('v1.25.2')).resolves.toHaveProperty(
'url', `https://github.com/MrcSnm/redub/releases/download/v1.25.2/redub-v1.25.2-osx-universal${exeExt}`)

Object.defineProperty(process, 'arch', { value: 'x64' })
await expect(init('v1.25.2')).resolves.toHaveProperty(
'url', `https://github.com/MrcSnm/redub/releases/download/v1.25.2/redub-v1.25.2-osx-universal${exeExt}`)
})
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ inputs:
description: "DUB version string, for example 'any', 'latest', or, '1.29.0'"
default: any
required: false
redub:
description: "Redub version string, for example 'latest' or '1.24.13'"
required: false
gh_token:
description: "Token to use when doing Github API request (for ldc-master)"
default: ${{ github.token }}
Expand Down
6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

93 changes: 92 additions & 1 deletion src/d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as semver from './semver'
import * as exec from '@actions/exec'

const sep = (process.platform == 'win32' ? '\\' : '/')
const exeExt = (process.platform == 'win32' ? '.exe' : '')
export const exeExt = (process.platform == 'win32' ? '.exe' : '')

export const SETTINGS = {
verify_sig: core.getInput('verify_sig') !== 'false'
Expand Down Expand Up @@ -763,6 +763,97 @@ export class Dub implements ITool {
}
}


export class Redub implements ITool {
public readonly name = 'redub'
public readonly exeName = this.name + exeExt;
constructor(public url: string, public version: string){}

static getUrlArchSuffix (version: string) {
if(process.platform == "darwin")
return "universal";
switch(process.arch)
{
case "x64": return "x86_64";
case "arm64": return "arm64";
default: throw new Error(`Unsupported arch ${process.arch} for redub releases ${version}`);
}
}

static getOS () {
switch (process.platform) {
case "win32": return "windows";
case "linux": return "linux";
case "darwin": return "osx";
default: throw new Error("unsupported platform: " + process.platform);
}
}


/** Parse a version string and compute the associated version

Possible values for version are:

- 'latest'. The release is taken from:
https://api.github.com/repos/MrcSnm/redub/releases/latest

- 'master'. The release is taken from https://github.com/MrcSnm/redub/releases/nightly

- '1.37.0'. This corresponds to the tag 'v1.37.0'. Note that
pre-releases like 'v1.37.0-rc.1' are not supported.
*/
static async initialize(version: string, token: string) {
const archSuffix = Redub.getUrlArchSuffix(version);
const os = Redub.getOS();

if (version == "master") {
return new Redub(`https://github.com/MrcSnm/redub/releases/download/nightly/redub-latest-${os}-${archSuffix}${exeExt}`, version);
}
if (version === "latest") {
let json = await utils.body_as_text(
`https://api.github.com/repos/MrcSnm/redub/releases/latest`,
token
);
let rname = JSON.parse(json)["tag_name"];
if (rname == undefined) {
console.log(json)
throw new Error("Couldn't load release name for redub latest version");
}
version = rname;
}

const matches = version.match(/^v?(1\.\d+\.\d+)(-.+)?$/);
if (!matches)
throw new Error("unrecognized Redub version: '" + version + '"')
if (matches[2])
throw new Error("only release versions of Redub are supported, not: " + version)
version = "v" + matches[1];

const url = `https://github.com/MrcSnm/redub/releases/download/${version}/redub-${version}-${os}-${archSuffix}${exeExt}`
return new Redub(url, version)
}

/** Return the path to where the url archive was extracted, after caching it */
private async getCached(): Promise<string> {
let cached = await tc.find(this.name, this.version)
if (!cached) {
console.log(`Downloading ${this.url}`);
const archive = await utils.downloadTool(this.url);
cached = await tc.cacheFile(archive,
this.exeName, this.name, this.version)
const exePath = cached + sep + this.exeName;
fs.chmodSync(exePath, 0o755);
}
return cached
}

async makeAvailable() {
let redubDir = await this.getCached()
console.log(`Adding redub directory '${redubDir}' to path`)
core.addPath(redubDir)
}
}

export class GDC implements ITool {
/** The version of the gdc apt package that will install gdc, it can by empty

Expand Down
65 changes: 41 additions & 24 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,57 @@ export function getActionInputs() {
dub_version = ''
}

const redub_version = core.getInput('redub') || "";

const gdmd_sha = core.getInput('gdmd_sha') || ""

return { d_compiler, gh_token, dub_version, gdmd_sha };
return { d_compiler, gh_token, dub_version, redub_version, gdmd_sha };
}

export async function run() {
try {
let { d_compiler, gh_token, dub_version, gdmd_sha } = getActionInputs();

let compiler: d.ITool
if (d_compiler.startsWith('dmd'))
compiler = await d.DMD.initialize(d_compiler, gh_token)
else if (d_compiler.startsWith('ldc'))
compiler = await d.LDC.initialize(d_compiler, gh_token)
else if (d_compiler.startsWith('gdc'))
compiler = await d.GDC.initialize(d_compiler, gdmd_sha)
else
throw new Error(`Unrecognized compiler: '${d_compiler}'`)

let dub: d.Dub | undefined
let { d_compiler, gh_token, dub_version, redub_version, gdmd_sha } = getActionInputs();

console.log('Enabling:')
console.log(` compiler '${d_compiler}'`)
if (dub_version) console.log(` dub '${dub_version}'`)
if (redub_version) console.log(` redub '${redub_version}'`)

let compiler_promise: Promise<d.ITool>
if (d_compiler.startsWith('dmd'))
compiler_promise = d.DMD.initialize(d_compiler, gh_token)
else if (d_compiler.startsWith('ldc'))
compiler_promise = d.LDC.initialize(d_compiler, gh_token)
else if (d_compiler.startsWith('gdc'))
compiler_promise = d.GDC.initialize(d_compiler, gdmd_sha)
else
throw new Error(`Unrecognized compiler: '${d_compiler}'`)

const redub_promise = redub_version ? d.Redub.initialize(redub_version, gh_token) : undefined

const [compiler, redub] = await Promise.all([
compiler_promise,
redub_promise
]);

let dub: d.Dub | undefined;
if (dub_version.length) {
dub = await d.Dub.initialize(dub_version, gh_token)
console.log(`Enabling ${d_compiler} with dub ${dub_version}`);
} else
console.log(`Enabling ${d_compiler}`);
dub = await d.Dub.initialize(dub_version, gh_token)
}

await compiler.makeAvailable()
await dub?.makeAvailable()

await Promise.all([
compiler.makeAvailable(),
redub?.makeAvailable()
]);
await dub?.makeAvailable();

console.log("Done");

} catch (error) {
if (error instanceof Error) {
console.log(error.message);
core.setFailed(error.message);
}
if (error instanceof Error) {
console.log(error.message);
core.setFailed(error.message);
}
}
}
Loading