update Workflows
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
name: Build WordPress Plugin
|
name: Build WordPress Plugin for Gitea
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- 'v*' # Trigger on version tags like v1.0.0, v2.1.3
|
- 'v*' # Trigger on version tags like v1.0.0
|
||||||
# workflow_dispatch: # (Optional) Uncomment to allow manual trigger
|
# workflow_dispatch: # Uncomment to enable manual trigger
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build-release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -15,25 +15,27 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
# 1. SETUP PHP (for Composer, if used)
|
# 1. 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.
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
# 2. SETUP NODE (for NPM/Yarn, if used)
|
# 2. 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' # or 'yarn'
|
cache: 'npm'
|
||||||
|
# If your plugin does NOT use NPM, remove this step.
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
# 3. INSTALL & BUILD ASSETS (optional)
|
# 3. OPTIONAL – Install dependencies & build assets
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
- name: Install Composer dependencies (production only)
|
- name: Install Composer dependencies (production only)
|
||||||
run: |
|
run: |
|
||||||
@@ -41,7 +43,7 @@ jobs:
|
|||||||
composer install --no-dev --prefer-dist --optimize-autoloader
|
composer install --no-dev --prefer-dist --optimize-autoloader
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Install NPM dependencies & build assets
|
- name: Install NPM dependencies & build
|
||||||
run: |
|
run: |
|
||||||
if [ -f "package.json" ]; then
|
if [ -f "package.json" ]; then
|
||||||
npm ci
|
npm ci
|
||||||
@@ -51,19 +53,19 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
# 4. EXTRACT PLUGIN VERSION FROM MAIN FILE
|
# 4. Extract plugin metadata from main file
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
- name: Get plugin version and slug
|
- name: Get plugin version and slug
|
||||||
id: meta
|
id: meta
|
||||||
run: |
|
run: |
|
||||||
# Find the main plugin file (the one with the WordPress header)
|
# 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
|
# 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
|
||||||
@@ -75,32 +77,33 @@ jobs:
|
|||||||
|
|
||||||
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 "MAIN_FILE=$MAIN_FILE" >> $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)
|
# 5. 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
|
# Rsync all files, excluding common dev/dependency folders
|
||||||
|
# If you have a .distignore file, use: --exclude-from='.distignore'
|
||||||
rsync -av \
|
rsync -av \
|
||||||
--exclude='.git' \
|
--exclude='.git' \
|
||||||
--exclude='.github' \
|
--exclude='.github' \
|
||||||
--exclude='.distignore' \
|
--exclude='.distignore' \
|
||||||
--exclude='.gitignore' \
|
--exclude='.gitignore' \
|
||||||
--exclude='node_modules' \
|
--exclude='node_modules' \
|
||||||
--exclude='vendor' \ # Composer dev dependencies (we already installed --no-dev, but safe to exclude if standalone)
|
--exclude='vendor' \ # we installed --no-dev, but safe to exclude anyway
|
||||||
--exclude='tests' \
|
--exclude='tests' \
|
||||||
--exclude='.env*' \
|
--exclude='.env*' \
|
||||||
--exclude='*.log' \
|
--exclude='*.log' \
|
||||||
--exclude='*.map' \
|
--exclude='*.map' \
|
||||||
--exclude='*.lock' \ # package-lock.json / composer.lock (optional, sometimes kept)
|
--exclude='package-lock.json' \
|
||||||
--exclude='package.json' \ # Remove if you want to keep it in production
|
--exclude='composer.lock' \
|
||||||
|
--exclude='package.json' \ # Remove if you want to keep it
|
||||||
--exclude='composer.json' \ # Remove if you want to keep it
|
--exclude='composer.json' \ # Remove if you want to keep it
|
||||||
--exclude='webpack.config.js' \
|
--exclude='webpack.config.js' \
|
||||||
--exclude='gulpfile.js' \
|
--exclude='gulpfile.js' \
|
||||||
@@ -109,11 +112,10 @@ 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
|
||||||
|
|
||||||
# NOTE: If your plugin needs composer.json/package.json in production,
|
# Adjust excludes above if your plugin needs any of these files in production.
|
||||||
# remove those specific --exclude lines above.
|
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
# 6. CREATE ZIP ARCHIVE
|
# 6. Create ZIP archive
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
- name: Create plugin zip
|
- name: Create plugin zip
|
||||||
run: |
|
run: |
|
||||||
@@ -123,9 +125,9 @@ jobs:
|
|||||||
echo "✅ Created: $FILENAME"
|
echo "✅ Created: $FILENAME"
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
# 7. UPLOAD TO GITHUB RELEASE
|
# 7. Install and configure tea CLI
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
- name: Install tea CLI
|
- 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
|
||||||
chmod +x tea
|
chmod +x tea
|
||||||
@@ -135,14 +137,26 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
tea login add \
|
tea login add \
|
||||||
--name gitea \
|
--name gitea \
|
||||||
--url "${{ vars.SERVER_URL }}" \
|
--url "${{ vars.GITEA_SERVER_URL }}" \
|
||||||
--token "${{ secrets.OC3_EXTENSION_RELEASE_TOKEN }}"
|
--token "${{ secrets.GITEA_TOKEN }}"
|
||||||
|
|
||||||
- name: Create Gitea Release
|
# ------------------------------------------------
|
||||||
|
# 8. Create or update Gitea release
|
||||||
|
# ------------------------------------------------
|
||||||
|
- name: Create 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)
|
||||||
|
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"
|
||||||
|
|
||||||
|
echo "✅ Release $TAG created with asset ${{ env.FILENAME }}"
|
||||||
Reference in New Issue
Block a user