Files
devops-skills/.gitea/workflows/preview-slot-reclaim.yml

84 lines
2.4 KiB
YAML

name: preview-slot-reclaim
on:
schedule:
- cron: "15 * * * *"
workflow_dispatch:
inputs:
repo:
description: "owner/repo (optional)"
required: false
type: string
branch:
description: "Branch to release (optional)"
required: false
type: string
issue:
description: "Issue number to release (optional)"
required: false
type: string
jobs:
reclaim:
runs-on: ubuntu-latest
env:
PREVIEW_SLOTS: ${{ vars.PREVIEW_SLOTS }}
PREVIEW_STATE_FILE: .tmp/preview-slots.json
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Release target or prune expired
shell: bash
run: |
SLOTS="${PREVIEW_SLOTS:-preview-a,preview-b}"
REPO_INPUT="${{ inputs.repo }}"
BRANCH_INPUT="${{ inputs.branch }}"
ISSUE_INPUT="${{ inputs.issue }}"
mkdir -p .tmp
if [ -n "$REPO_INPUT" ] || [ -n "$BRANCH_INPUT" ] || [ -n "$ISSUE_INPUT" ]; then
ISSUE_FLAG=""
if [ -n "$ISSUE_INPUT" ]; then
ISSUE_FLAG="--issue $ISSUE_INPUT"
fi
python skills/gitea-issue-devops-agent/scripts/preview_slot_allocator.py \
--state-file "$PREVIEW_STATE_FILE" \
--slots "$SLOTS" \
--repo "$REPO_INPUT" \
--branch "$BRANCH_INPUT" \
$ISSUE_FLAG \
--release > .tmp/slot-reclaim.json
else
python skills/gitea-issue-devops-agent/scripts/preview_slot_allocator.py \
--state-file "$PREVIEW_STATE_FILE" \
--slots "$SLOTS" \
--list > .tmp/slot-reclaim.json
fi
cat .tmp/slot-reclaim.json
- name: Persist state
shell: bash
run: |
if [ ! -f "$PREVIEW_STATE_FILE" ]; then
exit 0
fi
if [ -z "$(git status --porcelain -- "$PREVIEW_STATE_FILE")" ]; then
exit 0
fi
git config user.name "gitea-actions"
git config user.email "gitea-actions@local"
git add "$PREVIEW_STATE_FILE"
git commit -m "chore: reclaim preview slots [skip ci]" || true
git push || true