Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit cf8e38e

Browse files
committed
dev(trdl-actions): e2e-test install action
Signed-off-by: Alexandr Zaytsev <[email protected]>
1 parent 171bed0 commit cf8e38e

File tree

16 files changed

+106
-35
lines changed

16 files changed

+106
-35
lines changed

.github/workflows/_lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Lint
33
on: [push]
44

55
jobs:
6-
_:
6+
lint:
77
runs-on: ubuntu-22.04
88
timeout-minutes: 10
99

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Test e2e Install
2+
3+
on: [push]
4+
5+
jobs:
6+
test-e2e-install:
7+
runs-on: ubuntu-22.04
8+
timeout-minutes: 10
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Install trdl
15+
uses: ./install
16+
17+
- name: Use trdl binary
18+
run: |
19+
which trdl
20+
ls -l $(which trdl)
21+
trdl version
22+
trdl --help

.github/workflows/_test_unit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Test Unit
33
on: [push]
44

55
jobs:
6-
_:
6+
test-unit:
77
runs-on: ubuntu-22.04
88
timeout-minutes: 10
99

install/dist/index.mjs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29857,10 +29857,10 @@ class GpgCli {
2985729857
}
2985829858
}
2985929859
async import(ascPath) {
29860-
await execOutput(this.name, ['--import', ascPath]);
29860+
await execOutput(this.name, ['--import', ascPath], { silent: false, failOnStdErr: false });
2986129861
}
2986229862
async verify(sigPath, binPath) {
29863-
await execOutput(this.name, ['--verify', sigPath, binPath]);
29863+
await execOutput(this.name, ['--verify', sigPath, binPath], { silent: false, failOnStdErr: false });
2986429864
}
2986529865
async help() {
2986629866
const { stdout } = await execOutput(this.name, ['--help']);
@@ -29914,6 +29914,10 @@ class TrdlCli {
2991429914
const { stdout } = await execOutput(this.name, ['list']);
2991529915
return stdout.slice(1).map(parseLineToItem);
2991629916
}
29917+
async version() {
29918+
const { stdout } = await execOutput(this.name, ['version'], { silent: false });
29919+
return stdout.join('');
29920+
}
2991729921
}
2991829922
function parseLineToItem(line) {
2991929923
const [name, url, default_, channel] = line.trim().split(/ +/);
@@ -30007,18 +30011,19 @@ async function installTrdl(toolName, toolVersion, binPath) {
3000730011
coreExports.addPath(installedPath);
3000830012
}
3000930013
async function Run() {
30014+
coreExports.setCommandEcho(coreExports.isDebug());
3001030015
const trdlCli = new TrdlCli();
3001130016
const gpgCli = new GpgCli();
3001230017
const inputs = parseInputs();
3001330018
await Do(trdlCli, gpgCli, inputs);
3001430019
}
3001530020
async function Do(trdlCli, gpgCli, inputs) {
3001630021
coreExports.startGroup('Install or self-update trdl.');
30017-
coreExports.debug(format(`parsed inputs=%o`, inputs));
30022+
coreExports.info(format(`parsed inputs=%o`, inputs));
3001830023
const defaults = trdlCli.defaults();
30019-
coreExports.debug(format(`trdl defaults=%o`, defaults));
30024+
coreExports.info(format(`trdl defaults=%o`, defaults));
3002030025
const options = await getOptions(inputs, defaults);
30021-
coreExports.debug(format(`installation options=%o`, options));
30026+
coreExports.info(format(`installation options=%o`, options));
3002230027
const toolCache = findTrdlCache(defaults.repo, options.version);
3002330028
if (toolCache) {
3002430029
coreExports.info(`Installation skipped. trdl@v${options.version} is found at path ${toolCache}.`);
@@ -30030,16 +30035,19 @@ async function Do(trdlCli, gpgCli, inputs) {
3003030035
}
3003130036
await gpgCli.mustGnuGP();
3003230037
const [binUrl, sigUrl, ascUrl] = formatDownloadUrls(options.version);
30033-
coreExports.debug(format('%s bin_url=%s', defaults.repo, binUrl));
30034-
coreExports.debug(format('%s sig_url=%s', defaults.repo, sigUrl));
30035-
coreExports.debug(format('%s asc_url=%s', defaults.repo, ascUrl));
30036-
coreExports.info('Downloading signatures.');
30038+
coreExports.info(format('%s binUrl=%s', defaults.repo, binUrl));
30039+
coreExports.info(format('%s sigUrl=%s', defaults.repo, sigUrl));
30040+
coreExports.info(format('%s ascUrl=%s', defaults.repo, ascUrl));
30041+
coreExports.info('Downloading binary and signatures.');
3003730042
const [binPath, sigPath, ascPath] = await downloadParallel(binUrl, sigUrl, ascUrl);
3003830043
coreExports.info('Importing and verifying gpg keys.');
3003930044
await gpgCli.import(ascPath);
3004030045
await gpgCli.verify(sigPath, binPath);
3004130046
coreExports.info('Installing trdl and adding it to the $PATH.');
3004230047
await installTrdl(defaults.repo, options.version, binPath);
30048+
coreExports.info('Showing installed version.');
30049+
const version = await trdlCli.version();
30050+
coreExports.info(format('Installed version: trdl@%s', version));
3004330051
coreExports.endGroup();
3004430052
}
3004530053

install/dist/index.mjs.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.

install/src/action.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ describe('install/action.ts', function () {
106106
expect(toolCache.cacheFile).toHaveBeenCalledWith(binPath, defaults.repo, defaults.repo, inputs.version)
107107
expect(fs.chmodSync).toHaveBeenCalledWith(installedPath, 0o755)
108108
expect(core.addPath).toHaveBeenCalledWith(installedPath)
109+
expect(trdlCli.version).toHaveBeenCalled()
109110
})
110111
})
111112
})

