From 89c2c5c53a0f0841f091c625c0837d4fb91d366d Mon Sep 17 00:00:00 2001 From: Donovan Sydow Date: Fri, 17 Jan 2025 17:08:24 -0800 Subject: [PATCH] updated readme --- README.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f484b16..b8e3473 100644 --- a/README.md +++ b/README.md @@ -14,26 +14,96 @@ jobs: outputs: label: ${{ steps.create-runner.outputs.label }} steps: - - id: create-runner - uses: related-sciences/gce-github-runner@v0.11 + - name: Create Runner + id: create-runner + uses: iunu/gce-github-runner@iunu with: - token: ${{ secrets.GH_SA_TOKEN }} + token: ${{ secrets.GH_PAT_TOKEN }} project_id: ${{ secrets.GCP_PROJECT_ID }} service_account_key: ${{ secrets.GCP_SA_KEY }} + machine_zone: 'us-central1-c' + machine_type: 'c2-standard-4' + runner_service_account: ${{ inputs.runner_service_account }} + runner_ver: latest + network: 'runner-net' + subnet: 'runner-subnet' image_project: ubuntu-os-cloud image_family: ubuntu-2404-lts-amd64 + preemptible: true + no_external_address: true + actions_preinstalled: false + shutdown_timeout: 60 #max runtime test: needs: create-runner runs-on: ${{ needs.create-runner.outputs.label }} steps: - run: echo "This runs on the GCE VM" +# Runners don't reliably cleanup due to GHA bugs, so we delete when done with a job +# **Don't use method this if you have more than one job** + - name: Delete Runner + run: echo "Deleting Runner..." + - uses: iunu/gce-github-runner@iunu + with: + command: stop + if: ${{ true || always() || failure() || success() || cancelled() || needs.*.result == 'skipped' }} ``` * `create-runner` creates the GCE VM and registers the runner with unique label * `test` uses the runner * the runner VM will be automatically shut down after the workflow via [self-hosted runner hook](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/running-scripts-before-or-after-a-job) +Due to bugs with runners not or overzealously shutting down if you have multiple jobs you can reliably shutdown the runners with a `workflow_run` file that runs after your workflow. Make sure the `workflows:` value(s) match the `name:` of the workflow you created: + +```yaml +name: Runner Cleanup + +on: + workflow_run: + workflows: [Workflow Name] + types: + - completed + +jobs: + runner-cleanup: + runs-on: self-hosted + steps: + - uses: iunu/gce-github-runner@iunu + with: + command: stop + if: always() +``` +Similarly you could call another workflow and pass the runner label to it, but due to issues with skipping jobs you may not be able to reliably get this to run: + +```yaml +name: Runner Cleanup Reusable Workflow + +on: + workflow_call: + inputs: + runner: + required: true + type: string + +jobs: + runner-cleanup: + runs-on: ${{ inputs.runner }} + steps: + - uses: iunu/gce-github-runner@iunu + with: + command: stop + if: always() +``` +This would be called something like this where filename is the name of the yaml above: + +```yaml +jobs: + delete-my-runner: + uses: ./.github/workflows/{filename} + with: + runner: ${{ steps.create-runner.outputs.label }} +``` + ## Inputs See inputs and descriptions [here](./action.yml).