Skip to content

Commit

Permalink
reuse old runners if they were built
Browse files Browse the repository at this point in the history
  • Loading branch information
kp2pml30 committed Nov 26, 2024
1 parent ea85f4e commit 037b97d
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions .github/workflows/genvm-build-runners.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ on:
workflow_call:
outputs:
artifact_name:
value: ${{ jobs.build.outputs.artifact_name }}
value: ${{ jobs.gen_url.outputs.basename }}
artifact_url:
value: ${{ jobs.build.outputs.artifact_url }}
value: ${{ jobs.gen_url.outputs.gcs_url }}
defaults:
run:
shell: bash -x {0}
Expand All @@ -14,11 +14,39 @@ env:
GCS_BUCKET: "gh-af"

jobs:
build:
gen_url:
runs-on: ubuntu-latest
outputs:
artifact_name: ${{ steps.upload.outputs.basename }}
artifact_url: ${{ steps.upload.outputs.gcs_url }}
dirname: ${{ steps.upload.outputs.dirname }}
basename: ${{ steps.upload.outputs.basename }}
gcs_url: ${{ steps.upload.outputs.gcs_url }}
already_exists: ${{ steps.upload.outputs.already_exists }}
steps:
- uses: actions/checkout@v4
with:
lfs: true
- name: Generate upload url
id: gen_url
run: |
SHA="$(git log -1 --format=%H -- runners/)"
DIR_NAME="genvm_runners_${SHA}
echo "dirname=$DIR_NAME" >> $GITHUB_OUTPUT
BASE_NAME="runners.zip"
echo "basename=$BASE_NAME" >> $GITHUB_OUTPUT
GCS_URL="https://storage.googleapis.com/$GCS_BUCKET/$DIR_NAME/$BASE_NAME"
echo "gcs_url=$GCS_URL" >> $GITHUB_OUTPUT
if curl -o/dev/null -sfL -r 0-0 "$GCS_URL"
then
echo "already_exists=true" >> $GITHUB_OUTPUT
else
echo "already_exists=false" >> $GITHUB_OUTPUT
fi
build:
runs-on: ubuntu-latest
needs: [gen_url]
if: |
needs.gen_url.outputs.already_exists == 'false'
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -64,18 +92,9 @@ jobs:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Generate upload url
id: upload
run: |
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
DIR_NAME="genvm_runners_${GITHUB_SHA}_${TIMESTAMP}"
echo "dirname=$DIR_NAME" >> $GITHUB_OUTPUT
BASE_NAME="runners.zip"
echo "basename=$BASE_NAME" >> $GITHUB_OUTPUT
echo "gcs_url=https://storage.googleapis.com/$GCS_BUCKET/$DIR_NAME/$BASE_NAME" >> $GITHUB_OUTPUT
- name: Upload to GCS
uses: google-github-actions/upload-cloud-storage@v2
with:
path: build/${{ steps.upload.outputs.basename }}
destination: ${{ env.GCS_BUCKET }}/${{ steps.upload.outputs.dirname }}
path: build/${{ needs.gen_url.outputs.basename }}
destination: ${{ env.GCS_BUCKET }}/${{ needs.gen_url.outputs.dirname }}
parent: false

0 comments on commit 037b97d

Please sign in to comment.