install/src/action.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInput, platform, addPath, info, startGroup, endGroup, debug } from '@actions/core'
1+
import { getInput, platform, addPath, info, startGroup, endGroup, setCommandEcho, isDebug } from '@actions/core'
22
import { HttpClient } from '@actions/http-client'
33
import { downloadTool, find, cacheFile } from '@actions/tool-cache'
44
import { chmodSync } from 'node:fs'
@@ -100,6 +100,8 @@ async function installTrdl(toolName: string, toolVersion: string, binPath: strin
100100
}
101101

102102
export async function Run(): Promise<void> {
103+
setCommandEcho(isDebug())
104+
103105
const trdlCli = new TrdlCli()
104106
const gpgCli = new GpgCli()
105107
const inputs = parseInputs()
@@ -109,13 +111,13 @@ export async function Run(): Promise<void> {
109111

110112
export async function Do(trdlCli: TrdlCli, gpgCli: GpgCli, inputs: inputs): Promise<void> {
111113
startGroup('Install or self-update trdl.')
112-
debug(format(`parsed inputs=%o`, inputs))
114+
info(format(`parsed inputs=%o`, inputs))
113115

114116
const defaults = trdlCli.defaults()
115-
debug(format(`trdl defaults=%o`, defaults))
117+
info(format(`trdl defaults=%o`, defaults))
116118

117119
const options = await getOptions(inputs, defaults)
118-
debug(format(`installation options=%o`, options))
120+
info(format(`installation options=%o`, options))
119121

120122
const toolCache = findTrdlCache(defaults.repo, options.version)
121123

@@ -133,11 +135,11 @@ export async function Do(trdlCli: TrdlCli, gpgCli: GpgCli, inputs: inputs): Prom
133135
await gpgCli.mustGnuGP()
134136

135137
const [binUrl, sigUrl, ascUrl] = formatDownloadUrls(options.version)
136-
debug(format('%s bin_url=%s', defaults.repo, binUrl))
137-
debug(format('%s sig_url=%s', defaults.repo, sigUrl))
138-
debug(format('%s asc_url=%s', defaults.repo, ascUrl))
138+
info(format('%s binUrl=%s', defaults.repo, binUrl))
139+
info(format('%s sigUrl=%s', defaults.repo, sigUrl))
140+
info(format('%s ascUrl=%s', defaults.repo, ascUrl))
139141

140-
info('Downloading signatures.')
142+
info('Downloading binary and signatures.')
141143
const [binPath, sigPath, ascPath] = await downloadParallel(binUrl, sigUrl, ascUrl)
142144

143145
info('Importing and verifying gpg keys.')
@@ -146,5 +148,9 @@ export async function Do(trdlCli: TrdlCli, gpgCli: GpgCli, inputs: inputs): Prom
146148

147149
info('Installing trdl and adding it to the $PATH.')
148150
await installTrdl(defaults.repo, options.version, binPath)
151+
152+
info('Showing installed version.')
153+
const version = await trdlCli.version()
154+
info(format('Installed version: trdl@%s', version))
149155
endGroup()
150156
}

lib/gpg-cli.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ describe('gpg-cli.ts', function () {
2323
const ascPath = 'asc path'
2424
const result = await cli.import(ascPath)
2525
expect(result).toBeUndefined()
26-
expect(libExec.execOutput).toHaveBeenCalledWith(cliName, ['--import', ascPath])
26+
expect(libExec.execOutput).toHaveBeenCalledWith(cliName, ['--import', ascPath], {
27+
silent: false,
28+
failOnStdErr: false
29+
})
2730
})
2831
})
2932

@@ -33,7 +36,10 @@ describe('gpg-cli.ts', function () {
3336
const binPath = 'bin path'
3437
const result = await cli.verify(sigPath, binPath)
3538
expect(result).toBeUndefined()
36-
expect(libExec.execOutput).toHaveBeenCalledWith(cliName, ['--verify', sigPath, binPath])
39+
expect(libExec.execOutput).toHaveBeenCalledWith(cliName, ['--verify', sigPath, binPath], {
40+
silent: false,
41+
failOnStdErr: false
42+
})
3743
})
3844
})
3945

lib/gpg-cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ export class GpgCli {
1515
}
1616

1717
async import(ascPath: string): Promise<void> {
18-
await execOutput(this.name, ['--import', ascPath])
18+
await execOutput(this.name, ['--import', ascPath], { silent: false, failOnStdErr: false })
1919
}
2020

2121
async verify(sigPath: string, binPath: string): Promise<void> {
22-
await execOutput(this.name, ['--verify', sigPath, binPath])
22+
await execOutput(this.name, ['--verify', sigPath, binPath], { silent: false, failOnStdErr: false })
2323
}
2424

2525
async help(): Promise<string> {

lib/trdl-cli.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,13 @@ describe('trdl-cli.ts', function () {
157157
expect(libExec.execOutput).toHaveBeenCalledWith(cliName, ['list'])
158158
})
159159
})
160+
describe('version', function () {
161+
it('should work', async function () {
162+
const stdout: string[] = ['1.2.3']
163+
libExec.execOutput.mockResolvedValueOnce({ stdout, stderr: [], exitCode: 0 })
164+
const result = await cli.version()
165+
expect(result).toEqual(stdout.join(''))
166+
expect(libExec.execOutput).toHaveBeenCalledWith(cliName, ['version'], { silent: false })
167+
})
168+
})
160169
})

0 commit comments

Comments
 (0)