update
Build WordPress Plugin (Simple) / build-release (push) Failing after 24s

This commit is contained in:
Mohamed Youssef
2026-08-02 09:55:53 +03:00
parent 4d8823b1b3
commit 5b9ad90ed7
+63 -159
View File
@@ -1,4 +1,4 @@
name: WP Plugin Version & Release name: Build WordPress Plugin (Simple)
on: on:
push: push:
@@ -6,187 +6,91 @@ on:
- main - main
jobs: jobs:
release: build-release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 0
# -------------------------- - name: Install zip
# Validate required vars run: sudo apt-get update && sudo apt-get install -y zip
# --------------------------
- name: Check required variables
run: |
if [ -z "${{ vars.GITEA_SERVER_URL }}" ]; then
echo "::error::Missing variable: GITEA_SERVER_URL. Please add it in Settings → Secrets and variables → Actions → Variables"
exit 1
fi
if [ -z "${{ vars.GITEA_REPO }}" ]; then
echo "::error::Missing variable: GITEA_REPO. Please add it in Settings → Secrets and variables → Actions → Variables"
exit 1
fi
if [ -z "${{ secrets.RELEASE_TOKEN }}" ]; then
echo "::error::Missing secret: RELEASE_TOKEN. Please add it in Settings → Secrets and variables → Actions → Secrets"
exit 1
fi
echo "✅ All required variables and secrets are set."
- name: Install rsync # -----------------------------------------------------------------
run: sudo apt-get update && sudo apt-get install -y rsync # 1. Find the main plugin file and extract slug & version
# -----------------------------------------------------------------
# ------------------------------------------------------------ - name: Extract plugin metadata
# 1. Locate the main plugin file (recursively, excluding junk)
# ------------------------------------------------------------
- name: Locate main plugin file
id: locate
run: |
FILE=$(grep -rlE "^[[:space:]]*(\*|/\*\*)?[[:space:]]*Plugin Name:" \
--include="*.php" . \
| grep -v -e '/vendor/' -e '/node_modules/' -e '/build/' \
| head -n1)
if [ -z "$FILE" ]; then
echo "::error::Could not find a PHP file with a 'Plugin Name:' header."
exit 1
fi
echo "Found main plugin file: $FILE"
echo "file=${FILE}" >> "$GITHUB_OUTPUT"
# ------------------------------------------------------------
# 2. Parse Plugin Name, Slug, and Version from the header
# ------------------------------------------------------------
- name: Extract plugin name & version from header
id: meta id: meta
run: | run: |
FILE="${{ steps.locate.outputs.file }}" # Find the file that contains "Plugin Name:"
HEADER=$(sed -n '1,40p' "$FILE") MAIN_FILE=$(grep -rl "Plugin Name:" *.php | head -n1)
if [ -z "$MAIN_FILE" ]; then
PLUGIN_NAME=$(echo "$HEADER" | grep -im1 'Plugin Name:' \ echo "❌ No plugin file with 'Plugin Name:' found!" >&2
| sed -E 's/^[[:space:]]*(\*|\/\*\*)?[[:space:]]*Plugin Name:[[:space:]]*//' \
| sed -E 's/[[:space:]]*\*\/?[[:space:]]*$//')
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 exit 1
fi fi
SLUG=$(echo "$PLUGIN_NAME" | tr '[:upper:]' '[:lower:]' \ # Extract version (strip trailing newline)
| sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//') VERSION=$(grep "^Version:" "$MAIN_FILE" | awk '{print $NF}' | tr -d '\r')
if [ -z "$VERSION" ]; then
echo "Plugin: $PLUGIN_NAME" echo "❌ Version not found in $MAIN_FILE" >&2
echo "Slug: $SLUG" exit 1
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: |
TAG="v${{ steps.meta.outputs.version }}"
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' && 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]"
fi fi
# ------------------------------------------------------------ # Use repository name as the slug (or override with a custom variable)
# 5. Push commits and tags to Gitea (using token) SLUG="${GITHUB_REPOSITORY##*/}"
# ------------------------------------------------------------
- name: Push commits and tags to Gitea echo "SLUG=$SLUG" >> $GITHUB_ENV
if: steps.check.outputs.should_release == 'true' echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "FILENAME=${SLUG}-${VERSION}.zip" >> $GITHUB_ENV
echo "✅ Plugin: $SLUG, Version: $VERSION"
# -----------------------------------------------------------------
# 2. Prepare the package (copy everything except .git and .github)
# -----------------------------------------------------------------
- name: Prepare package
run: | run: |
GITEA_SERVER="${{ vars.GITEA_SERVER_URL }}" mkdir -p build/"$SLUG"
GITEA_REPO="${{ vars.GITEA_REPO }}" # Copy all files, but exclude git and github folders (optional)
TOKEN="${{ secrets.RELEASE_TOKEN }}" rsync -a --exclude='.git' --exclude='.github' ./ build/"$SLUG"/
# If you want to exclude node_modules, vendor, etc., add more --exclude's
# Strip protocol for the oauth2 URL # -----------------------------------------------------------------
SERVER_HOST="${GITEA_SERVER#https://}" # 3. Build the zip
SERVER_HOST="${SERVER_HOST#http://}" # -----------------------------------------------------------------
git remote set-url origin "https://oauth2:${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
# ------------------------------------------------------------
- name: Build plugin zip - name: Build plugin zip
if: steps.check.outputs.should_release == 'true'
run: | run: |
SLUG="${{ steps.meta.outputs.slug }}"
mkdir -p build/"${SLUG}"
rsync -a \
--exclude='.git' \
--exclude='.gitea' \
--exclude='.github' \
--exclude='node_modules' \
--exclude='build' \
--exclude='*.zip' \
./ build/"${SLUG}"/
cd build cd build
zip -r "../${SLUG}-${{ steps.meta.outputs.version }}.zip" "${SLUG}" zip -r "../$FILENAME" "$SLUG"
cd ..
# ------------------------------------------------------------ # -----------------------------------------------------------------
# 7. Install tea CLI # 4. Install tea CLI
# ------------------------------------------------------------ # -----------------------------------------------------------------
- name: Install tea CLI - name: Install tea CLI
if: steps.check.outputs.should_release == 'true'
run: | run: |
TEA_VERSION="0.14.2" curl -L https://dl.gitea.io/tea/main/tea-main-linux-amd64 -o tea
curl -fL -o /usr/local/bin/tea \ chmod +x tea
"https://gitea.com/gitea/tea/releases/download/v${TEA_VERSION}/tea-${TEA_VERSION}-linux-amd64" sudo mv tea /usr/local/bin/
chmod +x /usr/local/bin/tea
tea --version
# ------------------------------------------------------------ # -----------------------------------------------------------------
# 8. Create Gitea Release # 5. Configure tea (using your existing variables)
# ------------------------------------------------------------ # -----------------------------------------------------------------
- name: Create Gitea Release (tea CLI) - name: Configure tea
if: steps.check.outputs.should_release == 'true'
run: | run: |
ZIP="${{ steps.meta.outputs.slug }}-${{ steps.meta.outputs.version }}.zip"
if [ ! -f "$ZIP" ]; then
echo "::error::Zip file $ZIP not found!" >&2
exit 1
fi
tea login add \ tea login add \
--name ci \ --name gitea \
--url "${{ vars.GITEA_SERVER_URL }}" \ --url "${{ vars.SERVER_URL }}" \
--token "${{ secrets.RELEASE_TOKEN }}" --token "${{ secrets.OC3_EXTENSION_RELEASE_TOKEN }}"
tea release create \ # -----------------------------------------------------------------
# 6. Create/force-update release
# -----------------------------------------------------------------
- name: Create release
run: |
TAG="v${VERSION}"
tea release create "$TAG" \
--title "${SLUG}_${VERSION}" \
--asset "${FILENAME}" \
--repo "${{ vars.GITEA_REPO }}" \ --repo "${{ vars.GITEA_REPO }}" \
--tag "${{ steps.check.outputs.tag }}" \ --force # <-- overwrites if tag exists
--title "${{ steps.meta.outputs.name }} ${{ steps.meta.outputs.version }}" \
--asset "${ZIP}"