Skip to content

Commit 48279b4

Browse files
committed
ci: build all changed plugins instead of single plugin selection
1 parent c774aed commit 48279b4

File tree

2 files changed

+60
-19
lines changed

2 files changed

+60
-19
lines changed

.github/scripts/get_plugin_slug.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,30 @@ done
2929
# Get unique plugin names
3030
UNIQUE_PLUGINS=($(printf '%s\n' "${PLUGINS[@]}" | sort -u))
3131

32-
# Find the first plugin that actually exists
33-
PLUGIN_SLUG=""
32+
# Find all valid plugins that have changes
33+
VALID_PLUGINS=()
3434
for plugin in "${UNIQUE_PLUGINS[@]}"; do
35-
if [ -d "plugins/$plugin" ] || [[ " ${CHANGED_FILES[@]} " =~ "plugins/$plugin/" ]]; then
36-
PLUGIN_SLUG="$plugin"
37-
echo "Found plugin in changes or directory: $PLUGIN_SLUG"
38-
break
35+
if [ -d "plugins/$plugin" ]; then
36+
count=$(printf '%s\n' "${PLUGINS[@]}" | grep -c "^$plugin$")
37+
VALID_PLUGINS+=("$plugin")
38+
echo "Found plugin with $count changes: $plugin"
3939
fi
4040
done
4141

42+
# Output all valid plugins as JSON array for matrix strategy
43+
if [ ${#VALID_PLUGINS[@]} -gt 0 ]; then
44+
PLUGINS_JSON=$(printf '%s\n' "${VALID_PLUGINS[@]}" | jq -R . | jq -s .)
45+
echo "plugins=$PLUGINS_JSON" >> "$GITHUB_OUTPUT"
46+
echo "has-plugins=true" >> "$GITHUB_OUTPUT"
47+
48+
# For backward compatibility, set slug to first plugin
49+
PLUGIN_SLUG="${VALID_PLUGINS[0]}"
50+
else
51+
echo "plugins=[]" >> "$GITHUB_OUTPUT"
52+
echo "has-plugins=false" >> "$GITHUB_OUTPUT"
53+
PLUGIN_SLUG=""
54+
fi
55+
4256
if [ -z "$PLUGIN_SLUG" ]; then
4357
echo "No valid plugin directory found"
4458
exit 1

.github/workflows/plugin-artifact-for-pr.yml

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,68 @@ on:
99
- 'plugins/*/**.json'
1010

1111
jobs:
12-
create-plugin-artifact:
13-
name: Create Plugin Artifact
12+
detect-plugins:
13+
name: Detect Changed Plugins
1414
runs-on: ubuntu-latest
15-
15+
outputs:
16+
plugins: ${{ steps.plugin.outputs.plugins }}
17+
has-plugins: ${{ steps.plugin.outputs.has-plugins }}
1618
steps:
1719
- name: Checkout
1820
uses: actions/checkout@v4
1921

20-
- name: Get changed plugin directory
22+
- name: Get changed plugin directories
2123
id: plugin
2224
run: |
2325
bash .github/scripts/get_plugin_slug.sh \
2426
${{ github.event.pull_request.base.sha }} \
2527
${{ github.event.pull_request.head.sha }}
2628
27-
- name: Create plugin artifact
29+
create-plugin-artifacts:
30+
name: Create Plugin Artifacts
31+
runs-on: ubuntu-latest
32+
needs: detect-plugins
33+
if: needs.detect-plugins.outputs.has-plugins == 'true'
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
plugin: ${{ fromJson(needs.detect-plugins.outputs.plugins) }}
38+
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
43+
- name: Create plugin artifact for ${{ matrix.plugin }}
2844
uses: ./.github/actions/create-plugin-artifact
29-
env:
30-
PLUGIN_SLUG: ${{ steps.plugin.outputs.slug }}
3145
with:
32-
slug: ${{ env.PLUGIN_SLUG }}
46+
slug: ${{ matrix.plugin }}
3347
composer-options: '--no-progress --optimize-autoloader --no-dev'
3448

35-
- name: Comment with artifact link
49+
comment-on-pr:
50+
name: Comment with Artifact Links
51+
runs-on: ubuntu-latest
52+
needs: [detect-plugins, create-plugin-artifacts]
53+
if: needs.detect-plugins.outputs.has-plugins == 'true'
54+
steps:
55+
- name: Comment with artifact links
3656
uses: actions/github-script@v7
3757
env:
38-
PLUGIN_SLUG: ${{ steps.plugin.outputs.slug }}
58+
PLUGINS: ${{ needs.detect-plugins.outputs.plugins }}
3959
with:
4060
github-token: ${{ secrets.GITHUB_TOKEN }}
4161
script: |
4262
const pr = context.payload.pull_request;
4363
const runId = context.runId;
4464
const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
45-
const slug = process.env.PLUGIN_SLUG;
46-
const body = `ℹ️ [Download the latest ${slug} plugin zip from this PR](${artifactUrl})\n<em>(See the 'Artifacts' section at the bottom)</em>`;
65+
const plugins = JSON.parse(process.env.PLUGINS);
66+
67+
let body = '## 📦 Plugin Artifacts Ready!\n\n';
68+
body += `[Download from GitHub Actions run](${artifactUrl})\n\n`;
69+
body += '**Available plugins:**\n';
70+
plugins.forEach(plugin => {
71+
body += `- ✅ ${plugin}.zip\n`;
72+
});
73+
body += '\n<em>See the "Artifacts" section at the bottom of the Actions run page</em>';
4774
4875
// Find existing comment from this bot
4976
const comments = await github.rest.issues.listComments({
@@ -55,7 +82,7 @@ jobs:
5582
const botComment = comments.data.find(comment =>
5683
comment.user.type === 'Bot' &&
5784
comment.user.login === 'github-actions[bot]' &&
58-
comment.body.includes(`ℹ️ [Download the latest ${slug} plugin zip from this PR]`)
85+
comment.body.includes('## 📦 Plugin Artifacts Ready!')
5986
);
6087
6188
if (botComment) {

0 commit comments

Comments
 (0)