Skip to content

Commit c9c554c

Browse files
the-horoGeod24
authored andcommitted
Add dub: any input and make it the default
This value means install `dub` if the compiler is `gdc`, otherwise use the `dub` that comes with `dmd` or `ldc2`. This is meant to solve the common issue of having to specify the `dub` input to the action because one of the tested compilers is `gdc`. Signed-off-by: Andrei Horodniceanu <[email protected]>
1 parent a447b2e commit c9c554c

File tree

7 files changed

+67
-15
lines changed

7 files changed

+67
-15
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ jobs:
105105
with:
106106
dc: ${{ matrix.dc }}
107107
gdmd_sha: ${{ matrix.gdmd_sha }}
108+
- name: Test that dub is installed by default
109+
run: |
110+
cd .github && dub run --single hello.d
108111
109112
verify-default:
110113
needs: verify-index-js-up-to-date
@@ -142,7 +145,7 @@ jobs:
142145
matrix:
143146
os: [ ubuntu-latest, windows-latest, macos-latest, macOS-13 ]
144147
dc: [ ldc-latest, dmd-latest, gdc, gdc-12 ]
145-
dub: [ 1.19.0, 1.23.0, latest ]
148+
dub: [ 1.19.0, any, latest ]
146149
exclude:
147150
# Excluded because those are actually Linux executables
148151
- { os: windows-latest, dub: 1.19.0 }
@@ -163,6 +166,7 @@ jobs:
163166
dub: ${{ matrix.dub }}
164167

165168
- name: Verify DUB version
169+
if: matrix.dub != 'any'
166170
run: |
167171
if [[ ${{ matrix.dub }} == 'latest' ]]
168172
then

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ jobs:
7575
uses: dlang-community/setup-dlang@v2
7676
with:
7777
compiler: ${{ matrix.dc }}
78-
# dub doesn't come with gdc.
79-
# You wouldn't need the line below if only using dmd or ldc
80-
dub: latest
8178
8279
- name: Run tests
8380
shell: bash
@@ -103,8 +100,6 @@ Examples:
103100
- uses: dlang-community/setup-dlang@v2
104101
with:
105102
compiler: gdc-12
106-
# dub doesn't come with gdc
107-
dub: latest
108103
# Install gdmd from https://github.com/D-Programming-GDC/gdmd/blob/0a64b92ec5ad1177988496df4f3ca47c47580501/dmd-script
109104
# instead of the master branch
110105
gdmd_sha: '0a64b92ec5ad1177988496df4f3ca47c47580501'
@@ -162,12 +157,17 @@ The compilers are already configured to embed this path themselves so you really
162157

163158
### dub
164159

165-
If you need a specific version of dub or if the D compiler doesn't come with one (`gdc`) you can explicitly install one.
160+
You can select the specific version of dub that gets installed, or if it gets installed.
166161

167-
You can specify this version as:
162+
You can specify the version as:
168163
- `latest` - install the latest version from https://github.com/dlang/dub/releases.
169164
This may require an api token.
170165
- `1.24.0` - install https://github.com/dlang/dub/releases/tag/v1.24.0
166+
- `any` - use either the `dub` that comes with the compiler or install `latest`
167+
168+
The default value is `any`.
169+
You can disable installing an additional `dub` by passing an empty string.
170+
Note that this does not affect the `dub` executable that comes packaged with `dmd` and `ldc2`.
171171

172172
### gh_token
173173

@@ -210,7 +210,7 @@ Like dmd, ldc releases come with programs like `rdmd` and `dub`.
210210

211211
Gdc is currently only available on linux.
212212
The exact versions available are those in the ubuntu repos.
213-
Note that gdc won't come by default with any extra programs like `rdmd` or `dub` so you would need to install them separately or install another compiler that comes with them.
213+
Note that gdc won't come by default with extra programs like `rdmd` so you would need to install them separately or install another compiler that comes with them.
214214
You can do that with:
215215

