Skip to content

Commit b9fa7f1

Browse files
committed
Reorganize code and tests
1 parent bc5faa9 commit b9fa7f1

File tree

6 files changed

+137
-100
lines changed

6 files changed

+137
-100
lines changed

.github/workflows/test.yml

+25-4
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,41 @@ jobs:
99
fail-fast: false
1010
matrix:
1111
runs-on: [ubuntu-20.04]
12-
tarantool: ['1.10', '2.4', '2.5', '2.6', '2.7']
12+
tarantool:
13+
- '1.10'
14+
- '2.4'
15+
- '2.5'
16+
- '2.6'
17+
- '2.7'
18+
- '2.8'
1319
include:
1420
- {runs-on: ubuntu-18.04, tarantool: '1.10'}
1521
- {runs-on: ubuntu-16.04, tarantool: '1.10'}
1622
runs-on: ${{ matrix.runs-on }}
23+
env:
24+
TARANTOOL_CACHE_KEY_SUFFIX: -${{ github.run_id }}
1725
steps:
1826
- uses: actions/checkout@v2
1927

28+
- id: get-latest
29+
run: |
30+
node <<'SCRIPT'
31+
process.env["INPUT_TARANTOOL-VERSION"] = "${{ matrix.tarantool }}"
32+
require("./dist/main").latest_version().then(v => {
33+
console.log(v)
34+
console.log(`::set-output name=version::${v}`)
35+
})
36+
SCRIPT
37+
2038
- name: Setup from scratch
2139
uses: ./
2240
with:
2341
tarantool-version: ${{ matrix.tarantool }}
24-
cache-key: tarantool-${{ matrix.tarantool }}-${{ matrix.runs-on }}-${{ github.run_id }}
42+
43+
- name: Check precise version
44+
run: |
45+
dpkg -s tarantool | grep '^Version: ${{ steps.get-latest.outputs.version }}'
46+
# It'll also fail if tarantool is installed from cache but not from source
2547
2648
- name: Uninstall tarantool
2749
run: sudo apt-get -y remove tarantool tarantool-dev tarantool-common
@@ -30,9 +52,8 @@ jobs:
3052
uses: ./
3153
with:
3254
tarantool-version: ${{ matrix.tarantool }}
33-
cache-key: tarantool-${{ matrix.tarantool }}-${{ matrix.runs-on }}-${{ github.run_id }}
3455

35-
- name: Check version
56+
- name: Check branch version
3657
run: |
3758
T=$(tarantool -e 'print(_TARANTOOL:match("%d+%.%d+")); os.exit()')
3859
if [ "$T" != "${{ matrix.tarantool }}" ]; then

README.md

