Skip to content

Commit 243d062

Browse files
committed
Cleanup
1 parent 96dc165 commit 243d062

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

action.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ EOF
172172
173173
chmod +x /etc/systemd/system/shutdown.sh
174174
175-
su -s /bin/bash -c "cd /actions-runner-1/;/actions-runner-1/config.sh --url https://github.com/${GITHUB_REPOSITORY} --token ${RUNNER_TOKEN} --name ${VM_ID}-1 --labels ${VM_ID} --unattended --disableupdate" runner
176-
su -s /bin/bash -c "cd /actions-runner-2/;/actions-runner-2/config.sh --url https://github.com/${GITHUB_REPOSITORY} --token ${RUNNER_TOKEN} --name ${VM_ID}-2 --labels ${VM_ID} --unattended --disableupdate" runner
175+
RUNNER_ID=${VM_ID}-$(date +%s)
176+
su -s /bin/bash -c "cd /actions-runner-1/;/actions-runner-1/config.sh --url https://github.com/${GITHUB_REPOSITORY} --token ${RUNNER_TOKEN} --name ${RUNNER_ID}-1 --labels ${VM_ID} --unattended --disableupdate" runner
177+
su -s /bin/bash -c "cd /actions-runner-2/;/actions-runner-2/config.sh --url https://github.com/${GITHUB_REPOSITORY} --token ${RUNNER_TOKEN} --name ${RUNNER_ID}-2 --labels ${VM_ID} --unattended --disableupdate" runner
177178
178179
touch /.github-runner-config-ready
179180

action.yml

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ inputs:
99
runner_token:
1010
description: >-
1111
GitHub auth token, needs `repo`/`public_repo` scope: https://docs.github.com/en/rest/reference/actions#self-hosted-runners.
12-
required: true
13-
project_id:
12+
required: true
13+
project_id:
1414
description: >-
1515
ID of the Google Cloud Platform project. If provided, this will configure gcloud to use this project ID.
1616
required: false
@@ -51,6 +51,9 @@ inputs:
5151
description: Additional context about the workflow
5252
default: default
5353
required: true
54+
gcp_credentials:
55+
description: GCP JSON credentials
56+
required: true
5457

5558
outputs:
5659
label:
@@ -71,21 +74,43 @@ runs:
7174
run: |
7275
echo "❌ Job actions are not allowed to run in forks" >> $GITHUB_STEP_SUMMARY
7376
exit 1
77+
- uses: actions/checkout@v3
78+
- id: auth
79+
name: Authenticate to Google Cloud
80+
uses: google-github-actions/auth@v1
81+
with:
82+
credentials_json: ${{ inputs.gcp_credentials }}
83+
- id: gcloud-auth
84+
name: gcloud auth activate-service-account
85+
shell: bash
86+
run: |
87+
gcloud auth activate-service-account --key-file ${{ steps.auth.outputs.credentials_file_path }}
7488
- id: gce-github-runner-script
7589
if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
76-
shell: bash
77-
run: >
78-
${{ github.action_path }}/action.sh
79-
--command=start
80-
--runner_token=${{ inputs.runner_token }}
81-
--project_id=${{ inputs.project_id }}
82-
--machine_zone=${{ inputs.machine_zone }}
83-
--machine_type=${{ inputs.machine_type }}
84-
--disk_size=${{ inputs.disk_size }}
85-
--scopes=${{ inputs.scopes }}
86-
--shutdown_timeout=${{ inputs.shutdown_timeout }}
87-
--image_project=${{ inputs.image_project }}
88-
--image=${{ inputs.image }}
89-
--image_family=${{ inputs.image_family }}
90-
--boot_disk_type=pd-ssd
91-
--task=${{ inputs.task }}
90+
uses: pyTooling/Actions/with-post-step@r0
91+
with:
92+
main: |
93+
${{ github.action_path }}/action.sh
94+
--command=start
95+
--runner_token=${{ inputs.runner_token }}
96+
--project_id=${{ inputs.project_id }}
97+
--machine_zone=${{ inputs.machine_zone }}
98+
--machine_type=${{ inputs.machine_type }}
99+
--disk_size=${{ inputs.disk_size }}
100+
--scopes=${{ inputs.scopes }}
101+
--shutdown_timeout=${{ inputs.shutdown_timeout }}
102+
--image_project=${{ inputs.image_project }}
103+
--image=${{ inputs.image }}
104+
--image_family=${{ inputs.image_family }}
105+
--boot_disk_type=pd-ssd
106+
--task=${{ inputs.task }}
107+
post: |
108+
echo "Removing GCE VM..."
109+
110+
gcloud auth activate-service-account --key-file ${{ steps.auth.outputs.credentials_file_path }}
111+
if [ -z "$(gcloud compute instances list | grep "${{ inputs.runner-label }}")" ]; then
112+
# vm is gone
113+
exit 0
114+
fi
115+
116+
gcloud compute instances delete ${{ inputs.runner-label }} --quiet --zone ${{ inputs.machine-zone }}

0 commit comments

Comments
 (0)