Skip to content

Commit 0939118

Browse files
fix: ensure deploy state branch exists
1 parent f075825 commit 0939118

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

.github/workflows/ci_k8_base.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,24 +212,34 @@ jobs:
212212
BRANCH: deploy-state
213213

214214
run: |
215+
# Setup Git user
215216
git config user.name "github-actions"
216217
git config user.email "actions@github.com"
217218
218-
# Fetch and create worktree
219-
git fetch origin $BRANCH:$BRANCH || true
220-
git worktree add ../deploy-worktree $BRANCH
219+
# Check if remote branch exists
220+
if git ls-remote --exit-code --heads origin "$BRANCH"; then
221+
echo "🔁 Branch $BRANCH exists on remote. Fetching..."
222+
git fetch origin "$BRANCH":"$BRANCH"
223+
else
224+
echo "🆕 Branch $BRANCH does not exist. Creating from main..."
225+
git fetch origin main
226+
git branch "$BRANCH" origin/main
227+
fi
228+
229+
# Create a worktree for the branch
230+
git worktree add ../deploy-worktree "$BRANCH"
221231
222-
# Ensure deploys dir (local)
232+
# Ensure local .deploys dir
223233
mkdir -p .deploys
224234
225-
# If exists in branch, copy it; else init
235+
# Copy or initialize deploy file
226236
if [ -f ../deploy-worktree/.deploys/$FILE ]; then
227237
cp ../deploy-worktree/.deploys/$FILE .deploys/$FILE
228238
else
229239
echo "{}" > .deploys/$FILE
230240
fi
231241
232-
# Merge or add deploy info
242+
# Update the deploy file
233243
jq --arg env "$ENV" \
234244
--arg digest "$IMAGE_DIGEST" \
235245
--arg version_tag "$VERSION_TAG" \
@@ -239,7 +249,7 @@ jobs:
239249
240250
cat .deploys/$FILE
241251
242-
# Ensure destination dir before copying
252+
# Ensure destination dir and copy updated file
243253
mkdir -p ../deploy-worktree/.deploys
244254
cp .deploys/$FILE ../deploy-worktree/.deploys/$FILE
245255

0 commit comments

Comments
 (0)