diff --git a/.github/workflows/demo_deploy.yml b/.github/workflows/demo_deploy.yml
index 4efb5f3..5b14326 100644
--- a/.github/workflows/demo_deploy.yml
+++ b/.github/workflows/demo_deploy.yml
@@ -1,7 +1,6 @@
name: Deploy PR branches
-on:
+on:
pull_request:
- branches-ignore: "assets-update"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_REPO: "mkdocs-demo-deploy"
@@ -9,72 +8,147 @@ env:
WORKFLOW_ID: "deploy.yml"
DEPLOY_URL: "https://callumwalley.github.io/mkdocs-demo-deploy"
HEAD: ${{ github.event.pull_request.head.ref }}
-permissions: write-all
+ GH_REPO: ${{ github.repository }}
+ NO_MKDOCS_2_WARNING: "1"
+permissions:
+ contents: read
+ pull-requests: write
+concurrency:
+ group: demo-deploy-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
jobs:
demo-deploy:
- continue-on-error: true
name: Trigger test deployments
runs-on: ubuntu-24.04
steps:
- name: Trigger Workflow in Another Repository
- continue-on-error: true
+ id: trigger
run: |
set -x
- set -o xtrace
- curl -L \
+ echo "dispatch_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_OUTPUT"
+ curl -fsSL \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${TARGET_OWNER}/${TARGET_REPO}/dispatches \
-d "{\"event_type\":\"deploy\",\"client_payload\":{\"targets\":\"${GITHUB_REPOSITORY}:${HEAD}\", \"use-cache\":\"true\"}}"
-
- # This would be better if it worked
- # - name: Run 'deploy.yml' Workflow
- # uses: convictional/trigger-workflow-and-wait@v1.6.1
- # with:
- # owner: ${TARGET_OWNER}
- # repo: ${TARGET_REPO}
- # github_token: ${{ secrets.PAT }}
- # workflow_file_name: deploy.yml
- # client_payload: '{"targets":"${GITHUB_REPOSITORY}:${HEAD}", "use-cache":"true"}'
- # - name: Wait for Workflow Action
- # run: |
- # curl -L \
- # -X POST \
- # -H "Accept: application/vnd.github+json" \
- # -H "Authorization: Bearer ${{ secrets.PAT }}" \
- # -H "X-GitHub-Api-Version: 2022-11-28" \
- # https://api.github.com/repos/${TARGET_OWNER}/${TARGET_REPO}/actions/runs/deploy.yml
- - name: Wait for Workflow Action
+ - name: Post initial loading comment
+ id: comment
run: |
- # Just give a minute or so to deploy
- sleep 90
- - name: Checkout repository
- uses: actions/checkout@v4
- with:
- fetch-depth: 0
+ msg="Deployment in progress...
\
+ 
Waiting for test environment to finish building, please be patient ☺️"
+ gh pr comment "${HEAD}" --edit-last --create-if-none --body "${msg}"
+ - name: Wait for target workflow to complete
+ id: wait
+ env:
+ GH_TOKEN: ${{ secrets.PAT }}
+ TIMEOUT_SECONDS: 600
+ run: |
+ finish() {
+ echo "conclusion=$1" >> "$GITHUB_OUTPUT"
+ echo "completed_at=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_OUTPUT"
+ }
+
+ # Only consider runs created after we dispatched, so a stale
+ # already-completed run isn't mistaken for the one we just triggered.
+ echo "Looking for a run created after ${{ steps.trigger.outputs.dispatch_time }}..."
+ run_id=""
+ while [ -z "$run_id" ]; do
+ if [ "$SECONDS" -ge "$TIMEOUT_SECONDS" ]; then
+ echo "Timed out waiting for the run to appear."
+ finish "timed_out"
+ exit 0
+ fi
+ run_id=$(gh api -X GET "repos/${TARGET_OWNER}/${TARGET_REPO}/actions/workflows/${WORKFLOW_ID}/runs" \
+ -f "created=>${{ steps.trigger.outputs.dispatch_time }}" \
+ --jq '.workflow_runs[-1].id // empty')
+ [ -z "$run_id" ] && sleep 10
+ done
+ echo "Tracking run $run_id"
+
+ while true; do
+ if [ "$SECONDS" -ge "$TIMEOUT_SECONDS" ]; then
+ echo "Timed out waiting for the run to complete."
+ finish "timed_out"
+ exit 0
+ fi
+ run_json=$(gh api "repos/${TARGET_OWNER}/${TARGET_REPO}/actions/runs/${run_id}")
+ status=$(echo "$run_json" | jq -r '.status')
+ echo "Status: $status"
+ if [ "$status" = "completed" ]; then
+ finish "$(echo "$run_json" | jq -r '.conclusion')"
+ break
+ fi
+ sleep 10
+ done
+
- name: Post messages open requests
- continue-on-error: true
run: |
- msg="Test deployment available at ${DEPLOY_URL}/${GITHUB_REPOSITORY}/${HEAD}"
- changed_pages="$(git diff --name-only origin/main -- '*.md')"
- # Logic for truncating out long sections commented out.
- # maxlines=-5
- if [ -n "${changed_pages}" ]; then
- msg="${msg}
Seems the following pages differ;