Skip to content

Update tarantool if there is more fresh version #14

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 1 commit into from
Feb 10, 2021
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
32 changes: 27 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,41 @@ jobs:
fail-fast: false
matrix:
runs-on: [ubuntu-20.04]
tarantool: ['1.10', '2.4', '2.5', '2.6', '2.7']
tarantool:
- '1.10'
- '2.4'
- '2.5'
- '2.6'
- '2.7'
- '2.8'
include:
- {runs-on: ubuntu-18.04, tarantool: '1.10'}
- {runs-on: ubuntu-16.04, tarantool: '1.10'}
runs-on: ${{ matrix.runs-on }}
env:
TARANTOOL_CACHE_KEY_SUFFIX: -${{ github.run_id }}
steps:
- uses: actions/checkout@v2

- id: get-latest
run: |
node <<'SCRIPT'
process.env["INPUT_TARANTOOL-VERSION"] = "${{ matrix.tarantool }}"
require("./dist/main").latest_version().then(v => {
console.log(v)
console.log(`::set-output name=version::${v}`)
})
SCRIPT

- name: Setup from scratch
uses: ./
with:
tarantool-version: ${{ matrix.tarantool }}
cache-key: tarantool-${{ matrix.tarantool }}-${{ matrix.runs-on }}-${{ github.run_id }}

- name: Check precise version
run: |
dpkg -s tarantool | grep '^Version: ${{ steps.get-latest.outputs.version }}'
# It'll also fail if tarantool is installed from cache but not from apt-get

- name: Uninstall tarantool
run: sudo apt-get -y remove tarantool tarantool-dev tarantool-common
Expand All @@ -30,9 +52,8 @@ jobs:
uses: ./
with:
tarantool-version: ${{ matrix.tarantool }}
cache-key: tarantool-${{ matrix.tarantool }}-${{ matrix.runs-on }}-${{ github.run_id }}

