Skip to content

Commit 13a6e5f

Browse files
authored
ci: use the current branch name for cf deployments (#102)
2 parents 237e0f6 + d6a4385 commit 13a6e5f

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

.github/workflows/cd.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,33 @@ jobs:
171171
- name: Build the documentation
172172
run: pnpx nx build docs
173173

174+
- name: Determine source branch
175+
id: determine_branch
176+
run: |
177+
# Get the commit hash of the tag
178+
TAG_COMMIT=$(git rev-list -n 1 ${{ github.ref_name }})
179+
echo "Tag commit: $TAG_COMMIT"
180+
181+
# Check if this commit exists in main
182+
if git merge-base --is-ancestor "$TAG_COMMIT" origin/main; then
183+
echo "Commit is in main branch"
184+
echo "target_branch=main" >> "$GITHUB_OUTPUT"
185+
else
186+
# Find which branch contains this commit
187+
BRANCH=$(git branch -r --contains "$TAG_COMMIT" | grep -v '/HEAD' | head -1 | sed 's/.*origin\///')
188+
if [ -z "$BRANCH" ]; then
189+
echo "Could not determine source branch, defaulting to main"
190+
echo "target_branch=main" >> "$GITHUB_OUTPUT"
191+
else
192+
echo "Found source branch: $BRANCH"
193+
echo "target_branch=$BRANCH" >> "$GITHUB_OUTPUT"
194+
fi
195+
fi
196+
174197
- name: Deploy Cloudflare Pages
175198
uses: cloudflare/wrangler-action@v3
176199
with:
177200
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
178201
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
179-
command: pages deploy --branch main
202+
command: pages deploy --branch ${{ steps.determine_branch.outputs.target_branch }}
180203
packageManager: pnpm

0 commit comments

Comments
 (0)