Skip to content

Preview environment garbage collection #4193

Preview environment garbage collection

Preview environment garbage collection #4193

name: "Preview environment garbage collection"
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
on:
workflow_dispatch:
schedule:
- cron: "0 */4 * * *"
jobs:
create-runner:
uses: gitpod-io/gce-github-runner/.github/workflows/create-vm.yml@main
secrets:
runner_token: ${{ secrets.SELF_HOSTED_GITHUB_RUNNER_TOKEN }}
gcp_credentials: ${{ secrets.SELF_HOSTED_GITHUB_RUNNER_GCP_CREDENTIALS }}
stale:
name: "Find stale preview environments"
runs-on: ${{ needs.create-runner.outputs.label }}
needs: [create-runner]
container:
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:main-gha.30393
outputs:
names: ${{ steps.set-matrix.outputs.names }}
count: ${{ steps.set-matrix.outputs.count }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Environment
uses: ./.github/actions/setup-environment
with:
identity_provider: ${{ secrets.DEV_PREVIEW_PROVIDER }}
service_account: ${{ secrets.DEV_PREVIEW_SA }}
leeway_segment_key: ${{ secrets.LEEWAY_SEGMENT_KEY }}
- name: Compute matrix
id: set-matrix
shell: bash
run: |
set -euo pipefail
leeway run dev/preview/previewctl:install
previewctl list stale | jq --null-input --raw-input --compact-output '[inputs | select(length>0)]' > /tmp/stale-json
echo "names=$(cat /tmp/stale-json)" >> $GITHUB_OUTPUT
echo "count=$(jq '. | length' /tmp/stale-json)" >> $GITHUB_OUTPUT
delete:
name: "Delete preview environment"
needs: [stale, create-runner]
runs-on: ${{ needs.create-runner.outputs.label }}
if: ${{ needs.stale.outputs.count > 0 }}
strategy:
fail-fast: false
matrix:
name: ${{ fromJSON(needs.stale.outputs.names) }}
steps:
- uses: actions/checkout@v4
- name: Setup Environment
uses: ./.github/actions/setup-environment
with:
identity_provider: ${{ secrets.DEV_PREVIEW_PROVIDER }}
service_account: ${{ secrets.DEV_PREVIEW_SA }}
leeway_segment_key: ${{ secrets.LEEWAY_SEGMENT_KEY }}
- name: Delete preview environment ${{ matrix.name }}
uses: ./.github/actions/delete-preview
with:
name: ${{ matrix.name }}
delete-runner:
if: always()
needs:
- create-runner
- stale
- delete
uses: gitpod-io/gce-github-runner/.github/workflows/delete-vm.yml@main
secrets:
gcp_credentials: ${{ secrets.SELF_HOSTED_GITHUB_RUNNER_GCP_CREDENTIALS }}
with:
runner-label: ${{ needs.create-runner.outputs.label }}
machine-zone: ${{ needs.create-runner.outputs.machine-zone }}