Pull in changes from 'upstream' #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy PR branches | |
on: | |
pull_request: | |
workflow_dispatch: | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TARGET_REPO: "mkdocs-demo-deploy" | |
TARGET_OWNER: "CallumWalley" | |
WORKFLOW_ID: "deploy.yml" | |
DEPLOY_URL: "https://callumwalley.github.io/mkdocs-demo-deploy" | |
HEAD: ${{ github.event.pull_request.head.ref }} | |
permissions: write-all | |
jobs: | |
demo-deploy: | |
continue-on-error: true | |
name: Trigger test deployments | |
runs-on: ubuntu-latest | |
steps: | |
- name: Trigger Workflow in Another Repository | |
run: | | |
set -x | |
set -o xtrace | |
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}/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/[email protected] | |
# 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 | |
run: | | |
# Just give a minute or so to deploy | |
sleep 60 | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Post messages open requests | |
run: | | |
msg="Test deployment available at <a href=\"${DEPLOY_URL}/${GITHUB_REPOSITORY}/${HEAD}\">${DEPLOY_URL}/${GITHUB_REPOSITORY}/${HEAD}</a>" | |
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}<br><br>Seems the following pages differ;<br><ul>" | |
for f in ${changed_pages};do | |
# maxlines=((maxlines+1)) | |
#if [ ${maxlines} -lt 1 ]; then | |
g=${f#*/}; h=${g%.*} | |
msg="${msg}<li><a href=\"${DEPLOY_URL}/${GITHUB_REPOSITORY}/${HEAD}/${h}\" target=_blank>${h##*/}</a></li>" | |
#fi | |
done | |
# if [ ${maxlines} -gt 0 ];then | |
# msg="${msg}<li> ... and ${maxlines} more.</li>" | |
# fi | |
msg="${msg}</ul>" | |
fi | |
msg="${msg}<br><br><em><a href="${DEPLOY_URL}">See all deployed demo sites</a></em>" | |
(gh pr comment ${HEAD} --edit-last --body "${msg}") || (gh pr comment ${HEAD} --body "${msg}") | |
echo "::info title=Deploy successful::${DEPLOY_URL}/${GITHUB_REPOSITORY}/${HEAD}" |