updates
This commit is contained in:
@@ -2,9 +2,8 @@ name: Build WordPress Plugin for Gitea
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
branches:
|
||||||
- 'v*' # Trigger on version tags like v1.0.0
|
- main # Triggers on every push to main
|
||||||
# workflow_dispatch: # Uncomment to enable manual trigger
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-release:
|
build-release:
|
||||||
@@ -14,29 +13,29 @@ jobs:
|
|||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
# 1. OPTIONAL – Setup PHP & Composer
|
# OPTIONAL: Setup PHP & Composer
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: '7.4'
|
php-version: '7.4'
|
||||||
tools: composer
|
tools: composer
|
||||||
# If your plugin does NOT use Composer, remove this step.
|
# Remove if your plugin does not use Composer.
|
||||||
|
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
# 2. OPTIONAL – Setup Node & NPM
|
# OPTIONAL: Setup Node & NPM
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '20'
|
node-version: '20'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
# If your plugin does NOT use NPM, remove this step.
|
# Remove if your plugin does not use NPM.
|
||||||
|
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
# 3. OPTIONAL – Install dependencies & build assets
|
# OPTIONAL: Install dependencies & build assets
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
- name: Install Composer dependencies (production only)
|
- name: Install Composer dependencies (production only)
|
||||||
run: |
|
run: |
|
||||||
if [ -f "composer.json" ]; then
|
if [ -f "composer.json" ]; then
|
||||||
@@ -52,43 +51,39 @@ jobs:
|
|||||||
npm run build
|
npm run build
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
# 4. Extract plugin metadata from main file
|
# Extract plugin metadata
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
- name: Get plugin version and slug
|
- name: Get plugin version and slug
|
||||||
id: meta
|
id: meta
|
||||||
run: |
|
run: |
|
||||||
# Find the main plugin file (with "Plugin Name:" header)
|
|
||||||
MAIN_FILE=$(grep -l "Plugin Name:" *.php | head -n 1)
|
MAIN_FILE=$(grep -l "Plugin Name:" *.php | head -n 1)
|
||||||
if [ -z "$MAIN_FILE" ]; then
|
if [ -z "$MAIN_FILE" ]; then
|
||||||
echo "❌ No main plugin file (with 'Plugin Name:') found!" >&2
|
echo "❌ No main plugin file (with 'Plugin Name:') found!" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Extract version (strip trailing carriage returns)
|
|
||||||
VERSION=$(grep "^Version:" "$MAIN_FILE" | awk -F' ' '{print $NF}' | tr -d '\r')
|
VERSION=$(grep "^Version:" "$MAIN_FILE" | awk -F' ' '{print $NF}' | tr -d '\r')
|
||||||
if [ -z "$VERSION" ]; then
|
if [ -z "$VERSION" ]; then
|
||||||
echo "❌ Version header not found in $MAIN_FILE" >&2
|
echo "❌ Version header not found in $MAIN_FILE" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use repository name as slug, or override with a custom variable
|
# Use repository name as the plugin slug
|
||||||
SLUG="${GITHUB_REPOSITORY##*/}"
|
SLUG="${GITHUB_REPOSITORY##*/}"
|
||||||
|
|
||||||
echo "PLUGIN_SLUG=$SLUG" >> $GITHUB_ENV
|
echo "PLUGIN_SLUG=$SLUG" >> $GITHUB_ENV
|
||||||
echo "PLUGIN_VERSION=$VERSION" >> $GITHUB_ENV
|
echo "PLUGIN_VERSION=$VERSION" >> $GITHUB_ENV
|
||||||
echo "FILENAME=${SLUG}-${VERSION}.zip" >> $GITHUB_ENV
|
echo "FILENAME=${SLUG}-${VERSION}.zip" >> $GITHUB_ENV
|
||||||
echo "MAIN_FILE=$MAIN_FILE" >> $GITHUB_ENV
|
|
||||||
echo "✅ Plugin: $SLUG, Version: $VERSION"
|
echo "✅ Plugin: $SLUG, Version: $VERSION"
|
||||||
|
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
# 5. Prepare package (exclude dev files)
|
# Prepare package (exclude dev files)
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
- name: Prepare package directory
|
- name: Prepare package directory
|
||||||
run: |
|
run: |
|
||||||
mkdir -p /tmp/build/${{ env.PLUGIN_SLUG }}
|
mkdir -p /tmp/build/${{ env.PLUGIN_SLUG }}
|
||||||
|
|
||||||
# Rsync all files, excluding common dev/dependency folders
|
|
||||||
# If you have a .distignore file, use: --exclude-from='.distignore'
|
# If you have a .distignore file, use: --exclude-from='.distignore'
|
||||||
rsync -av \
|
rsync -av \
|
||||||
--exclude='.git' \
|
--exclude='.git' \
|
||||||
@@ -96,15 +91,15 @@ jobs:
|
|||||||
--exclude='.distignore' \
|
--exclude='.distignore' \
|
||||||
--exclude='.gitignore' \
|
--exclude='.gitignore' \
|
||||||
--exclude='node_modules' \
|
--exclude='node_modules' \
|
||||||
--exclude='vendor' \ # we installed --no-dev, but safe to exclude anyway
|
--exclude='vendor' \
|
||||||
--exclude='tests' \
|
--exclude='tests' \
|
||||||
--exclude='.env*' \
|
--exclude='.env*' \
|
||||||
--exclude='*.log' \
|
--exclude='*.log' \
|
||||||
--exclude='*.map' \
|
--exclude='*.map' \
|
||||||
--exclude='package-lock.json' \
|
--exclude='package-lock.json' \
|
||||||
--exclude='composer.lock' \
|
--exclude='composer.lock' \
|
||||||
--exclude='package.json' \ # Remove if you want to keep it
|
--exclude='package.json' \
|
||||||
--exclude='composer.json' \ # Remove if you want to keep it
|
--exclude='composer.json' \
|
||||||
--exclude='webpack.config.js' \
|
--exclude='webpack.config.js' \
|
||||||
--exclude='gulpfile.js' \
|
--exclude='gulpfile.js' \
|
||||||
--exclude='Gruntfile.js' \
|
--exclude='Gruntfile.js' \
|
||||||
@@ -112,11 +107,11 @@ jobs:
|
|||||||
--exclude='.wordpress-org' \
|
--exclude='.wordpress-org' \
|
||||||
./ /tmp/build/${{ env.PLUGIN_SLUG }}/ 2>/dev/null || true
|
./ /tmp/build/${{ env.PLUGIN_SLUG }}/ 2>/dev/null || true
|
||||||
|
|
||||||
# Adjust excludes above if your plugin needs any of these files in production.
|
# Adjust excludes if your plugin needs any of these files in production.
|
||||||
|
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
# 6. Create ZIP archive
|
# Create ZIP archive
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
- name: Create plugin zip
|
- name: Create plugin zip
|
||||||
run: |
|
run: |
|
||||||
cd /tmp/build
|
cd /tmp/build
|
||||||
@@ -124,9 +119,9 @@ jobs:
|
|||||||
cd $GITHUB_WORKSPACE
|
cd $GITHUB_WORKSPACE
|
||||||
echo "✅ Created: $FILENAME"
|
echo "✅ Created: $FILENAME"
|
||||||
|
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
# 7. Install and configure tea CLI
|
# Install & configure tea CLI
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
- name: Install tea CLI (pinned version)
|
- name: Install tea CLI (pinned version)
|
||||||
run: |
|
run: |
|
||||||
curl -L https://dl.gitea.io/tea/0.11.0/tea-0.11.0-linux-amd64 -o tea
|
curl -L https://dl.gitea.io/tea/0.11.0/tea-0.11.0-linux-amd64 -o tea
|
||||||
@@ -140,23 +135,19 @@ jobs:
|
|||||||
--url "${{ vars.GITEA_SERVER_URL }}" \
|
--url "${{ vars.GITEA_SERVER_URL }}" \
|
||||||
--token "${{ secrets.GITEA_TOKEN }}"
|
--token "${{ secrets.GITEA_TOKEN }}"
|
||||||
|
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
# 8. Create or update Gitea release
|
# Create or force‑update Gitea release
|
||||||
# ------------------------------------------------
|
# --------------------------------
|
||||||
- name: Create Gitea release
|
- name: Create/update Gitea release
|
||||||
run: |
|
run: |
|
||||||
TAG="v${{ env.PLUGIN_VERSION }}"
|
TAG="v${{ env.PLUGIN_VERSION }}"
|
||||||
REPO="${{ vars.GITEA_REPO }}"
|
REPO="${{ vars.GITEA_REPO }}"
|
||||||
|
|
||||||
# If a release with this tag already exists, delete it (optional)
|
# --force will overwrite an existing release with the same tag
|
||||||
if tea release list --repo "$REPO" | grep -q "^$TAG "; then
|
|
||||||
echo "Release $TAG already exists – deleting it."
|
|
||||||
tea release delete "$TAG" --repo "$REPO"
|
|
||||||
fi
|
|
||||||
|
|
||||||
tea release create "$TAG" \
|
tea release create "$TAG" \
|
||||||
--title "${{ env.PLUGIN_SLUG }} v${{ env.PLUGIN_VERSION }}" \
|
--title "${{ env.PLUGIN_SLUG }} v${{ env.PLUGIN_VERSION }}" \
|
||||||
--asset "${{ env.FILENAME }}" \
|
--asset "${{ env.FILENAME }}" \
|
||||||
--repo "$REPO"
|
--repo "$REPO" \
|
||||||
|
--force
|
||||||
|
|
||||||
echo "✅ Release $TAG created with asset ${{ env.FILENAME }}"
|
echo "✅ Release $TAG created/updated with asset ${{ env.FILENAME }}"
|
||||||
Reference in New Issue
Block a user