update
WP Plugin Version & Release / release (push) Failing after 25s

This commit is contained in:
Mohamed Youssef
2026-08-02 09:48:11 +03:00
parent b8674dc363
commit baf56793b6
+145 -115
View File
@@ -1,144 +1,174 @@
name: Build WordPress Plugin for Gitea name: WP Plugin Version & Release
on: on:
push: push:
branches: branches:
- main # Triggers on every push to main - main
jobs: jobs:
build-release: release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 0
# -------------------------------- - name: Install rsync
# OPTIONAL: Setup PHP & Composer run: sudo apt-get update && sudo apt-get install -y rsync
# --------------------------------
# - name: Setup PHP
# uses: shivammathur/setup-php@v2
# with:
# php-version: '7.4'
# tools: composer
# Remove if your plugin does not use Composer.
# -------------------------------- # ------------------------------------------------------------
# OPTIONAL: Setup Node & NPM # 1. Locate the main plugin file (recursively, excluding junk)
# -------------------------------- # ------------------------------------------------------------
# - name: Setup Node.js - name: Locate main plugin file
# uses: actions/setup-node@v4 id: locate
# with: run: |
# node-version: '20' FILE=$(grep -rlE "^[[:space:]]*(\*|/\*\*)?[[:space:]]*Plugin Name:" \
# cache: 'npm' --include="*.php" . \
# Remove if your plugin does not use NPM. | grep -v -e '/vendor/' -e '/node_modules/' -e '/build/' \
| head -n1)
# -------------------------------- if [ -z "$FILE" ]; then
# OPTIONAL: Install dependencies & build assets echo "::error::Could not find a PHP file with a 'Plugin Name:' header."
# -------------------------------- exit 1
# - name: Install Composer dependencies (production only) fi
# run: |
# if [ -f "composer.json" ]; then
# composer install --no-dev --prefer-dist --optimize-autoloader
# fi
# - name: Install NPM dependencies & build echo "Found main plugin file: $FILE"
# run: | echo "file=${FILE}" >> "$GITHUB_OUTPUT"
# if [ -f "package.json" ]; then
# npm ci
# fi
# if [ -f "package.json" ] && grep -q '"build"' package.json; then
# npm run build
# fi
# -------------------------------- # ------------------------------------------------------------
# Extract plugin metadata # 2. Parse Plugin Name, Slug, and Version from the header
# -------------------------------- # ------------------------------------------------------------
- name: Get plugin version and slug - name: Extract plugin name & version from header
id: meta id: meta
run: | run: |
MAIN_FILE=$(find . -maxdepth 3 -type f -name "*.php" -exec grep -l "Plugin Name:" {} \; | head -n 1) FILE="${{ steps.locate.outputs.file }}"
if [ -z "$MAIN_FILE" ]; then HEADER=$(sed -n '1,40p' "$FILE")
echo "❌ No plugin file with 'Plugin Name:' found!" >&2
exit 1
fi
MAIN_FILE=${MAIN_FILE#./}
VERSION=$(grep "^Version:" "$MAIN_FILE" | awk -F' ' '{print $NF}' | tr -d '\r')
if [ -z "$VERSION" ]; then
echo "❌ Version header not found in $MAIN_FILE" >&2
exit 1
fi
SLUG="${GITHUB_REPOSITORY##*/}"
echo "PLUGIN_SLUG=$SLUG" >> $GITHUB_ENV
echo "PLUGIN_VERSION=$VERSION" >> $GITHUB_ENV
echo "FILENAME=${SLUG}-${VERSION}.zip" >> $GITHUB_ENV
echo "MAIN_FILE=$MAIN_FILE" >> $GITHUB_ENV
echo "✅ Plugin: $SLUG, Version: $VERSION (main file: $MAIN_FILE)"
# -------------------------------- PLUGIN_NAME=$(echo "$HEADER" | grep -im1 'Plugin Name:' \
# Prepare package (exclude dev files) | sed -E 's/^[[:space:]]*(\*|\/\*\*)?[[:space:]]*Plugin Name:[[:space:]]*//' \
# -------------------------------- | sed -E 's/[[:space:]]*\*\/?[[:space:]]*$//')
- name: Prepare package directory
VERSION=$(echo "$HEADER" | grep -im1 'Version:' \
| sed -E 's/^[[:space:]]*(\*|\/\*\*)?[[:space:]]*Version:[[:space:]]*//' \
| sed -E 's/[[:space:]]*\*\/?[[:space:]]*$//')
if [ -z "$PLUGIN_NAME" ] || [ -z "$VERSION" ]; then
echo "::error::Could not parse Plugin Name or Version from $FILE header."
exit 1
fi
SLUG=$(echo "$PLUGIN_NAME" | tr '[:upper:]' '[:lower:]' \
| sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//')
echo "Plugin: $PLUGIN_NAME"
echo "Slug: $SLUG"
echo "Version: $VERSION"
echo "name=${PLUGIN_NAME}" >> "$GITHUB_OUTPUT"
echo "slug=${SLUG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
# ------------------------------------------------------------
# 3. Check if this version already has a release (tag)
# ------------------------------------------------------------
- name: Check if this version already has a release
id: check
run: | run: |
mkdir -p /tmp/build/${{ env.PLUGIN_SLUG }} TAG="v${{ steps.meta.outputs.version }}"
rsync -av \ git fetch --tags --quiet
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists — skipping release."
echo "should_release=false" >> "$GITHUB_OUTPUT"
else
echo "Tag $TAG is new — will release."
echo "should_release=true" >> "$GITHUB_OUTPUT"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
# ------------------------------------------------------------
# 4. Update Stable tag in readme.txt (if present)
# ------------------------------------------------------------
- name: Update Stable tag in readme.txt
if: steps.check.outputs.should_release == 'true' && runner.os == 'Linux' && hashFiles('readme.txt') != ''
run: |
sed -i -E "s/^(Stable tag:[[:space:]]*).*/\1${{ steps.meta.outputs.version }}/" readme.txt
if ! git diff --quiet -- readme.txt; then
git config user.name "gitea-actions"
git config user.email "actions@noreply.gitea"
git add readme.txt
git commit -m "chore: sync readme.txt stable tag to ${{ steps.meta.outputs.version }} [skip ci]"
# Push using the token (set remote below)
fi
# Note: We'll handle the actual push later, after setting the remote.
# ------------------------------------------------------------
# 5. Configure git remote with token and push everything
# ------------------------------------------------------------
- name: Push commits and tags to Gitea
if: steps.check.outputs.should_release == 'true'
run: |
# Reconstruct the remote URL with the token
GITEA_SERVER="${{ vars.GITEA_SERVER_URL }}"
GITEA_REPO="${{ vars.GITEA_REPO }}"
# Remove protocol part to build oauth2 URL
SERVER_HOST="${GITEA_SERVER#https://}"
SERVER_HOST="${SERVER_HOST#http://}"
git remote set-url origin "https://oauth2:${{ secrets.RELEASE_TOKEN }}@${SERVER_HOST}/${GITEA_REPO}.git"
git push origin HEAD:refs/heads/main
git push origin "${{ steps.check.outputs.tag }}"
# ------------------------------------------------------------
# 6. Build the plugin zip (only if we are releasing)
# ------------------------------------------------------------
- name: Build plugin zip
if: steps.check.outputs.should_release == 'true'
run: |
SLUG="${{ steps.meta.outputs.slug }}"
mkdir -p build/"${SLUG}"
rsync -a \
--exclude='.git' \ --exclude='.git' \
--exclude='.gitea' \
--exclude='.github' \ --exclude='.github' \
--exclude='.distignore' \
--exclude='.gitignore' \
--exclude='node_modules' \ --exclude='node_modules' \
--exclude='vendor' \ --exclude='build' \
--exclude='tests' \ --exclude='*.zip' \
--exclude='.env*' \ ./ build/"${SLUG}"/
--exclude='*.log' \ cd build
--exclude='*.map' \ zip -r "../${SLUG}-${{ steps.meta.outputs.version }}.zip" "${SLUG}"
--exclude='package-lock.json' \
--exclude='composer.lock' \
--exclude='package.json' \
--exclude='composer.json' \
--exclude='webpack.config.js' \
--exclude='gulpfile.js' \
--exclude='Gruntfile.js' \
--exclude='phpunit.xml' \
--exclude='.wordpress-org' \
./ /tmp/build/${{ env.PLUGIN_SLUG }}/ 2>/dev/null || true
# -------------------------------- # ------------------------------------------------------------
# Create ZIP # 7. Install tea CLI (pinned version)
# -------------------------------- # ------------------------------------------------------------
- name: Create plugin zip
run: |
cd /tmp/build
zip -r "$GITHUB_WORKSPACE/${{ env.FILENAME }}" ${{ env.PLUGIN_SLUG }}/
cd $GITHUB_WORKSPACE
echo "✅ Created: $FILENAME"
# --------------------------------
# Install & configure tea CLI
# --------------------------------
- name: Install tea CLI - name: Install tea CLI
if: steps.check.outputs.should_release == 'true'
run: | run: |
curl -L https://dl.gitea.io/tea/0.11.0/tea-0.11.0-linux-amd64 -o tea TEA_VERSION="0.14.2"
chmod +x tea curl -fL -o /usr/local/bin/tea \
sudo mv tea /usr/local/bin/ "https://gitea.com/gitea/tea/releases/download/v${TEA_VERSION}/tea-${TEA_VERSION}-linux-amd64"
chmod +x /usr/local/bin/tea
tea --version
- name: Configure tea # ------------------------------------------------------------
# 8. Create Gitea Release (with the asset)
# ------------------------------------------------------------
- name: Create Gitea Release (tea CLI)
if: steps.check.outputs.should_release == 'true'
run: | run: |
ZIP="${{ steps.meta.outputs.slug }}-${{ steps.meta.outputs.version }}.zip"
# Ensure the zip exists
if [ ! -f "$ZIP" ]; then
echo "::error::Zip file $ZIP not found!" >&2
exit 1
fi
tea login add \ tea login add \
--name gitea \ --name ci \
--url "${{ vars.GITEA_SERVER_URL }}" \ --url "${{ vars.GITEA_SERVER_URL }}" \
--token "${{ secrets.GITEA_TOKEN }}" --token "${{ secrets.RELEASE_TOKEN }}"
# -------------------------------- tea release create \
# Create/forceupdate Gitea release --repo "${{ vars.GITEA_REPO }}" \
# -------------------------------- --tag "${{ steps.check.outputs.tag }}" \
- name: Create/update Gitea release --title "${{ steps.meta.outputs.name }} ${{ steps.meta.outputs.version }}" \
run: | --asset "${ZIP}"
TAG="v${{ env.PLUGIN_VERSION }}"
REPO="${{ vars.GITEA_REPO }}"
tea release create "$TAG" \
--title "${{ env.PLUGIN_SLUG }} v${{ env.PLUGIN_VERSION }}" \
--asset "${{ env.FILENAME }}" \
--repo "$REPO" \
--force
echo "✅ Release $TAG created/updated with asset ${{ env.FILENAME }}"