This repository was archived by the owner on Jan 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
137 lines (116 loc) · 5.29 KB
/
Copy pathplayground-requests.yml
File metadata and controls
137 lines (116 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Playground for Requests
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: write
pull-requests: write
jobs:
build-playground:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'true'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.10.0
run_install: |
- recursive: true
cwd: .
- name: Setting up GITHUB_ENV for later steps
run: |
TARGET_DIR="pr/${{ github.head_ref}}/${GITHUB_SHA}"
TARGET_HOST=${GITHUB_REPOSITORY%%/*}/${GITHUB_REPOSITORY##*/}
echo "TARGET_DIR=$TARGET_DIR" >> $GITHUB_ENV
echo "TARGET_HOST=$TARGET_HOST" >> $GITHUB_ENV
- name: Set up Git credentials and ensure gh-pages branch exists
run: |
# Configure the bot's name and email and
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Ensure that a gh-pages branch exists and push it to the remote
# HACK: since refs are not properly updated, we have to fetch the refs first
# and then check if the gh-pages branch exists
echo "Updating refs"
git fetch > /dev/null 2>&1
ref=$(git show-ref | grep "gh-pages") || true
if [ -z "$ref" ]; then
echo "Creating gh-pages branch"
BASE_BRANCH=$(git branch --show-current)
git checkout --orphan gh-pages
git reset --hard
git commit --allow-empty -m "Initial commit"
git push origin gh-pages
git checkout $BASE_BRANCH
git branch -D gh-pages
fi
- name: Clone the gh-pages branch
run: |
# this will create a gh-pages directory with the content of the gh-pages branch. this makes it easier to work
# with the gh-pages branch instead of having to switch branches all the time
git clone --single-branch --branch gh-pages https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} gh-pages
- name: Preparing Folders for Deployment
run: |
# this will create the target directory if it does not exist
# and ensure that it is empty
printf "%s\n" "Creating gh-pages/$TARGET_DIR"
rm -rf gh-pages/$TARGET_DIR
mkdir -p "gh-pages/$TARGET_DIR"
- name: Prepare Branch for Deployment
run: |
# this whould be to much work to do in a single step.
# please refer th scripts/playground.sh for more details
# this script will build and zip all Plugins for deployment
# it will also create a playground for the trunk
./scripts/playground.sh $TARGET_HOST $TARGET_DIR
- name: Copy dist folder to gh-pages/trunk
run: |
# Move all Files from dist to gh-pages/trunk and commit the changes
# HACK: The mv command does not work as expected, so we have to use the dirname command
echo "copying dist/$TARGET_DIR to gh-pages/$TARGET_DIR"
mv dist/$TARGET_DIR $(dirname gh-pages/$TARGET_DIR)
- name: Commit and push changes
run: |
# Adding changes to git
cd gh-pages
git add .
git commit -m "Deploying state of PR ${{ github.pr_number}} from ${{ github.head_ref}}"
git push origin gh-pages --force
- name: write a State file for transfering to Node
run : |
# HACK: this is very hacky, but it works for now
# GITHUB_ENV does not transfer to Node, so we write a
# separate file that we can read in Node.
# This is a workaround until we have a better solution
# NOTE: this is only necessary because we want to comment on the PR
# with a link to the playground, which is only available after the
# deployment
echo "TARGET_DIR=$TARGET_DIR" >> ./state.txt
echo "GITHUB_SHA=$GITHUB_SHA" >> ./state.txt
echo "PR_NUMBER=${{ github.pr_number}}" >> ./state.txt
echo "HEAD_REF=${{ github.head_ref}}" >> ./state.txt
echo "GITHUB_REPOSITORY=${GITHUB_REPOSITORY}" >> ./state.txt
- name: comment on PR with playground link
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const state = fs.readFileSync('./state.txt', 'utf8');
const [TARGET_DIR, GITHUB_SHA, PR_NUMBER, HEAD_REF, GITHUB_REPOSITORY] = state.split('\n').map(x => x.split('=')[1]);
const badge = `[](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/gh-pages/${TARGET_DIR}/playground.json)`;
console.log(`TARGET_DIR=${TARGET_DIR}`);
console.log(`GITHUB_SHA=${GITHUB_SHA}`);
github.rest.issues.createComment({
owner: context.repo.owner,
issue_number: context.issue.number,
repo: context.repo.repo,
body: `Playground for PR ${PR_NUMBER} from ${HEAD_REF} is ready! \n ${badge}`
});