diff --git a/.github/workflows/registered_runner.yml b/.github/workflows/registered_runner.yml new file mode 100644 index 0000000..16810ae --- /dev/null +++ b/.github/workflows/registered_runner.yml @@ -0,0 +1,19 @@ +# This simple workflow is used to test if a runner is registered on GitHub platform. +name: Test registered runner + +on: + workflow_call: + inputs: + runner-name: + required: true + type: string + +jobs: + test-runner: + name: Test Runner + runs-on: ${{ inputs.runner-name }} + timeout-minutes: 5 # Job should be picked very quickly + steps: + - name: Checkout + id: checkout + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 diff --git a/.github/workflows/removed_runner.yml b/.github/workflows/removed_runner.yml new file mode 100644 index 0000000..b330983 --- /dev/null +++ b/.github/workflows/removed_runner.yml @@ -0,0 +1,22 @@ +# This simple workflow is used to test if a runner is removed from GitHub platform. +name: Test registered runner + +on: + workflow_call: + inputs: + runner-name: + required: true + type: string + exist-ok: + type: boolean + default: false + +jobs: + test-removed-runner: + name: Test Removed Runner + runs-on: ubuntu-latest + steps: + - name: Check removal + id: checkout + run: | + echo "1" diff --git a/.github/workflows/test_javascript.yml b/.github/workflows/test_javascript.yml new file mode 100644 index 0000000..a041458 --- /dev/null +++ b/.github/workflows/test_javascript.yml @@ -0,0 +1,44 @@ +name: Test Javascript + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + +permissions: + contents: read + +jobs: + test-javascript: + name: JavaScript Tests + runs-on: ubuntu-latest + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 + + - name: Setup Node.js + id: setup-node + uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af + with: + node-version-file: .node-version + cache: npm + + - name: Install Dependencies + id: npm-ci + run: npm ci + + - name: Check Format + id: npm-format-check + run: npm run format:check + + - name: Lint + id: npm-lint + run: npm run lint + + - name: Test + id: npm-ci-test + run: npm run ci-test diff --git a/.github/workflows/test_spawn_terminate.yml b/.github/workflows/test_spawn_terminate.yml new file mode 100644 index 0000000..edbbf7c --- /dev/null +++ b/.github/workflows/test_spawn_terminate.yml @@ -0,0 +1,86 @@ +# Test action to spawn/terminate backend instance +name: Test Spawn-Terminate + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + +permissions: + contents: read + +jobs: + action-start: + name: GitHub Actions Test (spawn) + runs-on: ubuntu-latest + strategy: + matrix: + provider: [ aws, hyperstack ] + fail-fast: false + outputs: + runner-aws: ${{ steps.gen-output.outputs.runner_aws }} + runner-hyperstack: ${{ steps.gen-output.outputs.runner_hyperstack }} + steps: + - name: Checkout + id: checkout + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 + + - name: Test start instance + id: test-start + uses: ./ + with: + mode: start + github-token: ${{ secrets.SLAB_ACTION_TOKEN }} + slab-url: ${{ secrets.SLAB_BASE_URL_PRE_PROD }} + job-secret: ${{ secrets.JOB_SECRET }} + backend: ${{ matrix.provider }} + profile: ci-test + + - name: Generate output + id: gen-output + run: | + echo "runner_${{ matrix.provider }}=${{ steps.test-start.outputs.label }}" >> "$GITHUB_OUTPUT" + + test-runner-alive: + name: Test runner is alive + runs-on: ubuntu-latest + needs: [ action-start ] + strategy: + matrix: + runner: [ fromJSON(needs.action-start.outputs) ] + fail-fast: false + steps: + - name: Checkout + id: checkout + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 + + - name: Run job self-hosted runner + uses: ./.github/workflows/registered_runner.yml + with: + runner-name: ${{ matrix.runner }} + + action-stop: + name: GitHub Actions Test (terminate) + runs-on: ubuntu-latest + needs: [ action-start, test-runner-alive ] + strategy: + matrix: + runner: [ fromJSON(needs.action-start.outputs) ] + fail-fast: false + steps: + - name: Checkout + id: checkout + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 + + - name: Test stop instance + id: test-stop + if: ${{ always() }} + uses: ./ + with: + mode: stop + github-token: ${{ secrets.SLAB_ACTION_TOKEN }} + slab-url: ${{ secrets.SLAB_BASE_URL_PRE_PROD }} + job-secret: ${{ secrets.JOB_SECRET }} + label: ${{ matrix.runner }} diff --git a/.github/workflows/ci.yml b/.github/workflows/test_start_stop.yml similarity index 55% rename from .github/workflows/ci.yml rename to .github/workflows/test_start_stop.yml index d7a8789..b1f05d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/test_start_stop.yml @@ -1,4 +1,5 @@ -name: Continuous Integration +# Test action to start/stop already provisioned backend instance. +name: Test Start-Stop on: workflow_dispatch: @@ -11,60 +12,47 @@ permissions: contents: read jobs: - test-javascript: - name: JavaScript Tests + action-start: + name: GitHub Actions Test (start) runs-on: ubuntu-latest - steps: - name: Checkout id: checkout uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 - - name: Setup Node.js - id: setup-node - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af + - name: Test start instance + id: test-start + uses: ./ with: - node-version-file: .node-version - cache: npm - - - name: Install Dependencies - id: npm-ci - run: npm ci - - - name: Check Format - id: npm-format-check - run: npm run format:check - - - name: Lint - id: npm-lint - run: npm run lint - - - name: Test - id: npm-ci-test - run: npm run ci-test + mode: start + github-token: ${{ secrets.SLAB_ACTION_TOKEN }} + slab-url: ${{ secrets.SLAB_BASE_URL_PRE_PROD }} + job-secret: ${{ secrets.JOB_SECRET }} + backend: aws + profile: ci-test-start-stop - test-action: - name: GitHub Actions Test + test-runner-alive: + name: Test runner is alive runs-on: ubuntu-latest - strategy: - matrix: - provider: [ aws, hyperstack ] - fail-fast: false + needs: [ action-start ] steps: - name: Checkout id: checkout uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 - - name: Test start instance - id: test-start - uses: ./ + - name: Test runner is alive + uses: ./.github/workflows/registered_runner.yml with: - mode: start - github-token: ${{ secrets.SLAB_ACTION_TOKEN }} - slab-url: ${{ secrets.SLAB_BASE_URL_PRE_PROD }} - job-secret: ${{ secrets.JOB_SECRET }} - backend: ${{ matrix.provider }} - profile: ci-test + runner-name: ci-persistent-runner + + action-stop: + name: GitHub Actions Test (stop) + runs-on: ubuntu-latest + needs: [ action-start, test-runner-alive ] + steps: + - name: Checkout + id: checkout + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 - name: Test stop instance id: test-stop @@ -75,4 +63,4 @@ jobs: github-token: ${{ secrets.SLAB_ACTION_TOKEN }} slab-url: ${{ secrets.SLAB_BASE_URL_PRE_PROD }} job-secret: ${{ secrets.JOB_SECRET }} - label: ${{ steps.test-start.outputs.label }} + label: ci-persistent-runner diff --git a/ci/slab.toml b/ci/slab.toml index 513defe..5941f70 100644 --- a/ci/slab.toml +++ b/ci/slab.toml @@ -6,6 +6,14 @@ image_id = "ami-01d21b7be69801c2f" # Ubuntu 22.04 instance_type = "t3.2xlarge" user = "ubuntu" +# This instance is a persistent one with a runner already registered +[backend.aws.ci-test-start-stop] +region = "eu-west-3" +image_id = "ami-01d21b7be69801c2f" # Ubuntu 22.04 +instance_type = "t3.2xlarge" +instance_id = "i-042a592f53f5ab592" +runner_name = "ci-persistent-runner" + [backend.hyperstack.ci-test] environment_name = "canada" image_name = "Ubuntu Server 22.04 LTS R535 CUDA 12.2" diff --git a/dist/index.js b/dist/index.js index ea7be2e..b535055 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49653,7 +49653,7 @@ async function getRunner(label) { repo: config.githubContext.repo } ) - const foundRunners = _.filter(runners, { labels: [{ name: label }] }) + const foundRunners = _.filter(runners, { name: label }) return foundRunners.length > 0 ? foundRunners[0] : null } catch (error) { return null @@ -49671,7 +49671,7 @@ async function waitForRunnerRegistered(label) { ) await utils.sleep(quietPeriodSeconds) core.info( - `Checking every ${retryIntervalSeconds}s if the GitHub self-hosted runner is registered` + `Checking every ${retryIntervalSeconds}s if the GitHub self-hosted runner is registered (runner: ${label})` ) while (waitSeconds < timeoutSeconds) { @@ -51877,7 +51877,7 @@ async function stop() { ) await slab.waitForInstance(stop_instance_response.task_id, 'stop') - core.info('Instance sucessfully terminated') + core.info('Instance successfully terminated') } async function run() { diff --git a/src/gh.js b/src/gh.js index 0f1455e..ab50d9d 100644 --- a/src/gh.js +++ b/src/gh.js @@ -17,7 +17,7 @@ async function getRunner(label) { repo: config.githubContext.repo } ) - const foundRunners = _.filter(runners, { labels: [{ name: label }] }) + const foundRunners = _.filter(runners, { name: label }) return foundRunners.length > 0 ? foundRunners[0] : null } catch (error) { return null @@ -35,7 +35,7 @@ async function waitForRunnerRegistered(label) { ) await utils.sleep(quietPeriodSeconds) core.info( - `Checking every ${retryIntervalSeconds}s if the GitHub self-hosted runner is registered` + `Checking every ${retryIntervalSeconds}s if the GitHub self-hosted runner is registered (runner: ${label})` ) while (waitSeconds < timeoutSeconds) { diff --git a/src/index.js b/src/index.js index 145c921..c3ec1d9 100644 --- a/src/index.js +++ b/src/index.js @@ -29,7 +29,7 @@ async function stop() { ) await slab.waitForInstance(stop_instance_response.task_id, 'stop') - core.info('Instance sucessfully terminated') + core.info('Instance successfully terminated') } async function run() {