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

Commit a281ed0

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

File tree

16 files changed

+120
-40
lines changed

16 files changed

+120
-40
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: 19 additions & 10 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 { dirname, basename as basename$1 } 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(/ +/);
@@ -30000,25 +30005,26 @@ function findTrdlCache(toolName, toolVersion) {
3000030005
}
3000130006
async function installTrdl(toolName, toolVersion, binPath) {
3000230007
// install tool
30003-
const installedPath = await toolCacheExports.cacheFile(binPath, toolName, toolName, toolVersion);
30008+
const installedPath = await toolCacheExports.cacheFile(dirname(binPath), basename$1(binPath), toolName, toolVersion);
3000430009
// set permissions
3000530010
chmodSync(installedPath, 0o755);
3000630011
// add tool to $PATH
3000730012
coreExports.addPath(installedPath);
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,19 @@ 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);
3003830044
coreExports.info('Importing and verifying gpg keys.');
3003930045
await gpgCli.import(ascPath);
3004030046
await gpgCli.verify(sigPath, binPath);
3004130047
coreExports.info('Installing trdl and adding it to the $PATH.');
3004230048
await installTrdl(defaults.repo, options.version, binPath);
30049+
coreExports.info('Showing installed version.');
30050+
const version = await trdlCli.version();
30051+
coreExports.info(format('Installed version: trdl@%s', version));
3004330052
coreExports.endGroup();
3004430053
}
3004530054

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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, jest, it, beforeEach } from '@jest/globals'
22
import * as core from '../../test/mocks/core'
33
import * as toolCache from '../../test/mocks/tool-cache'
44
import * as fs from '../../test/mocks/fs'
5+
import { dirname, basename } from 'node:path'
56
import { trdlCli } from '../../test/mocks/trdl-cli'
67
import { gpgCli } from '../../test/mocks/gpg-cli'
78

@@ -86,7 +87,7 @@ 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/path/to/exec-name'
9091
const sigPath = 'sig path'
9192
const ascPath = 'asc path'
9293

@@ -103,9 +104,15 @@ describe('install/action.ts', function () {
103104
expect(gpgCli.mustGnuGP).toHaveBeenCalled()
104105
expect(gpgCli.import).toHaveBeenCalledWith(ascPath)
105106
expect(gpgCli.verify).toHaveBeenCalledWith(sigPath, binPath)
106-
expect(toolCache.cacheFile).toHaveBeenCalledWith(binPath, defaults.repo, defaults.repo, inputs.version)
107+
expect(toolCache.cacheFile).toHaveBeenCalledWith(
108+
dirname(binPath),
109+
basename(binPath),
110+
defaults.repo,
111+
inputs.version
112+
)
107113
expect(fs.chmodSync).toHaveBeenCalledWith(installedPath, 0o755)
108114
expect(core.addPath).toHaveBeenCalledWith(installedPath)
115+
expect(trdlCli.version).toHaveBeenCalled()
109116
})
110117
})
111118
})

install/src/action.ts

Lines changed: 16 additions & 9 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 { dirname, basename } from 'node:path'
56
import { GpgCli } from '../../lib/gpg-cli'
67
import { Defaults, TrdlCli } from '../../lib/trdl-cli'
78
import { format } from 'util'
@@ -92,14 +93,16 @@ function findTrdlCache(toolName: string, toolVersion: string): string {
9293

9394
async function installTrdl(toolName: string, toolVersion: string, binPath: string): Promise<void> {
9495
// install tool
95-
const installedPath = await cacheFile(binPath, toolName, toolName, toolVersion)
96+
const installedPath = await cacheFile(dirname(binPath), basename(binPath), toolName, toolVersion)
9697
// set permissions
9798
chmodSync(installedPath, 0o755)
9899
// add tool to $PATH
99100
addPath(installedPath)
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,11 +136,11 @@ 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)
142145

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

147150
info('Installing trdl and adding it to the $PATH.')
148151
await installTrdl(defaults.repo, options.version, binPath)
152+
153+
info('Showing installed version.')
154+
const version = await trdlCli.version()
155+
info(format('Installed version: trdl@%s', version))
149156
endGroup()
150157
}

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)