Skip to content

Commit 5afdaed

Browse files
committed
Add dc_format input to the action
Signed-off-by: Andrei Horodniceanu <[email protected]>
1 parent c0a55c2 commit 5afdaed

File tree

13 files changed

+237
-19
lines changed

13 files changed

+237
-19
lines changed

.github/actions/verify-d-compiler/action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ inputs:
1616
description: "Use .sig file to verify downloaded archives"
1717
type: boolean
1818
default: true
19+
dc_format:
20+
description: "The way the $DC and $DMD variables are set: absolute path or basename"
21+
default: absolute
22+
required: true
23+
type: choice
24+
options:
25+
- absolute
26+
- basename
27+
- shortname
1928
runs:
2029
using: "composite"
2130
steps:
@@ -26,6 +35,7 @@ runs:
2635
gh_token: ${{ inputs.gh_token }}
2736
gdmd_sha: ${{ inputs.gdmd_sha }}
2837
verify_sig: ${{ inputs.verify_sig }}
38+
dc_format: ${{ inputs.dc_format }}
2939

3040
- name: Verify D compiler ($DC)
3141
shell: bash

.github/workflows/test.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,65 @@ jobs:
194194
- name : Compile with dub
195195
run: |
196196
cd .github && dub run --single hello.d --compiler=${DC}
197+
198+
dc-format:
199+
needs: verify-index-js-up-to-date
200+
name: Check dc_format input
201+
strategy:
202+
max-parallel: 5
203+
fail-fast: false
204+
matrix:
205+
include:
206+
- { dc: dmd, os: ubuntu-latest, dc_format: absolute }
207+
- { dc: ldc, os: windows-latest, dc_format: absolute }
208+
- { dc: gdc-14, os: ubuntu-latest, dc_format: shortname }
209+
- { dc: ldc, os: windows-latest, dc_format: basename }
210+
- { dc: ldc-1.41.0, os: macos-latest, dc_format: basename }
211+
runs-on: ${{ matrix.os }}
212+
steps:
213+
- uses: actions/checkout@v4
214+
- uses: ./.github/actions/verify-d-compiler
215+
with:
216+
dc: ${{ matrix.dc }}
217+
dc_format: ${{ matrix.dc_format }}
218+
219+
- name: Check DC and DMD variables
220+
run: |
221+
fail=
222+
223+
for var in DC DMD; do
224+
value="${!var}"
225+
226+
base=$(basename "${value}")
227+
case "${DC_FORMAT}" in
228+
absolute)
229+
expected=$(command -v "${base}")
230+
if [[ ${{ matrix.os }} == windows-* ]]; then
231+
expected=$(cygpath -aw "${expected}")
232+
fi
233+
;;
234+
basename)
235+
expected="${base}"
236+
;;
237+
shortname)
238+
expected="${base%.exe}"
239+
;;
240+
*)
241+
echo "Unknown DC_FORMAT: ${DC_FORMAT}"
242+
exit 1
243+
;;
244+
esac
245+
246+
echo -n "Checking if ${var} (${value}) is ${expected}..."
247+
if [[ ${value} == "${expected}" ]]; then
248+
echo " good"
249+
else
250+
echo " fail"
251+
fail=1
252+
fi
253+
done
254+
255+
[[ -z ${fail} ]] || exit 1
256+
env:
257+
DC_FORMAT: ${{ matrix.dc_format }}
258+
shell: bash

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ Examples:
105105
gdmd_sha: '0a64b92ec5ad1177988496df4f3ca47c47580501'
106106
# turn off gpg verification (only dmd archives currently undergo this verification)
107107
verify_sig: false
108+
# set DC to `gdc-12` and DMD to `gdmd-12` instead of `/usr/bin/gdc-12`
109+
dc_format: basename
108110
```
109111
110112
### compiler
@@ -169,6 +171,24 @@ The default value is `any`.
169171
You can disable installing an additional `dub` by passing an empty string.
170172
Note that this does not affect the `dub` executable that comes packaged with `dmd` and `ldc2`.
171173

174+
### dc_format
175+
176+
This option allows you to change the path value of the `DC` and `DMD` environment variables set by this action.
177+
There are three possible values:
178+
- `absolute`
179+
- `basename`
180+
- `shortname`
181+
182+
Assuming that `ldc2` has been downloaded and extracted to the following directories, the `dc_format` input would set `$DC` like so:
183+
184+
| | `C:\Program Files\ldc2-1.41.0-windows` | `/home/toolcache/cache/ldc2-1.41.0-linux` |
185+
| `absolute` | `C:\Program Files\ldc2-1.41.0-windows\bin\ldc2.exe` | `/home/toolcache/cache/ldc2-1.41.0-linux/bin/ldc2-1.40` |
186+
| `basename` | `ldc2.exe` | `ldc2-1.40` |
187+
| `shortname` | `ldc2` | `ldc2-1.40` |
188+
189+
The default value for this setting is `absolute`.
190+
Previously, before `v2`, the action would set the variable in the same way `shortname` does now.
191+
172192
### gh_token
173193

174194
A github token used to perform queries to https://api.github.com.
@@ -276,3 +296,9 @@ This is a special value that means:
276296
2. if the compiler is `gdc`, install latest `dub`
277297

278298
This has become the default value because most D projects use `dub` to build and it is a hindrance to manually specify it just because `gdc` doesn't come with it.
299+
300+
Added the `dc_format` input to control how the `DC` and `DMD` variables are set.
301+
They allow setting the variables to:
302+
- the absolute path of the compiler executable
303+
- the basename of the executable
304+
- the basename without the `.exe` extension

__tests__/d-compiler.test.ts

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,58 @@ describe('Test Compiler class', () => {
124124
expect(process.env['DMD']).toBe(`${root}${bin}\\${dmdWrapper}.exe`)
125125
})
126126

127-
test('DC and DMD get set to the absolute path of the compiler', () => {
128-
for (const platform of [ 'linux', 'win32', 'darwin', 'freebsd' ]) {
129-
const sep = SETTINGS.sep = '/'
130-
const exeExt = SETTINGS.exeExt = ''
131-
Object.defineProperty(process, 'platform', { value: platform })
132-
c.setDC(root)
133-
expect(process.env['DC']).toBe(root + bin + sep + name + exeExt)
134-
expect(process.env['DMD']).toBe(root + bin + sep + dmdWrapper + exeExt)
135-
}
127+
describe('Test DC and DMD path format', () => {
128+
const origDcFormat = SETTINGS.dcFormat
129+
beforeEach(() => SETTINGS.sep = '/')
130+
afterEach(() => SETTINGS.dcFormat = origDcFormat)
131+
132+
test('default is absolute', () => {
133+
SETTINGS.exeExt = '.exe'
134+
c.setDC(root)
135+
expect(process.env['DC']).toBe(root + bin + '/' + name + '.exe')
136+
expect(process.env['DMD']).toBe(root + bin + '/' + dmdWrapper + '.exe')
137+
})
138+
139+
test('explicit absolute', () => {
140+
SETTINGS.exeExt = ''
141+
SETTINGS.dcFormat = 'absolute'
142+
c.setDC(root)
143+
expect(process.env['DC']).toBe(root + bin + '/' + name)
144+
expect(process.env['DMD']).toBe(root + bin + '/' + dmdWrapper)
145+
})
146+
147+
describe('basename', () => {
148+
beforeEach(() => SETTINGS.dcFormat = 'basename')
149+
test('posix', () => {
150+
SETTINGS.exeExt = ''
151+
c.setDC(root)
152+
expect(process.env['DC']).toBe(name)
153+
expect(process.env['DMD']).toBe(dmdWrapper)
154+
})
155+
156+
test('windows', () => {
157+
SETTINGS.exeExt = '.exe'
158+
c.setDC(root)
159+
expect(process.env['DC']).toBe(name + '.exe')
160+
expect(process.env['DMD']).toBe(dmdWrapper + '.exe')
161+
})
162+
})
163+
164+
describe('shortname', () => {
165+
beforeEach(() => SETTINGS.dcFormat = 'shortname')
166+
test('posix', () => {
167+
SETTINGS.exeExt = ''
168+
c.setDC(root)
169+
expect(process.env['DC']).toBe(name)
170+
expect(process.env['DMD']).toBe(dmdWrapper)
171+
})
172+
173+
test('windows', () => {
174+
SETTINGS.exeExt = '.exe'
175+
c.setDC(root)
176+
expect(process.env['DC']).toBe(name)
177+
expect(process.env['DMD']).toBe(dmdWrapper)
178+
})
179+
})
136180
})
137181
})

__tests__/d-dmd.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,4 +535,18 @@ describe('Test makeAvailable', () => {
535535
expect(gpgSpy).toHaveBeenCalled()
536536
})
537537
})
538+
539+
describe('test DC and DMD format', () => {
540+
const origDcFormat = SETTINGS.dcFormat
541+
afterEach(() => SETTINGS.dcFormat = origDcFormat)
542+
543+
test('basename', async () => {
544+
SETTINGS.dcFormat = 'basename'
545+
SETTINGS.exeExt = '.exe'
546+
const dmd = await init('dmd-2.108')
547+
await dmd.makeAvailable()
548+
expect(process.env['DC']).toBe('dmd.exe')
549+
expect(process.env['DMD']).toBe('dmd.exe')
550+
})
551+
})
538552
})

__tests__/d-gdc.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { GDC } from '../src/d'
22
import * as testUtils from './test-helpers.test'
33
import * as exec from '@actions/exec'
44
import * as tc from '@actions/tool-cache'
5+
import SETTINGS from '../src/settings'
6+
7+
const GdmdSha = 'dc0ad9f739795f3ce5c69825efcd5d1d586bb013'
58

69
testUtils.saveProcessRestorePoint()
710
testUtils.hideConsoleLogs()
@@ -13,8 +16,7 @@ beforeEach(() => {
1316
})
1417

1518
async function init (version: string) {
16-
const gdmdSha = 'dc0ad9f739795f3ce5c69825efcd5d1d586bb013'
17-
const gdc = await GDC.initialize(version, gdmdSha)
19+
const gdc = await GDC.initialize(version, GdmdSha)
1820
await gdc.makeAvailableGdc()
1921
}
2022

@@ -91,3 +93,15 @@ describe('Gdmd tests', () => {
9193
})
9294
})
9395

96+
describe('test DC and DMD format', () => {
97+
const origDcFormat = SETTINGS.dcFormat
98+
afterEach(() => SETTINGS.dcFormat = origDcFormat)
99+
100+
test('shortname', async () => {
101+
SETTINGS.dcFormat = 'shortname'
102+
const gdc = await GDC.initialize('gdc-14', GdmdSha)
103+
await gdc.makeAvailable()
104+
expect(process.env['DC']).toBe('gdc-14')
105+
expect(process.env['DMD']).toBe('gdmd-14')
106+
})
107+
})

__tests__/d-ldc.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,4 +514,17 @@ describe('Test makeAvailable', () => {
514514
expect(process.env['DC']).toBe(root + '\\ldc2-1.39.0-windows-multilib\\bin\\ldc2.exe')
515515
expect(process.env['DMD']).toBe(root + '\\ldc2-1.39.0-windows-multilib\\bin\\ldmd2.exe')
516516
})
517+
518+
describe('test DC and DMD format', () => {
519+
const origDcFormat = SETTINGS.dcFormat
520+
afterEach(() => SETTINGS.dcFormat = origDcFormat)
521+
522+
test('shortname', async () => {
523+
SETTINGS.dcFormat = 'shortname'
524+
const dmd = await init('ldc-1.39.0')
525+
await dmd.makeAvailable()
526+
expect(process.env['DC']).toBe('ldc2')
527+
expect(process.env['DMD']).toBe('ldmd2')
528+
})
529+
})
517530
})

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ inputs:
99
description: "DUB version string, for example 'any', 'latest', or, '1.29.0'"
1010
default: any
1111
required: false
12+
dc_format:
13+
description: "The way the $DC and $DMD variables are set: absolute path or basename"
14+
default: absolute
15+
required: true
16+
type: choice
17+
options:
18+
- absolute
19+
- basename
20+
- shortname
1221
gh_token:
1322
description: "Token to use when doing Github API request (for ldc-master)"
1423
default: ${{ github.token }}

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)