216216
```yml
@@ -229,7 +229,7 @@ You can do that with:
229229

230230
## DUB support
231231

232-
[dub](https://github.com/dlang/dub) is installed alongside the selected compiler for any versions of dmd and ldc higher than v2.072.0 (2016-10-31).
232+
[dub](https://github.com/dlang/dub) is installed alongside the selected compiler for any versions of dmd and ldc higher than v2.072.0 (2016-10-31) and any version of gdc.
233233

234234
If the `dub` parameter is provided to the action, that version will be the one installed instead.
235235

@@ -269,3 +269,10 @@ Added unittests.
269269
To run them use `npm test`.
270270

271271
Added the `verify_sig` option. It can be used to disable the gpg verification of the downloaded dmd archives. The option is meant to be used in edge-case scenarios when the [d-keyring](https://github.com/dlang/dlang.org/blob/master/d-keyring.gpg) is not updated alongside the dmd releases (#87). Requested in #90.
272+
273+
Added the `dub: "any"` input
274+
This is a special value that means:
275+
1. if the compiler is `dmd` or `ldc`, don't install `dub`, use the executable that comes with the compiler
276+
2. if the compiler is `gdc`, install latest `dub`
277+
278+
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.

__tests__/action_input.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describe('Action messages', () => {
132132
for (var comp of [ 'dmd', 'ldc-11.3.0', 'gdc-12' ]) {
133133
mockInputs(comp)
134134
await main.run()
135-
expect(nopTool.makeAvailable).toHaveBeenCalledTimes(1)
135+
expect(nopTool.makeAvailable).toHaveBeenCalled()
136136
expect(consoleSpy).toHaveBeenCalledTimes(2)
137137
nopTool.makeAvailable.mockClear()
138138
consoleSpy.mockClear()
@@ -150,3 +150,36 @@ describe('Action messages', () => {
150150
expect(consoleSpy.mock.calls[0][0]).toMatch(msg)
151151
})
152152
})
153+
154+
describe('dub default input', () => {
155+
function mockCompiler(compiler: string) {
156+
jest.spyOn(core, 'getInput').mockImplementation((key) => {
157+
switch (key) {
158+
case 'compiler':
159+
return compiler
160+
case 'dub':
161+
return 'any'
162+
default:
163+
return ''
164+
}
165+
})
166+
}
167+
168+
test('with gdc dub is latest', () => {
169+
mockCompiler('gdc-14')
170+
const got = main.getActionInputs()
171+
expect(got.dub_version).toBe('latest')
172+
})
173+
174+
test('with dmd dub is empty', async () => {
175+
mockCompiler('dmd')
176+
const got = main.getActionInputs()
177+
expect(got.dub_version).toBe('')
178+
})
179+
180+
test('without a compiler specified dub is empty', async () => {
181+
mockCompiler('')
182+
const got = main.getActionInputs()
183+
expect(got.dub_version).toBe('')
184+
})
185+
})

action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ inputs:
66
description: "Compiler version string, for example 'dmd-latest' or 'ldc-1.20.1'"
77
required: false
88
dub:
9-
description: "DUB version string, for example 'latest' or '1.29.0'"
9+
description: "DUB version string, for example 'any', 'latest', or, '1.29.0'"
10+
default: any
1011
required: false
1112
gh_token:
1213
description: "Token to use when doing Github API request (for ldc-master)"

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.

src/main.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ export function getActionInputs() {
1313
}
1414
const d_compiler = core.getInput('compiler') || default_compiler;
1515
const gh_token = core.getInput('gh_token') || "";
16-
const dub_version = core.getInput('dub') || "";
16+
let dub_version = core.getInput('dub')
17+
if (dub_version == 'any') {
18+
if (d_compiler.startsWith('gdc'))
19+
dub_version = 'latest'
20+
else
21+
dub_version = ''
22+
}
23+
1724
const gdmd_sha = core.getInput('gdmd_sha') || ""
1825

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

0 commit comments

Comments
 (0)