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

Commit 82d94e1

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

File tree

16 files changed

+158
-84
lines changed

16 files changed

+158
-84
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
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: 34 additions & 22 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

@@ -29826,7 +29827,7 @@ async function execOutput(commandLine, args, options) {
2982629827
const stderr = [];
2982729828
const defaultOptions = {
2982829829
// https://github.com/actions/toolkit/blob/%40actions/exec%401.0.1/packages/exec/src/interfaces.ts#L39
29829-
silent: true,
29830+
silent: false,
2983029831
failOnStdErr: true,
2983129832
listeners: {
2983229833
stdline(data) {
@@ -29857,13 +29858,13 @@ class GpgCli {
2985729858
}
2985829859
}
2985929860
async import(ascPath) {
29860-
await execOutput(this.name, ['--import', ascPath]);
29861+
await execOutput(this.name, ['--import', ascPath], { failOnStdErr: false });
2986129862
}
2986229863
async verify(sigPath, binPath) {
29863-
await execOutput(this.name, ['--verify', sigPath, binPath]);
29864+
await execOutput(this.name, ['--verify', sigPath, binPath], { failOnStdErr: false });
2986429865
}
2986529866
async help() {
29866-
const { stdout } = await execOutput(this.name, ['--help']);
29867+
const { stdout } = await execOutput(this.name, ['--help'], { silent: true });
2986729868
return stdout.join('\n');
2986829869
}
2986929870
}
@@ -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']);
29920+
return stdout.join('');
29921+
}
2991729922
}
2991829923
function parseLineToItem(line) {
2991929924
const [name, url, default_, channel] = line.trim().split(/ +/);
@@ -29998,13 +30003,14 @@ 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);
30004-
// set permissions
30005-
chmodSync(installedPath, 0o755);
30008+
const cachedPath = await toolCacheExports.cacheFile(binPath, toolName, toolName, toolVersion);
3000630009
// add tool to $PATH
30007-
coreExports.addPath(installedPath);
30010+
coreExports.addPath(cachedPath);
30011+
const cachedFile = join(cachedPath, toolName);
30012+
// set permissions
30013+
chmodSync(cachedFile, 0o755);
3000830014
}
3000930015
async function Run() {
3001030016
const trdlCli = new TrdlCli();
@@ -30013,33 +30019,39 @@ async function Run() {
3001330019
await Do(trdlCli, gpgCli, inputs);
3001430020
}
3001530021
async function Do(trdlCli, gpgCli, inputs) {
30016-
coreExports.startGroup('Install or self-update trdl.');
30017-
coreExports.debug(format(`parsed inputs=%o`, inputs));
30022+
coreExports.startGroup(`Install or self-update ${trdlCli.name}.`);
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(`${trdlCli.name} repository defaults=%o`, defaults));
3002030026
const options = await getOptions(inputs, defaults);
30021-
coreExports.debug(format(`installation options=%o`, options));
30022-
const toolCache = findTrdlCache(defaults.repo, options.version);
30027+
coreExports.info(format(`${trdlCli.name} installation options=%o`, options));
30028+
const toolCache = findTrdlCache(trdlCli.name, options.version);
3002330029
if (toolCache) {
30024-
coreExports.info(`Installation skipped. trdl@v${options.version} is found at path ${toolCache}.`);
30030+
coreExports.info(`Installation skipped. ${trdlCli.name}@v${options.version} is found in tool cache ${toolCache}.`);
3002530031
await trdlCli.mustExist();
30026-
coreExports.info(`Updating trdl to group=${defaults.group} and channel=${defaults.channel}`);
30032+
coreExports.info(`Checking ${trdlCli.name} version before updating.`);
30033+
await trdlCli.version();
30034+
coreExports.info(`Updating ${trdlCli.name} to group=${defaults.group} and channel=${defaults.channel}.`);
3002730035
await trdlCli.update(defaults);
30036+
coreExports.info(`Checking ${trdlCli.name} version after updating.`);
30037+
await trdlCli.version();
3002830038
coreExports.endGroup();
3002930039
return;
3003030040
}
3003130041
await gpgCli.mustGnuGP();
3003230042
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.');
30043+
coreExports.info(`${trdlCli.name} binUrl=${binUrl}`);
30044+
coreExports.info(`${trdlCli.name} sigUrl=${sigUrl}`);
30045+
coreExports.info(`${trdlCli.name} ascUrl=${ascUrl}`);
30046+
coreExports.info('Downloading binary and signatures.');
3003730047
const [binPath, sigPath, ascPath] = await downloadParallel(binUrl, sigUrl, ascUrl);
3003830048
coreExports.info('Importing and verifying gpg keys.');
3003930049
await gpgCli.import(ascPath);
3004030050
await gpgCli.verify(sigPath, binPath);
30041-
coreExports.info('Installing trdl and adding it to the $PATH.');
30042-
await installTrdl(defaults.repo, options.version, binPath);
30051+
coreExports.info(`Installing ${trdlCli.name} and adding it to the $PATH.`);
30052+
await installTrdl(binPath, trdlCli.name, options.version);
30053+
coreExports.info(`Checking installed ${trdlCli.name} version.`);
30054+
await trdlCli.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: 11 additions & 8 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)
@@ -81,31 +82,33 @@ describe('install/action.ts', function () {
8182

8283
await Do(trdlCli, gpgCli, inputs)
8384

84-
expect(toolCache.find).toHaveBeenCalledWith(defaults.repo, inputs.version)
85+
expect(toolCache.find).toHaveBeenCalledWith(trdlCli.name, inputs.version)
8586
expect(trdlCli.mustExist).toHaveBeenCalled()
87+
expect(trdlCli.version).toHaveBeenCalledTimes(2)
8688
expect(trdlCli.update).toHaveBeenCalledWith(defaults)
8789
})
8890
it('should install trdl if tool cache is not found', async function () {
89-
const binPath = 'bin path'
91+
const binPath = '/tmp/cache/path'
9092
const sigPath = 'sig path'
9193
const ascPath = 'asc path'
9294

9395
toolCache.downloadTool.mockResolvedValueOnce(binPath)
9496
toolCache.downloadTool.mockResolvedValueOnce(sigPath)
9597
toolCache.downloadTool.mockResolvedValueOnce(ascPath)
9698

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

100102
await Do(trdlCli, gpgCli, inputs)
101103

102-
expect(toolCache.find).toHaveBeenCalledWith(defaults.repo, inputs.version)
104+
expect(toolCache.find).toHaveBeenCalledWith(trdlCli.name, inputs.version)
103105
expect(gpgCli.mustGnuGP).toHaveBeenCalled()
104106
expect(gpgCli.import).toHaveBeenCalledWith(ascPath)
105107
expect(gpgCli.verify).toHaveBeenCalledWith(sigPath, binPath)
106-
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(toolCache.cacheFile).toHaveBeenCalledWith(binPath, trdlCli.name, trdlCli.name, inputs.version)
109+
expect(core.addPath).toHaveBeenCalledWith(cachedPath)
110+
expect(fs.chmodSync).toHaveBeenCalledWith(join(cachedPath, trdlCli.name), 0o755)
111+
expect(trdlCli.version).toHaveBeenCalled()
109112
})
110113
})
111114
})