+1-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This action will set up [Tarantool](https://www.tarantool.io) environment and **
77
- When cached, it takes \~1-2s to finish.
88
- The first run takes \~40s.
99
- Cache size is \~20MB.
10-
- Runs on `ubuntu-*` only.
10+
- Runs on GitHub-hosted `ubuntu-*` runners only.
1111

1212
# Usage
1313

@@ -24,22 +24,6 @@ steps:
2424
- run: .rocks/bin/luatest -v
2525
```
2626
27-
### Custom cache key
28-
29-
By default, the action caches installed apt packages with the key:
30-
31-
```tarantool-setup-${tarantool-version}-${ubuntu-version}```
32-
33-
If you need to drop the cache, it's customizable:
34-
35-
```yaml
36-
steps:
37-
- uses: tarantool/setup-tarantool@v1
38-
with:
39-
tarantool-version: 2.6
40-
cache-key: some-other-key
41-
```
42-
4327
# License
4428
4529
The scripts and documentation in this project are released under the [MIT License](LICENSE).

action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ inputs:
77
tarantool-version:
88
description: Tarantool version
99
cache-key:
10-
description: Custom key used for APT packages caching
10+
description: Deprecated. Custom key used for APT packages caching
1111
required: false
1212
runs:
1313
using: 'node12'
14-
main: dist/main/index.js
14+
main: dist/index.js

dist/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("./main").run()

dist/main/index.js

+52-35
Original file line numberDiff line numberDiff line change
@@ -3392,13 +3392,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
33923392
return result;
33933393
};
33943394
Object.defineProperty(exports, "__esModule", { value: true });
3395+
exports.run = exports.latest_version = void 0;
33953396
const httpm = __importStar(__webpack_require__(539));
33963397
const cache = __importStar(__webpack_require__(692));
33973398
const core = __importStar(__webpack_require__(470));
33983399
const exec = __importStar(__webpack_require__(986));
33993400
const io = __importStar(__webpack_require__(1));
34003401
const path = __importStar(__webpack_require__(622));
34013402
const fs = __importStar(__webpack_require__(747));
3403+
const baseUrl = 'https://download.tarantool.org/tarantool/release/' +
3404+
core.getInput('tarantool-version', { required: true });
34023405
async function capture(cmd, options) {
34033406
let output = '';
34043407
await exec.exec(cmd, [], {
@@ -3411,6 +3414,21 @@ async function capture(cmd, options) {
34113414
});
34123415
return output.trim();
34133416
}
3417+
let _lsb_release;
3418+
async function lsb_release() {
3419+
if (!_lsb_release) {
3420+
_lsb_release = capture('lsb_release -c -s', { silent: true });
3421+
}
3422+
return _lsb_release;
3423+
}
3424+
let _httpc;
3425+
async function http_get(url) {
3426+
if (!_httpc) {
3427+
_httpc = new httpm.HttpClient('httpc');
3428+
}
3429+
core.info('curl ' + url);
3430+
return _httpc.get(url);
3431+
}
34143432
async function dpkg_list() {
34153433
const cmd = 'sudo dpkg-query -W -f "${binary:Package}\\n"';
34163434
const output = await capture(cmd, { silent: true });
@@ -3437,41 +3455,43 @@ function semver_max(a, b) {
34373455
return pa[i] >= pb[i] ? a : b;
34383456
}
34393457
}
3458+
async function latest_version() {
3459+
const repo = baseUrl + '/ubuntu/dists/' + (await lsb_release());
3460+
return http_get(`${repo}/main/binary-amd64/Packages`)
3461+
.then(response => {
3462+
if (response.message.statusCode !== 200) {
3463+
throw new Error(`server replied ${response.message.statusCode}`);
3464+
}
3465+
return response.readBody();
3466+
})
3467+
.then(output => {
3468+
let ret = '';
3469+
output
3470+
.split('\n\n')
3471+
.filter(paragraph => paragraph.startsWith('Package: tarantool\n'))
3472+
.forEach(paragraph => {
3473+
const match = paragraph.match(/^Version: (.+)$/m);
3474+
const version = match ? match[1] : ret;
3475+
ret = semver_max(ret, version);
3476+
});
3477+
return ret;
3478+
});
3479+
}
3480+
exports.latest_version = latest_version;
34403481
async function run_linux() {
34413482
try {
3442-
const httpc = new httpm.HttpClient('httpc');
3443-
const lsb_release = await capture('lsb_release -c -s', { silent: true });
3483+
const distro = await lsb_release();
34443484
const cache_dir = 'cache-tarantool';
3445-
let cache_key = core.getInput('cache-key');
3446-
const baseUrl = 'https://download.tarantool.org/tarantool/release/' +
3447-
core.getInput('tarantool-version', { required: true });
34483485
core.startGroup('Checking latest tarantool version');
3449-
const latest_version = await httpc
3450-
.get(baseUrl + `/ubuntu/dists/${lsb_release}/main/binary-amd64/Packages`)
3451-
.then(response => {
3452-
if (response.message.statusCode !== 200) {
3453-
throw new Error(`server replied ${response.message.statusCode}`);
3454-
}
3455-
return response.readBody();
3456-
})
3457-
.then(output => {
3458-
let ret = '';
3459-
output
3460-
.split('\n\n')
3461-
.filter(paragraph => paragraph.startsWith('Package: tarantool\n'))
3462-
.forEach(paragraph => {
3463-
const match = paragraph.match(/^Version: (.+)$/m);
3464-
const version = match ? match[1] : ret;
3465-
core.info(`Seen ${version}`);
3466-
ret = semver_max(ret, version);
3467-
});
3468-
return ret;
3469-
});
3470-
core.info(`${latest_version}`);
3486+
const version = await latest_version();
3487+
core.info(`${version}`);
34713488
core.endGroup();
3472-
if (!cache_key) {
3473-
cache_key = `tarantool-setup-${lsb_release}-${latest_version}`;
3489+
if (core.getInput('cache-key')) {
3490+
core.warning("Setup-tarantool input 'cache-key' is deprecated");
34743491
}
3492+
let cache_key = `tarantool-setup-${distro}-${version}`;
3493+
// This for testing only
3494+
cache_key += process.env['TARANTOOL_CACHE_KEY_SUFFIX'] || '';
34753495
if (await cache.restoreCache([cache_dir], cache_key)) {
34763496
core.info(`Cache restored from key: ${cache_key}`);
34773497
await exec.exec(`sudo rsync -aK "${cache_dir}/" /`);
@@ -3482,9 +3502,7 @@ async function run_linux() {
34823502
core.info(`Cache not found for input key: ${cache_key}`);
34833503
}
34843504
await core.group('Adding gpg key', async () => {
3485-
const url = baseUrl + '/gpgkey';
3486-
core.info('curl ' + url);
3487-
const response = await httpc.get(url);
3505+
const response = await http_get(baseUrl + '/gpgkey');
34883506
if (response.message.statusCode !== 200) {
34893507
throw new Error(`server replied ${response.message.statusCode}`);
34903508
}
@@ -3493,7 +3511,7 @@ async function run_linux() {
34933511
});
34943512
await core.group('Setting up repository', async () => {
34953513
await exec.exec('sudo tee /etc/apt/sources.list.d/tarantool.list', [], {
3496-
input: Buffer.from(`deb ${baseUrl}/ubuntu/ ${lsb_release} main\n`)
3514+
input: Buffer.from(`deb ${baseUrl}/ubuntu/ ${distro} main\n`)
34973515
});
34983516
});
34993517
await core.group('Running apt-get update', async () => {
@@ -3540,8 +3558,7 @@ async function run() {
35403558
}
35413559
await exec.exec('tarantool --version');
35423560
}
3543-
run();
3544-
exports.default = run;
3561+
exports.run = run;
35453562

35463563

35473564
/***/ }),

src/main.ts

+56-42
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import * as io from '@actions/io'
77
import * as path from 'path'
88
import * as fs from 'fs'
99

10+
const baseUrl =
11+
'https://download.tarantool.org/tarantool/release/' +
12+
core.getInput('tarantool-version', {required: true})
13+
1014
interface CaptureOptions {
1115
/** optional. defaults to false */
1216
silent?: boolean
@@ -27,6 +31,24 @@ async function capture(cmd: string, options?: CaptureOptions): Promise<string> {
2731
return output.trim()
2832
}
2933

34+
let _lsb_release: Promise<string>
35+
async function lsb_release(): Promise<string> {
36+
if (!_lsb_release) {
37+
_lsb_release = capture('lsb_release -c -s', {silent: true})
38+
}
39+
40+
return _lsb_release
41+
}
42+
43+
let _httpc: httpm.HttpClient
44+
async function http_get(url: string): Promise<httpm.HttpClientResponse> {
45+
if (!_httpc) {
46+
_httpc = new httpm.HttpClient('httpc')
47+
}
48+
core.info('curl ' + url)
49+
return _httpc.get(url)
50+
}
51+
3052
async function dpkg_list(): Promise<Set<string>> {
3153
const cmd = 'sudo dpkg-query -W -f "${binary:Package}\\n"'
3254
const output: string = await capture(cmd, {silent: true})
@@ -51,46 +73,45 @@ function semver_max(a: string, b: string): string {
5173
}
5274
}
5375

76+
export async function latest_version(): Promise<string> {
77+
const repo = baseUrl + '/ubuntu/dists/' + (await lsb_release())
78+
return http_get(`${repo}/main/binary-amd64/Packages`)
79+
.then(response => {
80+
if (response.message.statusCode !== 200) {
81+
throw new Error(`server replied ${response.message.statusCode}`)
82+
}
83+
return response.readBody()
84+
})
85+
.then(output => {
86+
let ret = ''
87+
output
88+
.split('\n\n')
89+
.filter(paragraph => paragraph.startsWith('Package: tarantool\n'))
90+
.forEach(paragraph => {
91+
const match = paragraph.match(/^Version: (.+)$/m)
92+
const version = match ? match[1] : ret
93+
ret = semver_max(ret, version)
94+
})
95+
return ret
96+
})
97+
}
98+
5499
async function run_linux(): Promise<void> {
55100
try {
56-
const httpc = new httpm.HttpClient('httpc')
57-
const lsb_release = await capture('lsb_release -c -s', {silent: true})
101+
const distro = await lsb_release()
58102
const cache_dir = 'cache-tarantool'
59-
let cache_key = core.getInput('cache-key')
60-
61-
const baseUrl =
62-
'https://download.tarantool.org/tarantool/release/' +
63-
core.getInput('tarantool-version', {required: true})
64103

65104
core.startGroup('Checking latest tarantool version')
66-
const latest_version = await httpc
67-
.get(baseUrl + `/ubuntu/dists/${lsb_release}/main/binary-amd64/Packages`)
68-
.then(response => {
69-
if (response.message.statusCode !== 200) {
70-
throw new Error(`server replied ${response.message.statusCode}`)
71-
}
72-
return response.readBody()
73-
})
74-
.then(output => {
75-
let ret = ''
76-
output
77-
.split('\n\n')
78-
.filter(paragraph => paragraph.startsWith('Package: tarantool\n'))
79-
.forEach(paragraph => {
80-
const match = paragraph.match(/^Version: (.+)$/m)
81-
const version = match ? match[1] : ret
82-
core.info(`Seen ${version}`)
83-
ret = semver_max(ret, version)
84-
})
85-
return ret
86-
})
87-
88-
core.info(`${latest_version}`)
105+
const version = await latest_version()
106+
core.info(`${version}`)
89107
core.endGroup()
90108

91-
if (!cache_key) {
92-
cache_key = `tarantool-setup-${lsb_release}-${latest_version}`
109+
if (core.getInput('cache-key')) {
110+
core.warning("Setup-tarantool input 'cache-key' is deprecated")
93111
}
112+
let cache_key = `tarantool-setup-${distro}-${version}`
113+
// This for testing only
114+
cache_key += process.env['TARANTOOL_CACHE_KEY_SUFFIX'] || ''
94115

95116
if (await cache.restoreCache([cache_dir], cache_key)) {
96117
core.info(`Cache restored from key: ${cache_key}`)
@@ -102,10 +123,7 @@ async function run_linux(): Promise<void> {
102123
}
103124

104125
await core.group('Adding gpg key', async () => {
105-
const url = baseUrl + '/gpgkey'
106-
core.info('curl ' + url)
107-
108-
const response = await httpc.get(url)
126+
const response = await http_get(baseUrl + '/gpgkey')
109127
if (response.message.statusCode !== 200) {
110128
throw new Error(`server replied ${response.message.statusCode}`)
111129
}
@@ -116,7 +134,7 @@ async function run_linux(): Promise<void> {
116134

117135
await core.group('Setting up repository', async () => {
118136
await exec.exec('sudo tee /etc/apt/sources.list.d/tarantool.list', [], {
119-
input: Buffer.from(`deb ${baseUrl}/ubuntu/ ${lsb_release} main\n`)
137+
input: Buffer.from(`deb ${baseUrl}/ubuntu/ ${distro} main\n`)
120138
})
121139
})
122140

@@ -164,7 +182,7 @@ async function run_linux(): Promise<void> {
164182
}
165183
}
166184

167-
async function run(): Promise<void> {
185+
export async function run(): Promise<void> {
168186
if (process.platform === 'linux') {
169187
await run_linux()
170188
} else {
@@ -173,7 +191,3 @@ async function run(): Promise<void> {
173191

174192
await exec.exec('tarantool --version')
175193
}
176-
177-
run()
178-
179-
export default run

0 commit comments

Comments
 (0)