ci: chain browser-e2e to run only after deploy workflow succeeds via workflow_run
TaxBaik CI/CD / build-and-deploy (push) Successful in 57s
TaxBaik CI/CD / build-and-deploy (push) Successful in 57s
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
name: TaxBaik Browser E2E
|
name: TaxBaik Browser E2E
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
workflow_run:
|
||||||
branches:
|
workflows: ["TaxBaik CI/CD"]
|
||||||
- master
|
types:
|
||||||
|
- completed
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
browser-e2e:
|
browser-e2e:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event.workflow_run.conclusion == 'success'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
@@ -37,21 +39,24 @@ jobs:
|
|||||||
- name: Wait for deployment
|
- name: Wait for deployment
|
||||||
env:
|
env:
|
||||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||||
|
EXPECTED_VERSION: ${{ github.event.workflow_run.head_sha }}
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
EXPECTED_VERSION="$(git rev-parse --short HEAD)"
|
# Extract short commit hash (first 7 characters)
|
||||||
for i in $(seq 1 60); do
|
SHORT_VERSION=$(echo "$EXPECTED_VERSION" | cut -c1-7)
|
||||||
|
echo "Expected short version: $SHORT_VERSION"
|
||||||
|
for i in $(seq 1 30); do
|
||||||
# Suppress stderr and allow failures to handle transition/down periods cleanly
|
# Suppress stderr and allow failures to handle transition/down periods cleanly
|
||||||
VERSION_BODY="$(curl -fsS "http://${DEPLOY_HOST}/taxbaik/version.txt" 2>/dev/null || true)"
|
VERSION_BODY="$(curl -fsS "http://${DEPLOY_HOST}/taxbaik/version.txt" 2>/dev/null || true)"
|
||||||
BLOG_STATUS="$(curl -s -o /dev/null -w '%{http_code}' "http://${DEPLOY_HOST}/taxbaik/blog/accountant-mistakes-5" || true)"
|
BLOG_STATUS="$(curl -s -o /dev/null -w '%{http_code}' "http://${DEPLOY_HOST}/taxbaik/blog/accountant-mistakes-5" || true)"
|
||||||
if echo "$VERSION_BODY" | grep -q "Version: ${EXPECTED_VERSION}" && [ "$BLOG_STATUS" = "200" ]; then
|
if echo "$VERSION_BODY" | grep -q "Version: ${SHORT_VERSION}" && [ "$BLOG_STATUS" = "200" ]; then
|
||||||
echo "Deployment is ready for ${EXPECTED_VERSION}"
|
echo "Deployment is ready for ${SHORT_VERSION}"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
echo "Waiting for deployment ${EXPECTED_VERSION} (attempt $i/60); blog status=${BLOG_STATUS:-down}; version=${VERSION_BODY:-unknown}"
|
echo "Waiting for deployment ${SHORT_VERSION} (attempt $i/30); blog status=${BLOG_STATUS:-down}; version=${VERSION_BODY:-unknown}"
|
||||||
sleep 10
|
sleep 5
|
||||||
done
|
done
|
||||||
echo "Deployment did not publish expected version ${EXPECTED_VERSION} in time" >&2
|
echo "Deployment did not publish expected version ${SHORT_VERSION} in time" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
- name: Browser E2E verification
|
- name: Browser E2E verification
|
||||||
|
|||||||
Reference in New Issue
Block a user