name: Build WordPress Plugin on: push: tags: - 'v*' # Trigger on version tags like v1.0.0, v2.1.3 # workflow_dispatch: # (Optional) Uncomment to allow manual trigger jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 # ------------------------------------------------ # 1. SETUP PHP (for Composer, if used) # ------------------------------------------------ - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '7.4' tools: composer # ------------------------------------------------ # 2. SETUP NODE (for NPM/Yarn, if used) # ------------------------------------------------ - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' cache: 'npm' # or 'yarn' # ------------------------------------------------ # 3. INSTALL & BUILD ASSETS (optional) # ------------------------------------------------ - name: Install Composer dependencies (production only) run: | if [ -f "composer.json" ]; then composer install --no-dev --prefer-dist --optimize-autoloader fi - name: Install NPM dependencies & build assets run: | if [ -f "package.json" ]; then npm ci fi if [ -f "package.json" ] && grep -q '"build"' package.json; then npm run build fi # ------------------------------------------------ # 4. EXTRACT PLUGIN VERSION FROM MAIN FILE # ------------------------------------------------ - name: Get plugin version and slug id: meta run: | # Find the main plugin file (the one with the WordPress header) MAIN_FILE=$(grep -l "Plugin Name:" *.php | head -n 1) if [ -z "$MAIN_FILE" ]; then echo "❌ No main plugin file (with 'Plugin Name:') found!" >&2 exit 1 fi # Extract version 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 # Use repository name as slug, or override with a custom variable SLUG="${GITHUB_REPOSITORY##*/}" echo "PLUGIN_SLUG=$SLUG" >> $GITHUB_ENV echo "PLUGIN_VERSION=$VERSION" >> $GITHUB_ENV echo "MAIN_FILE=$MAIN_FILE" >> $GITHUB_ENV echo "FILENAME=${SLUG}-${VERSION}.zip" >> $GITHUB_ENV echo "✅ Plugin: $SLUG, Version: $VERSION" # ------------------------------------------------ # 5. PREPARE PACKAGE (Exclude dev files) # ------------------------------------------------ - name: Prepare package directory run: | mkdir -p /tmp/build/${{ env.PLUGIN_SLUG }} # Rsync all files, excluding common dev/dependency folders rsync -av \ --exclude='.git' \ --exclude='.github' \ --exclude='.distignore' \ --exclude='.gitignore' \ --exclude='node_modules' \ --exclude='vendor' \ # Composer dev dependencies (we already installed --no-dev, but safe to exclude if standalone) --exclude='tests' \ --exclude='.env*' \ --exclude='*.log' \ --exclude='*.map' \ --exclude='*.lock' \ # package-lock.json / composer.lock (optional, sometimes kept) --exclude='package.json' \ # Remove if you want to keep it in production --exclude='composer.json' \ # Remove if you want to keep it --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 # NOTE: If your plugin needs composer.json/package.json in production, # remove those specific --exclude lines above. # ------------------------------------------------ # 6. CREATE ZIP ARCHIVE # ------------------------------------------------ - name: Create plugin zip run: | cd /tmp/build zip -r "$GITHUB_WORKSPACE/${{ env.FILENAME }}" ${{ env.PLUGIN_SLUG }}/ cd $GITHUB_WORKSPACE echo "✅ Created: $FILENAME" # ------------------------------------------------ # 7. UPLOAD TO GITHUB RELEASE # ------------------------------------------------ - name: Install tea CLI run: | curl -L https://dl.gitea.io/tea/0.11.0/tea-0.11.0-linux-amd64 -o tea chmod +x tea sudo mv tea /usr/local/bin/ - name: Configure tea run: | tea login add \ --name gitea \ --url "${{ vars.SERVER_URL }}" \ --token "${{ secrets.OC3_EXTENSION_RELEASE_TOKEN }}" - name: Create Gitea Release run: | 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"