Skip to content

chore: Added test to Previews and setup test workflow for plugins #133

chore: Added test to Previews and setup test workflow for plugins

chore: Added test to Previews and setup test workflow for plugins #133

name: Plugin Artifact for PR
on:
pull_request:
paths:
- 'plugins/**.php'
- 'plugins/**.js'
- 'plugins/**.css'
- 'plugins/**.json'
jobs:
create-plugin-artifact:
name: Create Plugin Artifact
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get changed plugin directory
id: plugin
run: |
git fetch --prune --unshallow
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
echo "slug=$plugin" >> $GITHUB_OUTPUT
- name: Create plugin artifact
uses: ./.github/actions/create-plugin-artifact
env:
PLUGIN_SLUG: ${{ steps.plugin.outputs.slug }}
with:
slug: ${{ env.PLUGIN_SLUG }}
- name: Comment with artifact link
uses: actions/github-script@v7
env:
PLUGIN_SLUG: ${{ steps.plugin.outputs.slug }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = context.payload.pull_request;
const runId = context.runId;
const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
const slug = process.env.PLUGIN_SLUG;
const body = `ℹ️ [Download the latest ${slug} plugin zip from this PR](${artifactUrl})\n<em>(See the 'Artifacts' section at the bottom)</em>`;
// Find existing comment from this bot
const comments = await github.rest.issues.listComments({
issue_number: pr.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.user.login === 'github-actions[bot]' &&
comment.body.includes(`ℹ️ [Download the latest ${slug} plugin zip from this PR]`)
);
if (botComment) {
// Update existing comment
core.info(`Updating existing comment with ID: ${botComment.id}`);
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body
});
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: pr.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
});
}