install/src/action.ts

Lines changed: 31 additions & 20 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 } 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,13 +91,14 @@ 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-
// set permissions
97-
chmodSync(installedPath, 0o755)
96+
const cachedPath = await cacheFile(binPath, toolName, toolName, toolVersion)
9897
// add tool to $PATH
99-
addPath(installedPath)
98+
addPath(cachedPath)
99+
const cachedFile = join(cachedPath, toolName)
100+
// set permissions
101+
chmodSync(cachedFile, 0o755)
100102
}
101103

102104
export async function Run(): Promise<void> {
@@ -108,43 +110,52 @@ export async function Run(): Promise<void> {
108110
}
109111

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

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

117119
const options = await getOptions(inputs, defaults)
118-
debug(format(`installation options=%o`, options))
120+
info(format(`${trdlCli.name} installation options=%o`, options))
119121

120-
const toolCache = findTrdlCache(defaults.repo, options.version)
122+
const toolCache = findTrdlCache(trdlCli.name, options.version)
121123

122124
if (toolCache) {
123-
info(`Installation skipped. trdl@v${options.version} is found at path ${toolCache}.`)
124-
125+
info(`Installation skipped. ${trdlCli.name}@v${options.version} is found in tool cache ${toolCache}.`)
125126
await trdlCli.mustExist()
126-
info(`Updating trdl to group=${defaults.group} and channel=${defaults.channel}`)
127+
128+
info(`Checking ${trdlCli.name} version before updating.`)
129+
await trdlCli.version()
130+
131+
info(`Updating ${trdlCli.name} to group=${defaults.group} and channel=${defaults.channel}.`)
127132
await trdlCli.update(defaults)
128133

134+
info(`Checking ${trdlCli.name} version after updating.`)
135+
await trdlCli.version()
136+
129137
endGroup()
130138
return
131139
}
132140

133141
await gpgCli.mustGnuGP()
134142

135143
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))
144+
info(`${trdlCli.name} binUrl=${binUrl}`)
145+
info(`${trdlCli.name} sigUrl=${sigUrl}`)
146+
info(`${trdlCli.name} ascUrl=${ascUrl}`)
139147

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

