Skip to content

Continue deploying to playground.wordpress.net (don't use manually) #67

Continue deploying to playground.wordpress.net (don't use manually)

Continue deploying to playground.wordpress.net (don't use manually) #67

name: Continue deploying to playground.wordpress.net (don't use manually)
# Sorry, the previous job just built it and uploaded it to GitHub
on:
workflow_run:
workflows: [Deploy to playground.wordpress.net]
types:
- completed
jobs:
build_and_deploy:
# Only run this workflow from the trunk branch and when it's triggered by another workflow OR dmsnell OR adamziel
if: >
github.ref == 'refs/heads/trunk' && (
github.event.workflow_run.conclusion == 'success' ||
github.actor == 'adamziel' ||
github.actor == 'dmsnell'
)
# Specify runner + deployment step
runs-on: ubuntu-latest
environment:
name: playground-wordpress-net
steps:
# Deploy the latest website artifact to playground.wordpress.net website by
# sending a CURL request to https://playground.wordpress.net/webhook.php with a header
# like X-Deployment-Token that has the same value as github secret DEPLOY_AUTH_TOKEN
- name: Deploy
shell: bash
# Sleep to give the GitHub API time to register the artifact,
# otherwise the artifact will not be available when the webhook is called
run: |
while true; do
API_HASH=$(curl 'https://api.github.com/repos/wordpress/wordpress-playground/actions/artifacts?name=playground-website&per_page=2' \
| jq -r '.artifacts[0].workflow_run.head_sha')
if [ "$API_HASH" = "$GITHUB_SHA" ]; then
break;
fi;
echo "$API_HASH was not $GITHUB_SHA, waiting 10 seconds...";
sleep 10;
done;
curl -X POST https://playground.wordpress.net/webhook.php \
-H "X-Deployment-Token: ${{ secrets.DEPLOYMENT_KEY }}" \
-H "Content-Type: application/json"