Skip to content

Commit 8279304

Browse files
committed
Merge branch 'core' into flat-file
# Conflicts: # src/php/class-active-snippets.php # src/php/class-plugin.php # src/php/class-snippet.php # src/php/load.php # src/php/snippet-ops.php
2 parents 4d84a24 + 4162494 commit 8279304

File tree

157 files changed

+9530
-8365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+9530
-8365
lines changed

.github/workflows/build.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: "(Build): Plugin"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ref:
7+
required: false
8+
type: string
9+
default: ${{ inputs.ref }}
10+
outputs:
11+
version:
12+
value: ${{ jobs.build.outputs.version }}
13+
artifact_name:
14+
value: ${{ jobs.build.outputs.artifact_name }}
15+
artifact_url:
16+
value: ${{ jobs.build.outputs.artifact_url }}
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
outputs:
21+
artifact_name: ${{ steps.build.outputs.name }}
22+
artifact_url: ${{ steps.artifacts.outputs.artifact-url }}
23+
version: ${{ steps.build.outputs.version }}
24+
steps:
25+
- uses: actions/checkout@v4
26+
with:
27+
ref: ${{ inputs.ref }}
28+
29+
- name: Set up PHP
30+
uses: codesnippetspro/setup-php@v2
31+
with:
32+
php-version: "8.3"
33+
34+
- name: Set up Node.js
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version-file: .node-version
38+
39+
- name: Install & Build
40+
id: build
41+
run: |
42+
npm install && npm run bundle
43+
44+
echo "name=$(jq -r .name package.json)" >> $GITHUB_OUTPUT
45+
echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
46+
47+
mkdir -p ./bundle/code-snippets
48+
mv ./bundle/* ./bundle/code-snippets/ 2>/dev/null || true
49+
50+
- name: Upload
51+
id: artifacts
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: ${{ steps.build.outputs.name }}
55+
path: ./bundle

.github/workflows/create-tag.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "(Tag): Create"
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- core
8+
9+
jobs:
10+
create-tag:
11+
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'tag/v')
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout main
15+
uses: actions/checkout@v4
16+
with:
17+
ref: core
18+
19+
- name: Get version from package.json
20+
id: version
21+
run: |
22+
echo "tag=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
23+
24+
- name: Create tag
25+
run: |
26+
git config user.name "code-snippets-bot"
27+
git config user.email "sre@codesnippets.pro"
28+
git tag "v${{ steps.version.outputs.tag }}"
29+
git push origin "v${{ steps.version.outputs.tag }}"

.github/workflows/playwright.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Playwright
2+
3+
on:
4+
pull_request:
5+
types: [labeled, synchronize, opened, reopened]
6+
push:
7+
branches:
8+
- 'core'
9+
paths-ignore:
10+
- '**.md'
11+
- '**.txt'
12+
- '.gitignore'
13+
- 'docs/**'
14+
workflow_dispatch:
15+
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
actions: read
20+
21+
concurrency:
22+
group: playwright-${{ github.event_name }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref }}
23+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
24+
25+
jobs:
26+
build-plugin:
27+
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
28+
name: Build plugin
29+
uses: ./.github/workflows/build.yml
30+
31+
Playwright:
32+
name: Playwright test on PHP 8.1
33+
runs-on: ubuntu-22.04
34+
needs: [build-plugin]
35+
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
36+
steps:
37+
- name: Checkout source code
38+
uses: actions/checkout@v4
39+
40+
- name: Install Node.js 20.x
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: 20.x
44+
cache: 'npm'
45+
46+
- name: Download build artifact
47+
uses: actions/download-artifact@v4
48+
with:
49+
name: ${{ needs.build-plugin.outputs.artifact_name }}
50+
path: ./build
51+
52+
- name: Copy built plugin to source directory
53+
run: |
54+
rm -rf ./src
55+
cp -r ./build/code-snippets ./src
56+
57+
- name: Install workflow dependencies (wp-env, playwright)
58+
run: npm run prepare-environment:ci
59+
60+
- name: Start WordPress environment
61+
run: |
62+
npx wp-env start
63+
64+
- name: Activate code-snippets plugin
65+
run: npx wp-env run cli wp plugin activate code-snippets
66+
67+
- name: WordPress debug information
68+
run: |
69+
npx wp-env run cli wp core version
70+
npx wp-env run cli wp --info
71+
72+
- name: Install playwright/test
73+
run: |
74+
npx playwright install chromium
75+
76+
- name: Run Playwright tests
77+
run: npm run test:playwright
78+
79+
- name: Stop WordPress environment
80+
if: always()
81+
run: npx wp-env stop
82+
83+
- uses: actions/upload-artifact@v4
84+
if: always()
85+
with:
86+
name: playwright-test-results
87+
path: test-results/
88+
if-no-files-found: ignore
89+
retention-days: 2
90+
91+
test-result:
92+
needs: [Playwright]
93+
if: always() && (needs.Playwright.result != 'skipped')
94+
runs-on: ubuntu-22.04
95+
name: Playwright - Test Results
96+
steps:
97+
- name: Test status
98+
run: echo "Test status is - ${{ needs.Playwright.result }}"
99+
- name: Check Playwright status
100+
if: ${{ needs.Playwright.result != 'success' && needs.Playwright.result != 'skipped' }}
101+
run: exit 1

.github/workflows/prepare-tag.yml

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
name: "(Tag): Prepare"
2+
3+
permissions:
4+
contents: write
5+
pull-requests: write
6+
actions: read
7+
8+
on:
9+
workflow_dispatch:
10+
inputs:
11+
version:
12+
description: 'Version to create the tag for (e.g. 3.6.9) or `next`'
13+
required: true
14+
type: string
15+
default: next
16+
17+
jobs:
18+
version:
19+
runs-on: ubuntu-latest
20+
outputs:
21+
tag: ${{ steps.version.outputs.version }}
22+
steps:
23+
- name: Checkout branch for release
24+
uses: actions/checkout@v4
25+
26+
- name: Get tag version from package.json
27+
id: version
28+
run: |
29+
INPUT_VERSION=${{ github.event.inputs.version }}
30+
if [ -z "$INPUT_VERSION" ]; then
31+
echo "::info:: No version input provided, defaulting to 'next'."
32+
INPUT_VERSION="next"
33+
fi
34+
35+
if [ $INPUT_VERSION = "next" ]; then
36+
CURR=$(jq -r .version package.json)
37+
MAJOR=$(echo $CURR | cut -d. -f1)
38+
MINOR=$(echo $CURR | cut -d. -f2)
39+
PATCH=$(echo $CURR | cut -d. -f3)
40+
NEW_PATCH=$((PATCH+1))
41+
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
42+
VERSION="$NEW_VERSION"
43+
else
44+
VERSION="${{ github.event.inputs.version }}"
45+
fi
46+
47+
if [ -z "$VERSION" ]; then
48+
echo "::error::Version is empty. Failing job."
49+
exit 1
50+
fi
51+
echo "version=$VERSION" >> $GITHUB_OUTPUT
52+
53+
changelog:
54+
runs-on: ubuntu-latest
55+
needs: version
56+
strategy:
57+
matrix:
58+
include:
59+
- target-file: "CHANGELOG.md"
60+
template: "changelog"
61+
name: "github-changelog"
62+
- target-file: "src/readme.txt"
63+
template: "readme"
64+
name: "wordpress-readme"
65+
steps:
66+
- name: Validate repository access
67+
id: validate
68+
env:
69+
GH_TOKEN: ${{ secrets.CHANGELOG_PAT || github.token }}
70+
run: |
71+
target_repo="codesnippetspro/.github-private"
72+
workflow_file="changelog.yml"
73+
74+
echo "::notice::Validating access to $target_repo..."
75+
76+
# Test repository access
77+
if ! gh repo view "$target_repo" >/dev/null 2>&1; then
78+
echo "::error::Cannot access repository $target_repo"
79+
echo "::error::Please ensure CHANGELOG_PAT secret is configured with access to private repositories"
80+
exit 1
81+
fi
82+
83+
echo "::notice::Repository access confirmed"
84+
85+
# Verify workflow file exists
86+
if ! gh workflow view "$workflow_file" --repo "$target_repo" >/dev/null 2>&1; then
87+
echo "::error::Workflow file '$workflow_file' not found in $target_repo"
88+
echo "::error::Expected: https://github.com/$target_repo/blob/main/.github/workflows/$workflow_file"
89+
exit 1
90+
fi
91+
92+
echo "::notice::Workflow file '$workflow_file' found"
93+
echo "target_repo=$target_repo" >> $GITHUB_OUTPUT
94+
echo "workflow_file=$workflow_file" >> $GITHUB_OUTPUT
95+
96+
- name: Dispatch changelog workflow
97+
id: dispatch
98+
env:
99+
GH_TOKEN: ${{ secrets.CHANGELOG_PAT || github.token }}
100+
run: |
101+
target_repo="${{ steps.validate.outputs.target_repo }}"
102+
workflow_file="${{ steps.validate.outputs.workflow_file }}"
103+
104+
echo "::notice::Dispatching workflow '$workflow_file' for ${{ matrix.name }}..."
105+
echo " Repository: $target_repo"
106+
echo " Version: ${{ needs.version.outputs.tag }}"
107+
echo " Template: ${{ matrix.template }}"
108+
echo " Target file: ${{ matrix.target-file }}"
109+
110+
# Dispatch the workflow with required parameters
111+
if ! gh workflow run "$workflow_file" \
112+
--repo "$target_repo" \
113+
--ref main \
114+
--field repo="${{ github.repository }}" \
115+
--field branch="${{ github.ref_name }}" \
116+
--field version="${{ needs.version.outputs.tag }}" \
117+
--field template="${{ matrix.template }}" \
118+
--field target-file="./${{ matrix.target-file }}"; then
119+
echo "::error::Failed to dispatch workflow '$workflow_file' in $target_repo"
120+
exit 1
121+
fi
122+
123+
echo "::notice::Successfully dispatched changelog generation"
124+
125+
# Wait a moment for the run to be created
126+
echo "Waiting for workflow run to be created..."
127+
sleep 10
128+
129+
# Get the workflow run URL for monitoring
130+
if run_url=$(gh run list --repo "$target_repo" --workflow "$workflow_file" --limit 1 --json url -q '.[0].url' 2>/dev/null); then
131+
if [ -n "$run_url" ] && [ "$run_url" != "null" ]; then
132+
echo "::notice::Workflow run: $run_url"
133+
echo "run_url=$run_url" >> $GITHUB_OUTPUT
134+
fi
135+
fi
136+
137+
- name: Monitor workflow completion
138+
env:
139+
GH_TOKEN: ${{ secrets.CHANGELOG_PAT || github.token }}
140+
run: |
141+
target_repo="${{ steps.validate.outputs.target_repo }}"
142+
workflow_file="${{ steps.validate.outputs.workflow_file }}"
143+
max_attempts=30
144+
attempt=0
145+
146+
echo "::notice::Monitoring workflow completion..."
147+
148+
while [ $attempt -lt $max_attempts ]; do
149+
attempt=$((attempt + 1))
150+
151+
# Get latest run status
152+
run_data=$(gh run list \
153+
--repo "$target_repo" \
154+
--workflow "$workflow_file" \
155+
--limit 1 \
156+
--json status,conclusion,url \
157+
-q '.[0] | [.status, .conclusion, .url] | @tsv' 2>/dev/null)
158+
159+
if [ -n "$run_data" ]; then
160+
status=$(echo "$run_data" | cut -f1)
161+
conclusion=$(echo "$run_data" | cut -f2)
162+
url=$(echo "$run_data" | cut -f3)
163+
164+
if [ "$status" = "completed" ]; then
165+
if [ "$conclusion" = "success" ]; then
166+
echo "::notice::Workflow completed successfully!"
167+
echo "::notice::Run details: $url"
168+
break
169+
else
170+
echo "::error::Workflow failed with conclusion: $conclusion"
171+
echo "::error::Run details: $url"
172+
exit 1
173+
fi
174+
else
175+
echo "Attempt $attempt/$max_attempts: Workflow status: $status"
176+
fi
177+
else
178+
echo "Attempt $attempt/$max_attempts: Waiting for workflow run data..."
179+
fi
180+
181+
if [ $attempt -eq $max_attempts ]; then
182+
echo "::warning::Timeout reached after $max_attempts attempts"
183+
echo "::warning::Workflow may still be running. Check manually: ${{ steps.dispatch.outputs.run_url }}"
184+
exit 0
185+
fi
186+
187+
sleep 10
188+
done

0 commit comments

Comments
 (0)