143151
info('Importing and verifying gpg keys.')
144152
await gpgCli.import(ascPath)
145153
await gpgCli.verify(sigPath, binPath)
146154

147-
info('Installing trdl and adding it to the $PATH.')
148-
await installTrdl(defaults.repo, options.version, binPath)
155+
info(`Installing ${trdlCli.name} and adding it to the $PATH.`)
156+
await installTrdl(binPath, trdlCli.name, options.version)
157+
158+
info(`Checking installed ${trdlCli.name} version.`)
159+
await trdlCli.version()
149160
endGroup()
150161
}

lib/exec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export async function execOutput(
1616

1717
const defaultOptions = {
1818
// https://github.com/actions/toolkit/blob/%40actions/exec%401.0.1/packages/exec/src/interfaces.ts#L39
19-
silent: true,
19+
silent: false,
2020
failOnStdErr: true,
2121
listeners: {
2222
stdline(data: string) {

lib/gpg-cli.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ 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], { failOnStdErr: false })
2727
})
2828
})
2929

@@ -33,7 +33,7 @@ describe('gpg-cli.ts', function () {
3333
const binPath = 'bin path'
3434
const result = await cli.verify(sigPath, binPath)
3535
expect(result).toBeUndefined()
36-
expect(libExec.execOutput).toHaveBeenCalledWith(cliName, ['--verify', sigPath, binPath])
36+
expect(libExec.execOutput).toHaveBeenCalledWith(cliName, ['--verify', sigPath, binPath], { failOnStdErr: false })
3737
})
3838
})
3939

@@ -43,7 +43,7 @@ describe('gpg-cli.ts', function () {
4343
libExec.execOutput.mockResolvedValueOnce({ stdout, stderr: [], exitCode: 0 })
4444
const result = await cli.help()
4545
expect(result).toEqual(stdout.join('\n'))
46-
expect(libExec.execOutput).toHaveBeenCalledWith(cliName, ['--help'])
46+
expect(libExec.execOutput).toHaveBeenCalledWith(cliName, ['--help'], { silent: true })
4747
})
4848
})
4949

lib/gpg-cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ 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], { 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], { failOnStdErr: false })
2323
}
2424

2525
async help(): Promise<string> {
26-
const { stdout } = await execOutput(this.name, ['--help'])
26+
const { stdout } = await execOutput(this.name, ['--help'], { silent: true })
2727
return stdout.join('\n')
2828
}
2929
}

0 commit comments

Comments
 (0)