Skip to content

Commit 0105f29

Browse files
authored
Cleanup the action (#4)
1 parent c36c38f commit 0105f29

File tree

4 files changed

+78
-85
lines changed

4 files changed

+78
-85
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
runs-on: [ubuntu-latest]
11+
runs-on: [ubuntu-20.04]
1212
tarantool: ['1.10', '2.4', '2.5', '2.6', '2.7']
13+
include:
14+
- {runs-on: ubuntu-18.04, tarantool: '1.10'}
15+
- {runs-on: ubuntu-16.04, tarantool: '1.10'}
1316
runs-on: ${{ matrix.runs-on }}
1417
steps:
1518
- uses: actions/checkout@v2
@@ -18,7 +21,7 @@ jobs:
1821
uses: ./
1922
with:
2023
tarantool-version: ${{ matrix.tarantool }}
21-
cache-key: tarantool-${{ matrix.tarantool }}-${{ runner.os }}-${{ github.run_id }}
24+
cache-key: tarantool-${{ matrix.tarantool }}-${{ matrix.runs-on }}-${{ github.run_id }}
2225

2326
- name: Uninstall tarantool
2427
run: sudo apt-get -y remove tarantool tarantool-dev tarantool-common
@@ -27,9 +30,8 @@ jobs:
2730
uses: ./
2831
with:
2932
tarantool-version: ${{ matrix.tarantool }}
30-
cache-key: tarantool-${{ matrix.tarantool }}-${{ runner.os }}-${{ github.run_id }}
33+
cache-key: tarantool-${{ matrix.tarantool }}-${{ matrix.runs-on }}-${{ github.run_id }}
3134

32-
- run: tarantool --version
3335
- name: Check version
3436
run: |
3537
T=$(tarantool -e 'print(_TARANTOOL:match("%d+%.%d+")); os.exit()')

action.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ name: 'Setup tarantool'
22
description: 'Setup tarantool environment and add it to the PATH'
33
inputs:
44
tarantool-version:
5-
description: 'Tarantool version'
6-
default: '2.5'
5+
description: Tarantool version
76
cache-key:
8-
description: >
9-
Custom key used for apt packages caching.
10-
Default is "tarantool-<VERSION>-<RUNNER.OS>"
7+
description: Custom key used for APT packages caching
118
required: false
129
runs:
1310
using: 'node12'

dist/main/index.js

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,18 +3422,19 @@ async function run_linux() {
34223422
try {
34233423
const httpc = new httpm.HttpClient('httpc');
34243424
const t_version = core.getInput('tarantool-version', { required: true });
3425-
let cache_key = core.getInput('cache-key', { required: false });
3426-
if (!cache_key) {
3427-
cache_key = 'tarantool-setup-' + process.platform + '-' + t_version;
3428-
}
3429-
const cache_dir = path.join(cache_key);
3425+
const lsb_release = await capture('lsb_release -c -s', { silent: true });
3426+
const cache_dir = 'cache-tarantool';
3427+
const cache_key = core.getInput('cache-key') ||
3428+
`tarantool-setup-${t_version}-${lsb_release}`;
34303429
if (await cache.restoreCache([cache_dir], cache_key)) {
3431-
for (const f of fs.readdirSync(cache_dir)) {
3432-
await exec.exec(`sudo cp -f -r "${cache_dir}/${f}" /`);
3433-
}
3430+
core.info(`Cache restored from key: ${cache_key}`);
3431+
await exec.exec(`sudo rsync -aK "${cache_dir}/" /`);
34343432
await io.rmRF(cache_dir);
34353433
return;
34363434
}
3435+
else {
3436+
core.info(`Cache not found for input key: ${cache_key}`);
3437+
}
34373438
const baseUrl = 'https://download.tarantool.org/tarantool/release/' + t_version;
34383439
await core.group('Adding gpg key', async () => {
34393440
const url = baseUrl + '/gpgkey';
@@ -3446,51 +3447,47 @@ async function run_linux() {
34463447
await exec.exec('sudo apt-key add - ', [], { input: gpgkey });
34473448
});
34483449
await core.group('Setting up repository', async () => {
3449-
const release = await capture('lsb_release -c -s');
34503450
await exec.exec('sudo tee /etc/apt/sources.list.d/tarantool.list', [], {
3451-
input: Buffer.from(`deb ${baseUrl}/ubuntu/ ${release} main\n`)
3451+
input: Buffer.from(`deb ${baseUrl}/ubuntu/ ${lsb_release} main\n`)
34523452
});
34533453
});
34543454
await core.group('Running apt-get update', async () => {
34553455
await exec.exec('sudo apt-get update');
34563456
});
3457-
let dpkg_diff;
3458-
await core.group('Installing tarantool', async () => {
3459-
const dpkg_before = await dpkg_list();
3460-
await exec.exec('sudo apt-get install -y tarantool tarantool-dev');
3461-
const dpkg_after = await dpkg_list();
3462-
dpkg_diff = Array.from(dpkg_after.values()).filter(pkg => !dpkg_before.has(pkg));
3463-
});
3464-
await core.group('Cache apt packages', async () => {
3465-
core.info('Will cache ' + dpkg_diff.join(', '));
3466-
// let paths: Array<string> = []
3467-
for (const pkg of dpkg_diff) {
3468-
const output = await capture(`sudo dpkg -L ${pkg}`, { silent: true });
3469-
const files = output
3470-
.split('\n')
3471-
.filter(f => fs.statSync(f).isFile());
3472-
for (const f of files) {
3473-
const dest = path.join(cache_dir, path.dirname(f));
3474-
await io.mkdirP(dest);
3475-
await io.cp(f, dest);
3476-
}
3477-
}
3478-
await cache.saveCache([cache_dir], cache_key);
3479-
core.info(`Cache saved with key: ${cache_key}`);
3480-
await io.rmRF(cache_dir);
3481-
});
3457+
core.startGroup('Installing tarantool');
3458+
const dpkg_before = await dpkg_list();
3459+
await exec.exec('sudo apt-get install -y tarantool tarantool-dev');
3460+
const dpkg_after = await dpkg_list();
3461+
const dpkg_diff = Array.from(dpkg_after.values()).filter(pkg => !dpkg_before.has(pkg));
3462+
core.endGroup();
3463+
core.info('Caching APT packages: ' + dpkg_diff.join(', '));
3464+
for (const pkg of dpkg_diff) {
3465+
const output = await capture(`sudo dpkg -L ${pkg}`, { silent: true });
3466+
const files = output
3467+
.split('\n')
3468+
.filter(f => fs.statSync(f).isFile());
3469+
for (const f of files) {
3470+
const dest = path.join(cache_dir, path.dirname(f));
3471+
await io.mkdirP(dest);
3472+
await io.cp(f, dest);
3473+
}
3474+
}
3475+
await cache.saveCache([cache_dir], cache_key);
3476+
core.info(`Cache saved with key: ${cache_key}`);
3477+
await io.rmRF(cache_dir);
34823478
}
34833479
catch (error) {
34843480
core.setFailed(error.message);
34853481
}
34863482
}
34873483
async function run() {
34883484
if (process.platform === 'linux') {
3489-
return await run_linux();
3485+
await run_linux();
34903486
}
34913487
else {
34923488
core.setFailed(`Action doesn't support ${process.platform} platform`);
34933489
}
3490+
await exec.exec('tarantool --version');
34943491
}
34953492
run();
34963493
exports.default = run;

src/main.ts

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,19 @@ async function run_linux(): Promise<void> {
4040
try {
4141
const httpc = new httpm.HttpClient('httpc')
4242
const t_version = core.getInput('tarantool-version', {required: true})
43-
44-
let cache_key = core.getInput('cache-key', {required: false})
45-
if (!cache_key) {
46-
cache_key = 'tarantool-setup-' + process.platform + '-' + t_version
47-
}
48-
49-
const cache_dir = path.join(cache_key)
43+
const lsb_release = await capture('lsb_release -c -s', {silent: true})
44+
const cache_dir = 'cache-tarantool'
45+
const cache_key =
46+
core.getInput('cache-key') ||
47+
`tarantool-setup-${t_version}-${lsb_release}`
5048

5149
if (await cache.restoreCache([cache_dir], cache_key)) {
52-
for (const f of fs.readdirSync(cache_dir)) {
53-
await exec.exec(`sudo cp -f -r "${cache_dir}/${f}" /`)
54-
}
50+
core.info(`Cache restored from key: ${cache_key}`)
51+
await exec.exec(`sudo rsync -aK "${cache_dir}/" /`)
5552
await io.rmRF(cache_dir)
5653
return
54+
} else {
55+
core.info(`Cache not found for input key: ${cache_key}`)
5756
}
5857

5958
const baseUrl =
@@ -73,59 +72,57 @@ async function run_linux(): Promise<void> {
7372
})
7473

7574
await core.group('Setting up repository', async () => {
76-
const release = await capture('lsb_release -c -s')
7775
await exec.exec('sudo tee /etc/apt/sources.list.d/tarantool.list', [], {
78-
input: Buffer.from(`deb ${baseUrl}/ubuntu/ ${release} main\n`)
76+
input: Buffer.from(`deb ${baseUrl}/ubuntu/ ${lsb_release} main\n`)
7977
})
8078
})
8179

8280
await core.group('Running apt-get update', async () => {
8381
await exec.exec('sudo apt-get update')
8482
})
8583

86-
let dpkg_diff: Array<string>
84+
core.startGroup('Installing tarantool')
8785

88-
await core.group('Installing tarantool', async () => {
89-
const dpkg_before = await dpkg_list()
90-
await exec.exec('sudo apt-get install -y tarantool tarantool-dev')
91-
const dpkg_after = await dpkg_list()
86+
const dpkg_before = await dpkg_list()
87+
await exec.exec('sudo apt-get install -y tarantool tarantool-dev')
88+
const dpkg_after = await dpkg_list()
9289

93-
dpkg_diff = Array.from(dpkg_after.values()).filter(
94-
pkg => !dpkg_before.has(pkg)
95-
)
96-
})
90+
const dpkg_diff: Array<string> = Array.from(dpkg_after.values()).filter(
91+
pkg => !dpkg_before.has(pkg)
92+
)
93+
94+
core.endGroup()
9795

98-
await core.group('Cache apt packages', async () => {
99-
core.info('Will cache ' + dpkg_diff.join(', '))
100-
// let paths: Array<string> = []
101-
102-
for (const pkg of dpkg_diff) {
103-
const output = await capture(`sudo dpkg -L ${pkg}`, {silent: true})
104-
const files: Array<string> = output
105-
.split('\n')
106-
.filter(f => fs.statSync(f).isFile())
107-
for (const f of files) {
108-
const dest = path.join(cache_dir, path.dirname(f))
109-
await io.mkdirP(dest)
110-
await io.cp(f, dest)
111-
}
96+
core.info('Caching APT packages: ' + dpkg_diff.join(', '))
97+
98+
for (const pkg of dpkg_diff) {
99+
const output = await capture(`sudo dpkg -L ${pkg}`, {silent: true})
100+
const files: Array<string> = output
101+
.split('\n')
102+
.filter(f => fs.statSync(f).isFile())
103+
for (const f of files) {
104+
const dest = path.join(cache_dir, path.dirname(f))
105+
await io.mkdirP(dest)
106+
await io.cp(f, dest)
112107
}
108+
}
113109

114-
await cache.saveCache([cache_dir], cache_key)
115-
core.info(`Cache saved with key: ${cache_key}`)
116-
await io.rmRF(cache_dir)
117-
})
110+
await cache.saveCache([cache_dir], cache_key)
111+
core.info(`Cache saved with key: ${cache_key}`)
112+
await io.rmRF(cache_dir)
118113
} catch (error) {
119114
core.setFailed(error.message)
120115
}
121116
}
122117

123118
async function run(): Promise<void> {
124119
if (process.platform === 'linux') {
125-
return await run_linux()
120+
await run_linux()
126121
} else {
127122
core.setFailed(`Action doesn't support ${process.platform} platform`)
128123
}
124+
125+
await exec.exec('tarantool --version')
129126
}
130127

131128
run()

0 commit comments

Comments
 (0)