Skip to content

Commit 101d787

Browse files
iQQBotona-agent
andcommitted
use latest image automatically
Co-authored-by: Ona <no-reply@ona.com>
1 parent 4facdbb commit 101d787

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

.github/workflows/create-vm.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,24 @@ jobs:
4646
shell: bash
4747
run: |
4848
gcloud auth activate-service-account --key-file ${{ steps.auth.outputs.credentials_file_path }}
49+
- name: Get latest runner image
50+
id: get-image
51+
if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
52+
shell: bash
53+
run: |
54+
LATEST_IMAGE=$(gcloud compute images list \
55+
--project=public-github-runners \
56+
--filter="name~'gh-runner-.*'" \
57+
--sort-by="~creationTimestamp" \
58+
--format="value(name)" \
59+
--limit=1)
60+
echo "image=${LATEST_IMAGE}" >> $GITHUB_OUTPUT
61+
echo "Using latest image: ${LATEST_IMAGE}"
4962
- id: create-runner
5063
uses: gitpod-io/gce-github-runner@main
5164
with:
5265
runner_token: ${{ secrets.runner_token }}
5366
task: ${{ inputs.task }}
5467
label: ${{ inputs.label }}
68+
image: ${{ steps.get-image.outputs.image }}
5569
gcp_credentials: ${{ secrets.gcp_credentials }}

action.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ inputs:
3333
required: false
3434
default: public-github-runners
3535
image:
36-
description: Specifies the name of the image that the disk will be initialized with.
36+
description: Specifies the name of the image that the disk will be initialized with. If not provided, will use the latest gh-runner-* image.
3737
required: false
38-
default: gh-runner-202508041322
3938
image_family:
4039
description: The image family for the operating system that the boot disk will be initialized with.
4140
required: false
@@ -94,12 +93,30 @@ runs:
9493
shell: bash
9594
run: |
9695
gcloud auth activate-service-account --key-file ${{ steps.auth.outputs.credentials_file_path }}
96+
- name: Get latest runner image
97+
id: get-image
98+
if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && inputs.image == ''
99+
shell: bash
100+
run: |
101+
LATEST_IMAGE=$(gcloud compute images list \
102+
--project=${{ inputs.image_project }} \
103+
--filter="name~'gh-runner-.*'" \
104+
--sort-by="~creationTimestamp" \
105+
--format="value(name)" \
106+
--limit=1)
107+
echo "image=${LATEST_IMAGE}" >> $GITHUB_OUTPUT
108+
echo "Using latest image: ${LATEST_IMAGE}"
97109
- name: Create GCE VM
98110
id: gce-github-runner-script
99111
if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
100112
shell: bash
101113
run: |
102114
set -x
115+
116+
IMAGE_TO_USE="${{ inputs.image }}"
117+
if [ -z "${IMAGE_TO_USE}" ]; then
118+
IMAGE_TO_USE="${{ steps.get-image.outputs.image }}"
119+
fi
103120
104121
${{ github.action_path }}/action.sh \
105122
--command=start \
@@ -111,7 +128,7 @@ runs:
111128
--scopes=${{ inputs.scopes }} \
112129
--shutdown_timeout=${{ inputs.shutdown_timeout }} \
113130
--image_project=${{ inputs.image_project }} \
114-
--image=${{ inputs.image }} \
131+
--image="${IMAGE_TO_USE}" \
115132
--image_family=${{ inputs.image_family }} \
116133
--label=${{ inputs.label }} \
117134
--boot_disk_type=pd-ssd \

0 commit comments

Comments
 (0)