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

Commit 313b018

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

File tree

16 files changed

+135
-55
lines changed

16 files changed

+135
-55
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: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import require$$0$9 from 'diagnostics_channel';
2828
import require$$2$2 from 'child_process';
2929
import require$$6$1 from 'timers';
3030
import { chmodSync } from 'node:fs';
31+
import { join } from 'node:path';
3132

3233
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3334

@@ -29857,10 +29858,10 @@ class GpgCli {
2985729858
}
2985829859
}
2985929860
async import(ascPath) {
29860-
await execOutput(this.name, ['--import', ascPath]);
29861+
await execOutput(this.name, ['--import', ascPath], { silent: false, failOnStdErr: false });
2986129862
}
2986229863
async verify(sigPath, binPath) {
29863-
await execOutput(this.name, ['--verify', sigPath, binPath]);
29864+
await execOutput(this.name, ['--verify', sigPath, binPath], { silent: false, failOnStdErr: false });
2986429865
}
2986529866
async help() {
2986629867
const { stdout } = await execOutput(this.name, ['--help']);
@@ -29914,6 +29915,10 @@ class TrdlCli {
2991429915
const { stdout } = await execOutput(this.name, ['list']);
2991529916
return stdout.slice(1).map(parseLineToItem);
2991629917
}
29918+
async version() {
29919+
const { stdout } = await execOutput(this.name, ['version'], { silent: false });
29920+
return stdout.join('');
29921+
}
2991729922
}
2991829923
function parseLineToItem(line) {
2991929924
const [name, url, default_, channel] = line.trim().split(/ +/);
@@ -29998,27 +30003,30 @@ async function downloadParallel(binUrl, sigUrl, ascUrl) {
2999830003
function findTrdlCache(toolName, toolVersion) {
2999930004
return toolCacheExports.find(toolName, toolVersion);
3000030005
}
30001-
async function installTrdl(toolName, toolVersion, binPath) {
30006+
async function installTrdl(binPath, toolName, toolVersion) {
3000230007
// install tool
30003-
const installedPath = await toolCacheExports.cacheFile(binPath, toolName, toolName, toolVersion);
30008+
const cachedPath = await toolCacheExports.cacheFile(binPath, toolName, toolName, toolVersion);
30009+
const cachedFile = join(cachedPath, toolName);
30010+
coreExports.info(format('cached file=%s', cachedFile));
3000430011
// set permissions
30005-
chmodSync(installedPath, 0o755);
30012+
chmodSync(cachedFile, 0o755);
3000630013
// add tool to $PATH
30007-
coreExports.addPath(installedPath);
30014+
coreExports.addPath(cachedFile);
3000830015
}
3000930016
async function Run() {
30017+
coreExports.setCommandEcho(coreExports.isDebug());
3001030018
const trdlCli = new TrdlCli();
3001130019
const gpgCli = new GpgCli();
3001230020
const inputs = parseInputs();
3001330021
await Do(trdlCli, gpgCli, inputs);
3001430022
}
3001530023
async function Do(trdlCli, gpgCli, inputs) {
3001630024
coreExports.startGroup('Install or self-update trdl.');
30017-
coreExports.debug(format(`parsed inputs=%o`, inputs));
30025+
coreExports.info(format(`parsed inputs=%o`, inputs));
3001830026
const defaults = trdlCli.defaults();
30019-
coreExports.debug(format(`trdl defaults=%o`, defaults));
30027+
coreExports.info(format(`trdl defaults=%o`, defaults));
3002030028
const options = await getOptions(inputs, defaults);
30021-
coreExports.debug(format(`installation options=%o`, options));
30029+
coreExports.info(format(`installation options=%o`, options));
3002230030
const toolCache = findTrdlCache(defaults.repo, options.version);
3002330031
if (toolCache) {
3002430032
coreExports.info(`Installation skipped. trdl@v${options.version} is found at path ${toolCache}.`);
@@ -30030,16 +30038,19 @@ async function Do(trdlCli, gpgCli, inputs) {
3003030038
}
3003130039
await gpgCli.mustGnuGP();
3003230040
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.');
30041+
coreExports.info(format('%s binUrl=%s', defaults.repo, binUrl));
30042+
coreExports.info(format('%s sigUrl=%s', defaults.repo, sigUrl));
30043+
coreExports.info(format('%s ascUrl=%s', defaults.repo, ascUrl));
30044+
coreExports.info('Downloading binary and signatures.');
3003730045
const [binPath, sigPath, ascPath] = await downloadParallel(binUrl, sigUrl, ascUrl);
3003830046
coreExports.info('Importing and verifying gpg keys.');
3003930047
await gpgCli.import(ascPath);
3004030048
await gpgCli.verify(sigPath, binPath);
3004130049
coreExports.info('Installing trdl and adding it to the $PATH.');
30042-
await installTrdl(defaults.repo, options.version, binPath);
30050+
await installTrdl(binPath, defaults.repo, options.version);
30051+
coreExports.info('Showing installed version.');
30052+
const version = await trdlCli.version();
30053+
coreExports.info(format('Installed version: trdl@%s', version));
3004330054
coreExports.endGroup();
3004430055
}
3004530056

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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as toolCache from '../../test/mocks/tool-cache'
44
import * as fs from '../../test/mocks/fs'
55
import { trdlCli } from '../../test/mocks/trdl-cli'
66
import { gpgCli } from '../../test/mocks/gpg-cli'
7+
import { join } from 'node:path'
78

89
// Mocks should be declared before the module being tested is imported.
910
jest.unstable_mockModule('@actions/core', () => core)
@@ -86,16 +87,16 @@ describe('install/action.ts', function () {
8687
expect(trdlCli.update).toHaveBeenCalledWith(defaults)
8788
})
8889
it('should install trdl if tool cache is not found', async function () {
89-
const binPath = 'bin path'
90+
const binPath = '/tmp/cache/path'
9091
const sigPath = 'sig path'
9192
const ascPath = 'asc path'
9293

9394
toolCache.downloadTool.mockResolvedValueOnce(binPath)
9495
toolCache.downloadTool.mockResolvedValueOnce(sigPath)
9596
toolCache.downloadTool.mockResolvedValueOnce(ascPath)
9697

97-
const installedPath = '/tmp/installed/path'
98-
toolCache.cacheFile.mockResolvedValueOnce(installedPath)
98+
const cachedPath = '/tmp/installed/path'
99+
toolCache.cacheFile.mockResolvedValueOnce(cachedPath)
99100

100101
await Do(trdlCli, gpgCli, inputs)
101102

@@ -104,8 +105,9 @@ describe('install/action.ts', function () {
104105
expect(gpgCli.import).toHaveBeenCalledWith(ascPath)
105106
expect(gpgCli.verify).toHaveBeenCalledWith(sigPath, binPath)
106107
expect(toolCache.cacheFile).toHaveBeenCalledWith(binPath, defaults.repo, defaults.repo, inputs.version)
107-
expect(fs.chmodSync).toHaveBeenCalledWith(installedPath, 0o755)
108-
expect(core.addPath).toHaveBeenCalledWith(installedPath)
108+
expect(fs.chmodSync).toHaveBeenCalledWith(join(cachedPath, defaults.repo), 0o755)
109+
expect(core.addPath).toHaveBeenCalledWith(join(cachedPath, defaults.repo))
110+
expect(trdlCli.version).toHaveBeenCalled()
109111
})
110112
})
111113
})

install/src/action.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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'
5+
import { join } from 'node:path'
56
import { GpgCli } from '../../lib/gpg-cli'
67
import { Defaults, TrdlCli } from '../../lib/trdl-cli'
78
import { format } from 'util'
@@ -90,16 +91,20 @@ function findTrdlCache(toolName: string, toolVersion: string): string {
9091
return find(toolName, toolVersion)
9192
}
9293

93-
async function installTrdl(toolName: string, toolVersion: string, binPath: string): Promise<void> {
94+
async function installTrdl(binPath: string, toolName: string, toolVersion: string): Promise<void> {
9495
// install tool
95-
const installedPath = await cacheFile(binPath, toolName, toolName, toolVersion)
96+
const cachedPath = await cacheFile(binPath, toolName, toolName, toolVersion)
97+
const cachedFile = join(cachedPath, toolName)
98+
info(format('cached file=%s', cachedFile))
9699
// set permissions
97-
chmodSync(installedPath, 0o755)
100+
chmodSync(cachedFile, 0o755)
98101
// add tool to $PATH
99-
addPath(installedPath)
102+
addPath(cachedFile)
100103
}
101104

102105
export async function Run(): Promise<void> {
106+
setCommandEcho(isDebug())
107+
103108
const trdlCli = new TrdlCli()
104109
const gpgCli = new GpgCli()
105110
const inputs = parseInputs()
@@ -109,13 +114,13 @@ export async function Run(): Promise<void> {
109114

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

114119
const defaults = trdlCli.defaults()
115-
debug(format(`trdl defaults=%o`, defaults))
120+
info(format(`trdl defaults=%o`, defaults))
116121

117122
const options = await getOptions(inputs, defaults)
118-
debug(format(`installation options=%o`, options))
123+
info(format(`installation options=%o`, options))
119124

120125
const toolCache = findTrdlCache(defaults.repo, options.version)
121126

@@ -133,18 +138,22 @@ export async function Do(trdlCli: TrdlCli, gpgCli: GpgCli, inputs: inputs): Prom
133138
await gpgCli.mustGnuGP()
134139

135140
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))
141+
info(format('%s binUrl=%s', defaults.repo, binUrl))
142+
info(format('%s sigUrl=%s', defaults.repo, sigUrl))
143+
info(format('%s ascUrl=%s', defaults.repo, ascUrl))
139144

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

143148
info('Importing and verifying gpg keys.')
144149
await gpgCli.import(ascPath)
145150
await gpgCli.verify(sigPath, binPath)
146151

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

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)