diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 635cf54..5a33890 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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" ] diff --git a/dist/main/index.js b/dist/main/index.js index e5f5f08..c0a4c66 100644 --- a/dist/main/index.js +++ b/dist/main/index.js @@ -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. diff --git a/src/main.ts b/src/main.ts index f005dbe..8c10824 100644 --- a/src/main.ts +++ b/src/main.ts @@ -268,118 +268,125 @@ function dpkg_is_file_included( } async function run_linux(): Promise { - 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() - 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}`) - } + 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'] || '' - const gpgkey = Buffer.from(await response.readBody()) - await exec.exec('sudo apt-key add - ', [], {input: gpgkey}) - }) + 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('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('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('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') + await core.group('Running apt-get update', async () => { + await exec.exec('sudo apt-get update') + }) - 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() + core.startGroup('Installing tarantool') - const dpkg_diff: Array = Array.from(dpkg_after.values()).filter( - pkg => !dpkg_before.has(pkg) - ) + 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() - 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: Array = 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) - } - } + const dpkg_diff: Array = Array.from(dpkg_after.values()).filter( + pkg => !dpkg_before.has(pkg) + ) - try { - await cache.saveCache([cache_dir], cache_key) - core.info(`Cache saved with key: ${cache_key}`) - } catch (error: unknown) { - if (error instanceof Error) { - core.warning(error.message) - } - core.warning(`Saving cache failed, but it's not crucial`) + 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: Array = 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 io.rmRF(cache_dir) + try { + await cache.saveCache([cache_dir], cache_key) + core.info(`Cache saved with key: ${cache_key}`) } catch (error: unknown) { 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) } export async function run(): Promise { - 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`) + } + }) } // Export core.setOutput() to use in testing of setup-tarantool.