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

Commit be4a28b

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

File tree

16 files changed

+133
-51
lines changed

16 files changed

+133
-51
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 --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: 26 additions & 14 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(/ +/);
@@ -29998,27 +30002,29 @@ async function downloadParallel(binUrl, sigUrl, ascUrl) {
2999830002
function findTrdlCache(toolName, toolVersion) {
2999930003
return toolCacheExports.find(toolName, toolVersion);
3000030004
}
30001-
async function installTrdl(toolName, toolVersion, binPath) {
30005+
async function installTrdl(binPath, toolName, toolVersion) {
3000230006
// install tool
30003-
const installedPath = await toolCacheExports.cacheFile(binPath, toolName, toolName, toolVersion);
30007+
const cachedPath = await toolCacheExports.cacheFile(binPath, toolName, format('%s%s', toolName, toolVersion), toolVersion);
30008+
coreExports.info(format('cached path=%s', cachedPath));
3000430009
// set permissions
30005-
chmodSync(installedPath, 0o755);
30010+
chmodSync(cachedPath, 0o755);
3000630011
// add tool to $PATH
30007-
coreExports.addPath(installedPath);
30012+
coreExports.addPath(cachedPath);
3000830013
}
3000930014
async function Run() {
30015+
coreExports.setCommandEcho(coreExports.isDebug());
3001030016
const trdlCli = new TrdlCli();
3001130017
const gpgCli = new GpgCli();
3001230018
const inputs = parseInputs();
3001330019
await Do(trdlCli, gpgCli, inputs);
3001430020
}
3001530021
async function Do(trdlCli, gpgCli, inputs) {
3001630022
coreExports.startGroup('Install or self-update trdl.');
30017-
coreExports.debug(format(`parsed inputs=%o`, inputs));
30023+
coreExports.info(format(`parsed inputs=%o`, inputs));
3001830024
const defaults = trdlCli.defaults();
30019-
coreExports.debug(format(`trdl defaults=%o`, defaults));
30025+
coreExports.info(format(`trdl defaults=%o`, defaults));
3002030026
const options = await getOptions(inputs, defaults);
30021-
coreExports.debug(format(`installation options=%o`, options));
30027+
coreExports.info(format(`installation options=%o`, options));
3002230028
const toolCache = findTrdlCache(defaults.repo, options.version);
3002330029
if (toolCache) {
3002430030
coreExports.info(`Installation skipped. trdl@v${options.version} is found at path ${toolCache}.`);
@@ -30030,16 +30036,22 @@ async function Do(trdlCli, gpgCli, inputs) {
3003030036
}
3003130037
await gpgCli.mustGnuGP();
3003230038
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.');
30039+
coreExports.info(format('%s binUrl=%s', defaults.repo, binUrl));
30040+
coreExports.info(format('%s sigUrl=%s', defaults.repo, sigUrl));
30041+
coreExports.info(format('%s ascUrl=%s', defaults.repo, ascUrl));
30042+
coreExports.info('Downloading binary and signatures.');
3003730043
const [binPath, sigPath, ascPath] = await downloadParallel(binUrl, sigUrl, ascUrl);
30044+
coreExports.info(format('%s binPath=%s', defaults.repo, binPath));
30045+
coreExports.info(format('%s sigPath=%s', defaults.repo, sigPath));
30046+
coreExports.info(format('%s ascPath=%s', defaults.repo, ascPath));
3003830047
coreExports.info('Importing and verifying gpg keys.');
3003930048
await gpgCli.import(ascPath);
3004030049
await gpgCli.verify(sigPath, binPath);
3004130050
coreExports.info('Installing trdl and adding it to the $PATH.');
30042-
await installTrdl(defaults.repo, options.version, binPath);
30051+
await installTrdl(binPath, defaults.repo, options.version);
30052+
coreExports.info('Showing installed version.');
30053+
const version = await trdlCli.version();
30054+
coreExports.info(format('Installed version: trdl@%s', version));
3004330055
coreExports.endGroup();
3004430056
}
3004530057

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('install/action.ts', function () {
8686
expect(trdlCli.update).toHaveBeenCalledWith(defaults)
8787
})
8888
it('should install trdl if tool cache is not found', async function () {
89-
const binPath = 'bin path'
89+
const binPath = '/tmp/path/to/exec-name'
9090
const sigPath = 'sig path'
9191
const ascPath = 'asc path'
9292

@@ -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: 23 additions & 13 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'
@@ -90,16 +90,19 @@ function findTrdlCache(toolName: string, toolVersion: string): string {
9090
return find(toolName, toolVersion)
9191
}
9292

93-
async function installTrdl(toolName: string, toolVersion: string, binPath: string): Promise<void> {
93+
async function installTrdl(binPath: string, toolName: string, toolVersion: string): Promise<void> {
9494
// install tool
95-
const installedPath = await cacheFile(binPath, toolName, toolName, toolVersion)
95+
const cachedPath = await cacheFile(binPath, toolName, format('%s%s', toolName, toolVersion), toolVersion)
96+
info(format('cached path=%s', cachedPath))
9697
// set permissions
97-
chmodSync(installedPath, 0o755)
98+
chmodSync(cachedPath, 0o755)
9899
// add tool to $PATH
99-
addPath(installedPath)
100+
addPath(cachedPath)
100101
}
101102

102103
export async function Run(): Promise<void> {
104+
setCommandEcho(isDebug())
105+
103106
const trdlCli = new TrdlCli()
104107
const gpgCli = new GpgCli()
105108
const inputs = parseInputs()
@@ -109,13 +112,13 @@ export async function Run(): Promise<void> {
109112

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

114117
const defaults = trdlCli.defaults()
115-
debug(format(`trdl defaults=%o`, defaults))
118+
info(format(`trdl defaults=%o`, defaults))
116119

117120
const options = await getOptions(inputs, defaults)
118-
debug(format(`installation options=%o`, options))
121+
info(format(`installation options=%o`, options))
119122

120123
const toolCache = findTrdlCache(defaults.repo, options.version)
121124

@@ -133,18 +136,25 @@ export async function Do(trdlCli: TrdlCli, gpgCli: GpgCli, inputs: inputs): Prom
133136
await gpgCli.mustGnuGP()
134137

135138
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))
139+
info(format('%s binUrl=%s', defaults.repo, binUrl))
140+
info(format('%s sigUrl=%s', defaults.repo, sigUrl))
141+
info(format('%s ascUrl=%s', defaults.repo, ascUrl))
139142

140-
info('Downloading signatures.')
143+
info('Downloading binary and signatures.')
141144
const [binPath, sigPath, ascPath] = await downloadParallel(binUrl, sigUrl, ascUrl)
145+
info(format('%s binPath=%s', defaults.repo, binPath))
146+
info(format('%s sigPath=%s', defaults.repo, sigPath))
147+
info(format('%s ascPath=%s', defaults.repo, ascPath))
142148

143149
info('Importing and verifying gpg keys.')
144150
await gpgCli.import(ascPath)
145151
await gpgCli.verify(sigPath, binPath)
146152

147153
info('Installing trdl and adding it to the $PATH.')
148-
await installTrdl(defaults.repo, options.version, binPath)
154+
await installTrdl(binPath, defaults.repo, options.version)
155+
156+
info('Showing installed version.')
157+
const version = await trdlCli.version()
158+
info(format('Installed version: trdl@%s', version))
149159
endGroup()
150160
}

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)