Skip to content

Commit 69cdb6a

Browse files
committed
Updated package name. Thanks @theodesp . Updated logic of pre-release to catch some errors. Thanks @ahuseyn
1 parent ea2411a commit 69cdb6a

File tree

3 files changed

+191
-135
lines changed

3 files changed

+191
-135
lines changed

.github/workflows/pre-release.yml

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
paths:
88
- "plugins/**"
99

10+
permissions:
11+
contents: write # Allow actions to read and write repository contents
12+
actions: read # Allow actions to read repository metadata but not write
1013
jobs:
1114
tag-pre-release:
1215
runs-on: ubuntu-latest
@@ -36,10 +39,22 @@ jobs:
3639
- name: Get changed plugin directory
3740
id: plugin
3841
run: |
39-
git fetch --prune --unshallow || true
42+
git fetch --prune --unshallow
4043
plugin=$(git diff --name-only HEAD~1 HEAD | grep '^plugins/' | head -1 | cut -d/ -f2)
4144
echo "plugin_slug=$plugin" >> $GITHUB_OUTPUT
4245
46+
- name: Validate plugin detection
47+
run: |
48+
if [ -z "${{ steps.plugin.outputs.plugin_slug }}" ]; then
49+
echo "No plugin detected in changes"
50+
exit 1
51+
fi
52+
53+
if [ ! -d "plugins/${{ steps.plugin.outputs.plugin_slug }}" ]; then
54+
echo "Plugin directory does not exist"
55+
exit 1
56+
fi
57+
4358
- name: Install dependencies
4459
run: pnpm install
4560

@@ -58,42 +73,74 @@ jobs:
5873
id: metadata
5974
run: |
6075
PLUGIN_DIR="plugins/${{ steps.plugin.outputs.plugin_slug }}"
76+
77+
if [ ! -f "$PLUGIN_DIR/package.json" ]; then
78+
echo "package.json not found in $PLUGIN_DIR"
79+
exit 1
80+
fi
81+
6182
package_name=$(jq -r '.name // empty' "$PLUGIN_DIR/package.json")
6283
package_version=$(jq -r '.version // empty' "$PLUGIN_DIR/package.json")
6384
64-
if [ -z "$package_name" ] || [ -z "$package_version" ]; then
65-
echo "Missing name or version in $PLUGIN_DIR/package.json"
85+
if [ -z "$package_name" ] || [ "$package_name" = "null" ] || [ "$package_name" = "empty" ]; then
86+
echo "Missing or invalid name in $PLUGIN_DIR/package.json"
87+
exit 1
88+
fi
89+
90+
if [ -z "$package_version" ] || [ "$package_version" = "null" ] || [ "$package_version" = "empty" ]; then
91+
echo "Missing or invalid version in $PLUGIN_DIR/package.json"
6692
exit 1
6793
fi
6894
6995
echo "package_name=$package_name" >> $GITHUB_OUTPUT
7096
echo "package_version=$package_version" >> $GITHUB_OUTPUT
71-
echo "PLUGIN_DIR=$PLUGIN_DIR" >> $GITHUB_ENV
97+
echo "PLUGIN_DIR=$PLUGIN_DIR" >> $GITHUB_OUTPUT
7298
7399
- name: Create Git tag
74100
run: |
75101
TAG_NAME="${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}"
102+
103+
# Check if tag already exists
104+
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
105+
echo "Tag $TAG_NAME already exists. Skipping tag creation."
106+
exit 0
107+
fi
108+
76109
git config user.name "github-actions"
77110
git config user.email "[email protected]"
78111
git tag "$TAG_NAME"
79112
git push origin "$TAG_NAME"
80113
81114
- name: Run composer install
82-
working-directory: ${{ env.PLUGIN_DIR }}
115+
working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }}
83116
run: composer install --no-dev --optimize-autoloader
84117

118+
- name: Validate composer setup
119+
working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }}
120+
run: |
121+
composer validate --no-check-publish --no-check-lock
122+
85123
- name: Create plugin archive
86-
working-directory: ${{ env.PLUGIN_DIR }}
124+
working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }}
87125
run: |
88-
mkdir -p plugin-build || true
89-
composer archive -vvv --format=zip --file="plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip" --dir="."
126+
mkdir -p plugin-build
127+
composer archive --format=zip --file="plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip"
128+
129+
# Verify archive was created
130+
if [ ! -f "plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip" ]; then
131+
echo "Failed to create plugin archive"
132+
exit 1
133+
fi
134+
135+
echo "Archive created successfully: $(ls -lh plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip)"
90136
91137
- name: Upload archive to GitHub Release
92138
uses: softprops/action-gh-release@v2
93139
with:
94140
tag_name: ${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}
95141
name: "Pre-release ${{ steps.metadata.outputs.package_version }} for ${{ steps.metadata.outputs.package_name }}"
96142
prerelease: true
97-
files: ${{ env.PLUGIN_DIR }}/plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip
143+
files: |
144+
${{ steps.metadata.outputs.PLUGIN_DIR }}/plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip
98145
env:
99146
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)