diff --git a/.github/workflows/test_start_stop.yml b/.github/workflows/test_start_stop.yml index c054624..f9a817e 100644 --- a/.github/workflows/test_start_stop.yml +++ b/.github/workflows/test_start_stop.yml @@ -40,40 +40,40 @@ jobs: job-secret: ${{ secrets.JOB_SECRET }} backend: aws profile: ci-test-start-stop - - test-runner-alive: - name: Test runner is alive - needs: [ action-start ] - uses: ./.github/workflows/registered_runner.yml - with: - runner-name: ci-persistent-runner - - action-stop: - name: GitHub Actions Test (stop) - runs-on: ubuntu-latest - needs: [ action-start, test-runner-alive ] - if: ${{ always() && needs.action-start.result != 'skipped' }} - steps: - - name: Checkout - id: checkout - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 - - - name: Test stop instance - id: test-stop - uses: ./ - with: - mode: stop - github-token: ${{ secrets.SLAB_ACTION_TOKEN }} - slab-url: ${{ secrets.SLAB_BASE_URL_PRE_PROD }} - job-secret: ${{ secrets.JOB_SECRET }} - label: ci-persistent-runner - - test-runner-persist: - name: Test runner is still registered - needs: [ action-stop ] - uses: ./.github/workflows/removed_runner.yml - with: - runner-name: ci-persistent-runner - must-exist: true - secrets: - READ_REPO_TOKEN: ${{ secrets.SLAB_ACTION_TOKEN }} +# +# test-runner-alive: +# name: Test runner is alive +# needs: [ action-start ] +# uses: ./.github/workflows/registered_runner.yml +# with: +# runner-name: ci-persistent-runner +# +# action-stop: +# name: GitHub Actions Test (stop) +# runs-on: ubuntu-latest +# needs: [ action-start, test-runner-alive ] +# if: ${{ always() && needs.action-start.result != 'skipped' }} +# steps: +# - name: Checkout +# id: checkout +# uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 +# +# - name: Test stop instance +# id: test-stop +# uses: ./ +# with: +# mode: stop +# github-token: ${{ secrets.SLAB_ACTION_TOKEN }} +# slab-url: ${{ secrets.SLAB_BASE_URL_PRE_PROD }} +# job-secret: ${{ secrets.JOB_SECRET }} +# label: ci-persistent-runner +# +# test-runner-persist: +# name: Test runner is still registered +# needs: [ action-stop ] +# uses: ./.github/workflows/removed_runner.yml +# with: +# runner-name: ci-persistent-runner +# must-exist: true +# secrets: +# READ_REPO_TOKEN: ${{ secrets.SLAB_ACTION_TOKEN }} diff --git a/dist/index.js b/dist/index.js index 4abb551..a9c2401 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49835,7 +49835,7 @@ async function waitForInstance(taskId, taskName) { const task_status = body[taskName].status.toLowerCase() if (task_status === 'done') { - await removeTask(taskId) + // await removeTask(taskId) return body } else if (task_status === 'failed') { core.error(`Instance task failed (details: ${body[taskName].details})`) @@ -51855,11 +51855,27 @@ const slab = __nccwpck_require__(4156) const config = __nccwpck_require__(4570) const core = __nccwpck_require__(2186) const { waitForRunnerRegistered } = __nccwpck_require__(6989) +const utils = __nccwpck_require__(1608) function setOutput(label) { core.setOutput('label', label) } +// This variable should only be defined for cleanup purpose. +let runner_name + +async function cleanup() { + if (runner_name) { + core.info('Stop instance after cancellation') + await slab.stopInstanceRequest(runner_name) + } +} + +process.on('SIGINT', async function () { + await cleanup() + process.exit() +}) + async function start() { const provider = config.input.backend @@ -51868,6 +51884,7 @@ async function start() { for (let i = 1; i <= 3; i++) { try { start_instance_response = await slab.startInstanceRequest() + runner_name = start_instance_response.runner_name break } catch (error) { core.info('Retrying request now...') @@ -51886,6 +51903,9 @@ async function start() { )}` ) + core.info('[DEBUG] About to wait 30 seconds for cancelation') // DEBUG + await utils.sleep(30) // DEBUG + try { const wait_instance_response = await slab.waitForInstance( start_instance_response.task_id, diff --git a/src/index.js b/src/index.js index 57019a7..b899c82 100644 --- a/src/index.js +++ b/src/index.js @@ -2,11 +2,27 @@ const slab = require('./slab') const config = require('./config') const core = require('@actions/core') const { waitForRunnerRegistered } = require('./gh') +const utils = require('./utils') function setOutput(label) { core.setOutput('label', label) } +// This variable should only be defined for cleanup purpose. +let runner_name + +async function cleanup() { + if (runner_name) { + core.info('Stop instance after cancellation') + await slab.stopInstanceRequest(runner_name) + } +} + +process.on('SIGINT', async function () { + await cleanup() + process.exit() +}) + async function start() { const provider = config.input.backend @@ -15,6 +31,7 @@ async function start() { for (let i = 1; i <= 3; i++) { try { start_instance_response = await slab.startInstanceRequest() + runner_name = start_instance_response.runner_name break } catch (error) { core.info('Retrying request now...') @@ -33,6 +50,9 @@ async function start() { )}` ) + core.info('[DEBUG] About to wait 30 seconds for cancelation') // DEBUG + await utils.sleep(30) // DEBUG + try { const wait_instance_response = await slab.waitForInstance( start_instance_response.task_id, diff --git a/src/slab.js b/src/slab.js index e07586b..3f580fe 100644 --- a/src/slab.js +++ b/src/slab.js @@ -127,7 +127,7 @@ async function waitForInstance(taskId, taskName) { const task_status = body[taskName].status.toLowerCase() if (task_status === 'done') { - await removeTask(taskId) + // await removeTask(taskId) return body } else if (task_status === 'failed') { core.error(`Instance task failed (details: ${body[taskName].details})`)