Sync Release (Create & Update) to Frontend Repo workflow (MarSeventh/CloudFlare-ImgBed)
The Sync Release (Create & Update) to Frontend Repo workflow from MarSeventh/CloudFlare-ImgBed, explained and optimized by Latchkey.
CI health: A - excellent
Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Sync Release (Create & Update) to Frontend Repo workflow from the MarSeventh/CloudFlare-ImgBed repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Sync Release (Create & Update) to Frontend Repo
on:
release:
# 创建、发布、更新
types: [created, published, edited]
jobs:
sync-release:
if: github.repository == 'MarSeventh/CloudFlare-ImgBed'
runs-on: ubuntu-latest
steps:
- name: Sync or Update Release
env:
GH_TOKEN: ${{ secrets.RELEASE_SYNC_PAT }}
TARGET_REPO: "MarSeventh/Sanyue-ImgHub"
TAG_NAME: ${{ github.event.release.tag_name }}
RELEASE_TITLE: ${{ github.event.release.name }}
RELEASE_BODY: ${{ github.event.release.body }}
IS_DRAFT: ${{ github.event.release.draft }}
IS_PRERELEASE: ${{ github.event.release.prerelease }}
run: |
# 格式化参数
ARGS=""
if [ "$IS_DRAFT" = "true" ]; then ARGS="$ARGS --draft"; else ARGS="$ARGS --draft=false"; fi
if [ "$IS_PRERELEASE" = "true" ]; then ARGS="$ARGS --prerelease"; else ARGS="$ARGS --prerelease=false"; fi
echo "正在检查目标仓库 $TARGET_REPO 中是否存在 Tag: $TAG_NAME..."
# 检查目标仓库是否已有该 Release
if gh release view "$TAG_NAME" --repo "$TARGET_REPO" > /dev/null 2>&1; then
echo "检测到现有 Release,正在执行更新操作..."
gh release edit "$TAG_NAME" \
--repo "$TARGET_REPO" \
--title "$RELEASE_TITLE" \
--notes "$RELEASE_BODY" \
$ARGS
else
echo "未发现现有 Release,正在创建新 Release..."
gh release create "$TAG_NAME" \
--repo "$TARGET_REPO" \
--title "$RELEASE_TITLE" \
--notes "$RELEASE_BODY" \
$ARGS
fi
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Sync Release (Create & Update) to Frontend Repo on: release: # 创建、发布、更新 types: [created, published, edited] jobs: sync-release: timeout-minutes: 30 if: github.repository == 'MarSeventh/CloudFlare-ImgBed' runs-on: latchkey-small steps: - name: Sync or Update Release env: GH_TOKEN: ${{ secrets.RELEASE_SYNC_PAT }} TARGET_REPO: "MarSeventh/Sanyue-ImgHub" TAG_NAME: ${{ github.event.release.tag_name }} RELEASE_TITLE: ${{ github.event.release.name }} RELEASE_BODY: ${{ github.event.release.body }} IS_DRAFT: ${{ github.event.release.draft }} IS_PRERELEASE: ${{ github.event.release.prerelease }} run: | # 格式化参数 ARGS="" if [ "$IS_DRAFT" = "true" ]; then ARGS="$ARGS --draft"; else ARGS="$ARGS --draft=false"; fi if [ "$IS_PRERELEASE" = "true" ]; then ARGS="$ARGS --prerelease"; else ARGS="$ARGS --prerelease=false"; fi echo "正在检查目标仓库 $TARGET_REPO 中是否存在 Tag: $TAG_NAME..." # 检查目标仓库是否已有该 Release if gh release view "$TAG_NAME" --repo "$TARGET_REPO" > /dev/null 2>&1; then echo "检测到现有 Release,正在执行更新操作..." gh release edit "$TAG_NAME" \ --repo "$TARGET_REPO" \ --title "$RELEASE_TITLE" \ --notes "$RELEASE_BODY" \ $ARGS else echo "未发现现有 Release,正在创建新 Release..." gh release create "$TAG_NAME" \ --repo "$TARGET_REPO" \ --title "$RELEASE_TITLE" \ --notes "$RELEASE_BODY" \ $ARGS fi
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.