Skip to content

Commit a447b2e

Browse files
committed
Add verify_sig option
Bug: #87 Bug: #90 Signed-off-by: Andrei Horodniceanu <[email protected]>
1 parent 1df38b5 commit a447b2e

File tree

8 files changed

+71
-4
lines changed

8 files changed

+71
-4
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ inputs:
1212
gdmd_sha:
1313
descript: "Commit in D-programming-gdc/gdmd"
1414
default: 'latest'
15+
verify_sig:
16+
description: "Use .sig file to verify downloaded archives"
17+
type: boolean
18+
default: true
1519
runs:
1620
using: "composite"
1721
steps:
@@ -21,6 +25,7 @@ runs:
2125
compiler: ${{ inputs.dc }}
2226
gh_token: ${{ inputs.gh_token }}
2327
gdmd_sha: ${{ inputs.gdmd_sha }}
28+
verify_sig: ${{ inputs.verify_sig }}
2429

2530
- name: Verify D compiler ($DC)
2631
shell: bash

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ jobs:
119119
- uses: actions/checkout@v4
120120
- uses: ./.github/actions/verify-d-compiler
121121

122+
verify-sig:
123+
needs: verify-index-js-up-to-date
124+
name: Check verify_sig input
125+
strategy:
126+
max-parallel: 5
127+
fail-fast: false
128+
matrix:
129+
verify_sig: [ true, false ]
130+
runs-on: ubuntu-latest
131+
steps:
132+
- uses: actions/checkout@v4
133+
- uses: ./.github/actions/verify-d-compiler
134+
with:
135+
verify_sig: ${{ matrix.verify_sig }}
136+
122137
dub:
123138
name: Verify standalone DUB install
124139
needs: verify-index-js-up-to-date

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ Examples:
108108
# Install gdmd from https://github.com/D-Programming-GDC/gdmd/blob/0a64b92ec5ad1177988496df4f3ca47c47580501/dmd-script
109109
# instead of the master branch
110110
gdmd_sha: '0a64b92ec5ad1177988496df4f3ca47c47580501'
111+
# turn off gpg verification (only dmd archives currently undergo this verification)
112+
verify_sig: false
111113
```
112114

113115
### compiler
@@ -184,6 +186,12 @@ Take as an example that upstream may rename the development branch to `main` or
184186

185187
The default value for this input is `latest` and it is required when using GDC.
186188

189+
### verify_sig
190+
191+
Use this boolean to disable gpg verification of downloaded artifacts. Currently, only dmd releases from https://download.dlang.org have a signature file.
192+
193+
The default value is `true`.
194+
187195
## Compiler support
188196

189197
### DMD
@@ -259,3 +267,5 @@ This means that one no longer needs to set `NODE_OPTIONS=--openssl-legacy-provid
259267

260268
Added unittests.
261269
To run them use `npm test`.
270+
271+
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.

__tests__/d-dmd.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { DMD } from '../src/d'
1+
import { DMD, SETTINGS } from '../src/d'
2+
import * as gpg from '../src/gpg'
23
import * as utils from '../src/utils'
34
import * as testUtils from './test-helpers.test'
45
import * as tc from '@actions/tool-cache'
@@ -495,4 +496,31 @@ describe('Test makeAvailable', () => {
495496
expect(process.env['DC']).toBe(root + `\\dmd2\\windows\\bin64${sep}dmd${exeExt}`)
496497
expect(process.env['DMD']).toBe(root + `\\dmd2\\windows\\bin64${sep}dmd${exeExt}`)
497498
})
499+
500+
describe('Check that verify_sig is respected', () => {
501+
const save = SETTINGS.verify_sig
502+
const gpgSpy = jest.spyOn(gpg, 'verify').mockResolvedValue(undefined)
503+
504+
beforeEach(() => {
505+
jest.spyOn(tc, 'find').mockReturnValue(false)
506+
jest.spyOn(utils, 'downloadTool').mockResolvedValue('/tmp/p1')
507+
jest.spyOn(utils, 'extract').mockResolvedValue('/tmp/p2')
508+
jest.spyOn(tc, 'cacheDir').mockResolvedValue('/tmp/p3')
509+
})
510+
afterEach(() => SETTINGS.verify_sig = save)
511+
512+
test('verify_sig === false', async () => {
513+
SETTINGS.verify_sig = false
514+
const dmd = await init('dmd-2.109.1')
515+
await dmd.makeAvailable()
516+
expect(gpgSpy).not.toHaveBeenCalled()
517+
})
518+
519+
test('verify_sig === true', async () => {
520+
SETTINGS.verify_sig = true
521+
const dmd = await init('dmd-2.109.1')
522+
await dmd.makeAvailable()
523+
expect(gpgSpy).toHaveBeenCalled()
524+
})
525+
})
498526
})

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ inputs:
1515
gdmd_sha:
1616
description: "Commit sha in https://github.com/D-Programming-GDC/gdmd, used only by the gdmd compiler"
1717
default: 'latest'
18+
verify_sig:
19+
description: "Verify downloaded artifacts, if a signature file is present"
20+
default: true
21+
required: false
22+
type: boolean
1823
runs:
1924
using: "node20"
2025
main: "dist/index.js"

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/d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import * as exec from '@actions/exec'
99
const sep = (process.platform == 'win32' ? '\\' : '/')
1010
const exeExt = (process.platform == 'win32' ? '.exe' : '')
1111

12+
export const SETTINGS = {
13+
verify_sig: core.getInput('verify_sig') !== 'false'
14+
}
15+
1216
/** Base interface for all D tools */
1317
export interface ITool {
1418
makeAvailable(): Promise<void>
@@ -101,7 +105,7 @@ export class Compiler implements ITool {
101105
} else {
102106
console.log(`Downloading ${this.url}`);
103107
const archive = await utils.downloadTool(this.url)
104-
if (this.sig) {
108+
if (SETTINGS.verify_sig && this.sig) {
105109
console.log("Verifying the download with GPG");
106110
await gpg.verify(archive, this.sig);
107111
}

0 commit comments

Comments
 (0)