- name: Check version
- name: Check branch version
run: |
T=$(tarantool -e 'print(_TARANTOOL:match("%d+%.%d+")); os.exit()')
if [ "$T" != "${{ matrix.tarantool }}" ]; then
Expand All @@ -48,10 +69,11 @@ jobs:
matrix:
runs-on: [ubuntu-20.04, ubuntu-20.04, ubuntu-20.04]
runs-on: ${{ matrix.runs-on }}
env:
TARANTOOL_CACHE_KEY_SUFFIX: -${{ github.run_id }}
steps:
- uses: actions/checkout@v2
- name: Setup Tarantool
uses: ./
with:
tarantool-version: '1.10'
cache-key: test-concurrency-${{ github.run_id }}
20 changes: 2 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This action will set up [Tarantool](https://www.tarantool.io) environment and **
- When cached, it takes \~1-2s to finish.
- The first run takes \~40s.
- Cache size is \~20MB.
- Runs on `ubuntu-*` only.
- Runs on GitHub-hosted `ubuntu-*` runners only.

# Usage

Expand All @@ -18,28 +18,12 @@ steps:
- uses: actions/checkout@v2
- uses: tarantool/setup-tarantool@v1
with:
tarantool-version: '2.5'
tarantool-version: '2.6'
- run: tarantoolctl rocks install luatest
- run: tarantoolctl rocks make
- run: .rocks/bin/luatest -v
```

### Custom cache key

By default, the action caches installed apt packages with the key:

```tarantool-setup-${tarantool-version}-${ubuntu-version}```

If you need to drop the cache, it's customizable:

```yaml
steps:
- uses: tarantool/setup-tarantool@v1
with:
tarantool-version: 2.5
cache-key: some-other-key
```

# License

The scripts and documentation in this project are released under the [MIT License](LICENSE).
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ inputs:
tarantool-version:
description: Tarantool version
cache-key:
description: Custom key used for APT packages caching
description: Deprecated. Custom key used for APT packages caching
required: false
runs:
using: 'node12'
main: dist/main/index.js
main: dist/index.js
1 change: 1 addition & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("./main").run()
88 changes: 75 additions & 13 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3392,13 +3392,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = exports.latest_version = void 0;
const httpm = __importStar(__webpack_require__(539));
const cache = __importStar(__webpack_require__(692));
const core = __importStar(__webpack_require__(470));
const exec = __importStar(__webpack_require__(986));
const io = __importStar(__webpack_require__(1));
const path = __importStar(__webpack_require__(622));
const fs = __importStar(__webpack_require__(747));
const baseUrl = 'https://download.tarantool.org/tarantool/release/' +
core.getInput('tarantool-version', { required: true });
async function capture(cmd, options) {
let output = '';
await exec.exec(cmd, [], {
Expand All @@ -3411,21 +3414,84 @@ async function capture(cmd, options) {
});
return output.trim();
}
let _lsb_release;
async function lsb_release() {
if (!_lsb_release) {
_lsb_release = capture('lsb_release -c -s', { silent: true });
}
return _lsb_release;
}
let _httpc;
async function http_get(url) {
if (!_httpc) {
_httpc = new httpm.HttpClient('httpc');
}
core.info('HTTP GET ' + url);
return _httpc.get(url);
}
async function dpkg_list() {
const cmd = 'sudo dpkg-query -W -f "${binary:Package}\\n"';
const output = await capture(cmd, { silent: true });
let ret = new Set();
output.split('\n').forEach(l => ret.add(l));
return ret;
}
function semver_max(a, b) {
const re = /[.-]/;
var pa = a.split(re);
var pb = b.split(re);
for (var i = 0;; i++) {
var na = Number(pa[i]);
var nb = Number(pb[i]);
if (na > nb)
return a;
if (nb > na)
return b;
if (!isNaN(na) && isNaN(nb))
return a;
if (isNaN(na) && !isNaN(nb))
return b;
if (isNaN(na) && isNaN(nb))
return pa[i] >= pb[i] ? a : b;
}
}
async function latest_version() {
const repo = baseUrl + '/ubuntu/dists/' + (await lsb_release());
return http_get(`${repo}/main/binary-amd64/Packages`)
.then(response => {
if (response.message.statusCode !== 200) {
throw new Error(`server replied ${response.message.statusCode}`);
}
return response.readBody();
})
.then(output => {
let ret = '';
output
.split('\n\n')
.filter(paragraph => paragraph.startsWith('Package: tarantool\n'))
.forEach(paragraph => {
const match = paragraph.match(/^Version: (.+)$/m);
const version = match ? match[1] : ret;
ret = semver_max(ret, version);
});
return ret;
});
}
exports.latest_version = latest_version;
async function run_linux() {
try {
const httpc = new httpm.HttpClient('httpc');
const t_version = core.getInput('tarantool-version', { required: true });
const lsb_release = await capture('lsb_release -c -s', { silent: true });
const distro = await lsb_release();
const cache_dir = 'cache-tarantool';
const cache_key = core.getInput('cache-key') ||
`tarantool-setup-${t_version}-${lsb_release}`;
core.startGroup('Checking latest tarantool version');
const version = await latest_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}/" /`);
Expand All @@ -3435,20 +3501,17 @@ async function run_linux() {
else {
core.info(`Cache not found for input key: ${cache_key}`);
}
const baseUrl = 'https://download.tarantool.org/tarantool/release/' + t_version;
await core.group('Adding gpg key', async () => {
const url = baseUrl + '/gpgkey';
core.info('curl ' + url);
const response = await httpc.get(url);
const response = await http_get(baseUrl + '/gpgkey');
if (response.message.statusCode !== 200) {
throw new Error('server replied ${response.message.statusCode}');
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}/ubuntu/ ${lsb_release} main\n`)
input: Buffer.from(`deb ${baseUrl}/ubuntu/ ${distro} main\n`)
});
});
await core.group('Running apt-get update', async () => {
Expand Down Expand Up @@ -3495,8 +3558,7 @@ async function run() {
}
await exec.exec('tarantool --version');
}
run();
exports.default = run;
exports.run = run;


/***/ }),
Expand Down
Loading