Files
warp/.github/workflows/delete_release.yml
2026-04-28 08:43:33 -05:00

112 lines
4.7 KiB
YAML

# A workflow to delete (soft-delete) a release branch by renaming it.
#
# The branch will be renamed from its original name to deleted/{original_name}.
# For example, stable_release/v0.2025.01.01.00.00 becomes
# deleted/stable_release/v0.2025.01.01.00.00.
#
# This workflow will fail if:
# - The branch doesn't start with a release channel prefix
# (i.e.: stable_release/, preview_release/, or dev_release/)
# - The release has an entry in channel_versions.json (i.e., it's deployed)
name: Delete Release
on:
workflow_dispatch:
inputs:
branch:
description: 'The release branch to delete (e.g., stable_release/v0.2025.01.01.00.00.stable)'
required: true
type: string
confirmation:
description: 'Type DELETE to confirm'
required: true
type: string
jobs:
delete_release:
name: Delete Release Branch
runs-on: ubuntu-latest
steps:
- name: Verify confirmation
run: |
if [[ "${{ inputs.confirmation }}" != "DELETE" ]]; then
echo "::error::You must type DELETE to confirm branch deletion. \
If you're unsure about deleting, ask a TL in #oncall-client before running this workflow."
exit 1
fi
shell: bash
- name: Validate release branch
id: validate
run: |
BRANCH_NAME="${{ inputs.branch }}"
# Validate branch is a release branch and extract the channel
if [[ ! "$BRANCH_NAME" =~ ^(stable|preview|dev)_release/ ]]; then
echo "::error::Branch '$BRANCH_NAME' is not a release branch." && exit 1
fi
CHANNEL="${BASH_REMATCH[1]}"
# Extract the version base from the branch name
# e.g., "stable_release/v0.2025.01.26.12.30.stable" -> "v0.2025.01.26.12.30.stable"
VERSION_BASE="$(echo $BRANCH_NAME | sed -r 's|^\w+_release/(.*)$|\1|')"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
echo "new_branch_name=deleted/$BRANCH_NAME" >> $GITHUB_OUTPUT
echo "channel=$CHANNEL" >> $GITHUB_OUTPUT
echo "version_base=$VERSION_BASE" >> $GITHUB_OUTPUT
shell: bash
- name: Check if release has changelog in channel_versions.json
id: check_deployed
env:
CHANNEL: ${{ steps.validate.outputs.channel }}
VERSION_BASE: ${{ steps.validate.outputs.version_base }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Fetch channel_versions.json from the channel-versions repository
CHANNEL_VERSIONS=$(gh api repos/warpdotdev/channel-versions/contents/channel_versions.json --jq '.content' | base64 -d)
# Fail fast if the channel section is missing from channel_versions.json
CHANNEL_EXISTS=$(echo "$CHANNEL_VERSIONS" | jq -r --arg channel "$CHANNEL" 'has("changelogs") and (.changelogs | has($channel))')
if [[ "$CHANNEL_EXISTS" != "true" ]]; then
echo "::error::channel_versions.json is missing the 'changelogs.$CHANNEL' section. Cannot safely determine if release is deployed."
exit 1
fi
# Check if any key in the changelogs section for this channel starts with the version base
# Keys are like "v0.2025.01.26.12.30.stable_01" and version_base is "v0.2025.01.26.12.30.stable"
MATCHING_ENTRIES=$(echo "$CHANNEL_VERSIONS" | jq -r --arg channel "$CHANNEL" --arg version "$VERSION_BASE" \
'.changelogs[$channel] | keys[] | select(startswith($version))')
if [[ -n "$MATCHING_ENTRIES" ]]; then
echo "::error::Cannot delete release branch: version '$VERSION_BASE' has changelog entries in channel_versions.json:"
echo "$MATCHING_ENTRIES"
exit 1
fi
echo "::notice::Release has no changelog in channel_versions.json, safe to delete."
shell: bash
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ inputs.branch }}
fetch-depth: 0
- name: Rename branch to deleted/
env:
BRANCH_NAME: ${{ steps.validate.outputs.branch_name }}
NEW_BRANCH_NAME: ${{ steps.validate.outputs.new_branch_name }}
run: |
echo "Renaming branch '$BRANCH_NAME' to '$NEW_BRANCH_NAME'"
# Push the current HEAD to the new branch name
git push origin "HEAD:refs/heads/$NEW_BRANCH_NAME"
# Delete the original branch
git push origin --delete "$BRANCH_NAME"
echo "::notice::Successfully renamed branch '$BRANCH_NAME' to '$NEW_BRANCH_NAME'"
shell: bash