Skip to content

bugfix: verify presence of the given version #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,23 @@ jobs:
with:
tarantool-version: '${{ matrix.tarantool }}'
from-cache: true

# There is no 1.10.999 build. Verify that an attempt to install
# it fails.
test-unknown-version:
runs-on: ubuntu-latest
env:
TARANTOOL_CACHE_KEY_SUFFIX: -H-${{ github.run_id }}
steps:
- uses: actions/checkout@v4

- name: Attempt to install 1.10.999 (expect failure)
uses: ./
with:
tarantool-version: '1.10.999'
continue-on-error: true
id: install

- name: Verify that the previous step fails
run: |
[ "${{ steps.install.outcome }}" = "failure" ]
167 changes: 85 additions & 82 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62542,102 +62542,105 @@ function dpkg_is_file_included(dpkgConfig, filepath) {
return included;
}
async function run_linux() {
try {
const distro = await lsb_release();
const distro_id = (await lsb_release_id()).toLowerCase();
const cache_dir = 'cache-tarantool';
const baseUrl = construct_base_url();
core.startGroup(`Checking latest tarantool ${tarantool_version} version`);
const version = await latest_version(tarantool_version);
core.info(`${version}`);
core.endGroup();
if (core.getInput('cache-key')) {
core.warning("Setup-tarantool input 'cache-key' is deprecated");
}
let cache_key = `tarantool-setup-${distro}-${version}`;
// This for testing only
cache_key += process.env['TARANTOOL_CACHE_KEY_SUFFIX'] || '';
if (await cache.restoreCache([cache_dir], cache_key)) {
core.info(`Cache restored from key: ${cache_key}`);
await exec.exec(`sudo rsync -aK "${cache_dir}/" /`);
await io.rmRF(cache_dir);
return;
}
else {
core.info(`Cache not found for input key: ${cache_key}`);
const distro = await lsb_release();
const distro_id = (await lsb_release_id()).toLowerCase();
const cache_dir = 'cache-tarantool';
const baseUrl = construct_base_url();
core.startGroup(`Checking latest tarantool ${tarantool_version} version`);
const version = await latest_version(tarantool_version);
if (version == '') {
throw new Error(`There is no tarantool ${tarantool_version} for ` +
`${distro_id} ${distro}`);
}
core.info(`${version}`);
core.endGroup();
if (core.getInput('cache-key')) {
core.warning("Setup-tarantool input 'cache-key' is deprecated");
}
let cache_key = `tarantool-setup-${distro}-${version}`;
// This for testing only
cache_key += process.env['TARANTOOL_CACHE_KEY_SUFFIX'] || '';
if (await cache.restoreCache([cache_dir], cache_key)) {
core.info(`Cache restored from key: ${cache_key}`);
await exec.exec(`sudo rsync -aK "${cache_dir}/" /`);
await io.rmRF(cache_dir);
return;
}
else {
core.info(`Cache not found for input key: ${cache_key}`);
}
await core.group('Adding gpg key', async () => {
const response = await http_get(baseUrl + '/gpgkey');
if (response.message.statusCode !== 200) {
throw new Error(`server replied ${response.message.statusCode}`);
}
await core.group('Adding gpg key', async () => {
const response = await http_get(baseUrl + '/gpgkey');
if (response.message.statusCode !== 200) {
throw new Error(`server replied ${response.message.statusCode}`);
}
const gpgkey = Buffer.from(await response.readBody());
await exec.exec('sudo apt-key add - ', [], { input: gpgkey });
});
await core.group('Setting up repository', async () => {
await exec.exec('sudo tee /etc/apt/sources.list.d/tarantool.list', [], {
input: Buffer.from(`deb ${baseUrl}/${distro_id}/ ${distro} main\n`)
});
});
await core.group('Running apt-get update', async () => {
await exec.exec('sudo apt-get update');
const gpgkey = Buffer.from(await response.readBody());
await exec.exec('sudo apt-key add - ', [], { input: gpgkey });
});
await core.group('Setting up repository', async () => {
await exec.exec('sudo tee /etc/apt/sources.list.d/tarantool.list', [], {
input: Buffer.from(`deb ${baseUrl}/${distro_id}/ ${distro} main\n`)
});
core.startGroup('Installing tarantool');
const dpkg_before = await dpkg_list();
await exec.exec(`sudo apt-get install -y tarantool=${version}* tarantool-dev=${version}*`);
const dpkg_after = await dpkg_list();
const dpkg_diff = Array.from(dpkg_after.values()).filter(pkg => !dpkg_before.has(pkg));
core.endGroup();
core.info('Caching APT packages: ' + dpkg_diff.join(', '));
for (const pkg of dpkg_diff) {
const dpkgConfig = dpkg_read_config();
const output = await capture(`sudo dpkg -L ${pkg}`, { silent: true });
const files = output
.split('\n')
.filter(f => dpkg_is_file_included(dpkgConfig, f))
.filter(f => {
try {
return fs.statSync(f).isFile();
}
catch (err) {
throw new Error(`Error while checking file ${f} from package ${pkg}: ${err}`);
}
});
for (const f of files) {
const dest = path.join(cache_dir, path.dirname(f));
await io.mkdirP(dest);
await io.cp(f, dest);
});
await core.group('Running apt-get update', async () => {
await exec.exec('sudo apt-get update');
});
core.startGroup('Installing tarantool');
const dpkg_before = await dpkg_list();
await exec.exec(`sudo apt-get install -y tarantool=${version}* tarantool-dev=${version}*`);
const dpkg_after = await dpkg_list();
const dpkg_diff = Array.from(dpkg_after.values()).filter(pkg => !dpkg_before.has(pkg));
core.endGroup();
core.info('Caching APT packages: ' + dpkg_diff.join(', '));
for (const pkg of dpkg_diff) {
const dpkgConfig = dpkg_read_config();
const output = await capture(`sudo dpkg -L ${pkg}`, { silent: true });
const files = output
.split('\n')
.filter(f => dpkg_is_file_included(dpkgConfig, f))
.filter(f => {
try {
return fs.statSync(f).isFile();
}
}
try {
await cache.saveCache([cache_dir], cache_key);
core.info(`Cache saved with key: ${cache_key}`);
}
catch (error) {
if (error instanceof Error) {
core.warning(error.message);
catch (err) {
throw new Error(`Error while checking file ${f} from package ${pkg}: ${err}`);
}
core.warning(`Saving cache failed, but it's not crucial`);
});
for (const f of files) {
const dest = path.join(cache_dir, path.dirname(f));
await io.mkdirP(dest);
await io.cp(f, dest);
}
await io.rmRF(cache_dir);
}
try {
await cache.saveCache([cache_dir], cache_key);
core.info(`Cache saved with key: ${cache_key}`);
}
catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
}
else {
core.setFailed(`No error message`);
core.warning(error.message);
}
core.warning(`Saving cache failed, but it's not crucial`);
}
await io.rmRF(cache_dir);
}
async function run() {
if (process.platform === 'linux') {
await run_linux();
}
else {
if (process.platform !== 'linux') {
core.setFailed(`Action doesn't support ${process.platform} platform`);
return;
}
await exec.exec('tarantool --version');
await run_linux()
.then(_ => {
return exec.exec('tarantool --version');
})
.catch(error => {
if (error instanceof Error) {
core.setFailed(error.message);
}
else {
core.setFailed(`No error message`);
}
});
}
exports.run = run;
// Export core.setOutput() to use in testing of setup-tarantool.
Expand Down
Loading