Skip to content

Commit fc793d4

Browse files
committed
Refactoring @josephfusco work for plugin slug into a re-usable bash script to help reduce duplicate code for the various workflows.
1 parent 9b3ff16 commit fc793d4

2 files changed

Lines changed: 49 additions & 8 deletions

File tree

.github/scripts/get-plugin-slug.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
BASE_SHA="$1"
6+
HEAD_SHA="$2"
7+
8+
git fetch --prune --unshallow
9+
10+
# Get changed files in plugins subdirectories
11+
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" | grep '^plugins/[^/]\+/' || true)
12+
13+
if [ -z "$CHANGED_FILES" ]; then
14+
echo "No plugin files changed"
15+
exit 1
16+
fi
17+
18+
# Extract plugin names from both old and new paths
19+
PLUGINS=()
20+
for file in $CHANGED_FILES; do
21+
plugin=$(echo $file | cut -d/ -f2)
22+
PLUGINS+=("$plugin")
23+
done
24+
25+
# Get unique plugin names
26+
UNIQUE_PLUGINS=($(printf '%s\n' "${PLUGINS[@]}" | sort -u))
27+
28+
# Find the first plugin that actually exists
29+
PLUGIN_SLUG=""
30+
for plugin in "${UNIQUE_PLUGINS[@]}"; do
31+
if [ -d "plugins/$plugin" ]; then
32+
PLUGIN_SLUG="$plugin"
33+
echo "Found existing plugin directory: $PLUGIN_SLUG"
34+
break
35+
fi
36+
done
37+
38+
if [ -z "$PLUGIN_SLUG" ]; then
39+
echo "No valid plugin directory found"
40+
exit 1
41+
fi
42+
43+
echo "slug=$PLUGIN_SLUG" >> "$GITHUB_OUTPUT"

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ jobs:
2020
- name: Get changed plugin directory
2121
id: plugin
2222
run: |
23-
git fetch --prune --unshallow
24-
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
25-
echo "slug=$plugin" >> $GITHUB_OUTPUT
23+
bash .github/scripts/get-plugin-slug.sh ${{ github.event.pull_request.base.sha }} ${{ github.sha }}
2624
2725
- name: Create plugin artifact
2826
uses: ./.github/actions/create-plugin-artifact
@@ -44,20 +42,20 @@ jobs:
4442
const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
4543
const slug = process.env.PLUGIN_SLUG;
4644
const body = `ℹ️ [Download the latest ${slug} plugin zip from this PR](${artifactUrl})\n<em>(See the 'Artifacts' section at the bottom)</em>`;
47-
45+
4846
// Find existing comment from this bot
4947
const comments = await github.rest.issues.listComments({
5048
issue_number: pr.number,
5149
owner: context.repo.owner,
5250
repo: context.repo.repo
5351
});
54-
55-
const botComment = comments.data.find(comment =>
56-
comment.user.type === 'Bot' &&
52+
53+
const botComment = comments.data.find(comment =>
54+
comment.user.type === 'Bot' &&
5755
comment.user.login === 'github-actions[bot]' &&
5856
comment.body.includes(`ℹ️ [Download the latest ${slug} plugin zip from this PR]`)
5957
);
60-
58+
6159
if (botComment) {
6260
// Update existing comment
6361
core.info(`Updating existing comment with ID: ${botComment.id}`);

0 commit comments

Comments
 (0)