Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .github/scripts/build-wp-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ wpEnv.phpVersion = PHP_VERSION;
wpEnv.core = wpCore;

// Configure themes - Require built Hello Theme to avoid false positives
if ( fs.existsSync( './tmp/hello-theme' ) ) {
wpEnv.themes = [ './tmp/hello-theme' ];
if ( fs.existsSync( './tmp/hello-elementor' ) ) {
wpEnv.themes = [ './tmp/hello-elementor' ];
// eslint-disable-next-line no-console
console.log( '✅ Using built Hello Theme from ./tmp/hello-theme' );
console.log( '✅ Using built Hello Theme from ./tmp/hello-elementor' );
} else {
// eslint-disable-next-line no-console
console.error( 'Built Hello Theme not found at ./tmp/hello-theme' );
console.error( 'Built Hello Theme not found at ./tmp/hello-elementor' );
// eslint-disable-next-line no-console
console.error( 'This prevents false positives from using unbuild source theme' );
// eslint-disable-next-line no-console
Expand Down Expand Up @@ -167,7 +167,13 @@ if ( ELEMENTOR_VERSION ) {
console.error( `❌ Elementor directory not found at ./tmp/elementor for branch/commit: ${ ELEMENTOR_VERSION }` );
// eslint-disable-next-line no-console
console.error( 'Note: Semantic versions (e.g., 3.30.4) and latest-stable are downloaded directly from WordPress.org' );
process.exit( 1 );
// eslint-disable-next-line no-console
console.error( '🔄 Using WordPress.org latest-stable as fallback for CI stability' );

// Add fallback to WordPress.org for branches to prevent CI failures
wpEnv.plugins.push( 'https://downloads.wordpress.org/plugin/elementor.latest-stable.zip' );
// eslint-disable-next-line no-console
console.log( `⚠️ Fallback: Using WordPress.org Elementor latest-stable for ${ ELEMENTOR_VERSION }` );
}

// eslint-disable-next-line no-console
Expand Down
173 changes: 68 additions & 105 deletions .github/workflows/build-theme/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,110 +2,86 @@ name: Build Hello Theme
description: Build Hello Theme with specified version

inputs:
HELLO_THEME_VERSION:
description: 'The Hello Theme version to build (e.g. 3.4.4, main)'
PACKAGE_VERSION:
description: 'The package version to build (e.g. 3.4.4)'
required: true
BUILD_SCRIPT_PATH:
description: 'Path to build script'
required: false
default: "npm run zip"

outputs:
hello-theme-version:
description: 'The Hello Theme version that was built'
value: ${{ steps.set-version.outputs.hello-theme-version }}
hello-theme-source:
description: 'Source type used for Hello Theme (github or wordpress-org)'
value: ${{ steps.determine-source.outputs.source-type }}
default: "npm run build:prod"

runs:
using: "composite"
steps:
- name: Determine source type
id: determine-source
shell: bash
run: |
# Hello Theme builds from GitHub for workflow testing (like Hello Commerce)
# This ensures we have workflows and tests available
echo "source-type=github" >> $GITHUB_OUTPUT
echo "🔍 Using GitHub source for Hello Theme version: ${{ inputs.HELLO_THEME_VERSION }}"

- name: Checkout Hello Theme source
- name: Install npm dependencies
shell: bash
env:
HELLO_THEME_VERSION: ${{ inputs.HELLO_THEME_VERSION }}
run: |
echo "🔄 Checking out Hello Theme version: ${HELLO_THEME_VERSION}"

# Hello Theme builds from current repo like Hello Commerce
if [[ "$HELLO_THEME_VERSION" != "main" ]]; then
# Check if it's a semantic version (add 'v' prefix)
if [[ "$HELLO_THEME_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "📋 Checking out Git tag: v${HELLO_THEME_VERSION}"
git fetch --all --tags
git checkout "v${HELLO_THEME_VERSION}" || git checkout "${HELLO_THEME_VERSION}" || {
echo "⚠️ Version v${HELLO_THEME_VERSION} not found, trying without 'v' prefix"
git checkout "${HELLO_THEME_VERSION}" || {
echo "❌ Version ${HELLO_THEME_VERSION} not found, using current version"
}
}
else
# Branch name or other format
echo "📋 Checking out branch/ref: ${HELLO_THEME_VERSION}"
git fetch --all
git checkout "${HELLO_THEME_VERSION}" || {
echo "❌ Branch ${HELLO_THEME_VERSION} not found, using current version"
}
fi
else
echo "📋 Using main branch (already checked out)"
fi
export PUPPETEER_SKIP_DOWNLOAD=true
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1

# Verify we have the theme files
if [ ! -f "functions.php" ]; then
echo "❌ Hello Theme functions.php not found after checkout"
exit 1
fi

- name: Set version outputs
id: set-version
shell: bash
env:
HELLO_THEME_VERSION: ${{ inputs.HELLO_THEME_VERSION }}
run: |
# Get actual version from the checked out code
if [ -f "functions.php" ]; then
ACTUAL_VERSION=$(grep "HELLO_ELEMENTOR_VERSION" functions.php | sed "s/.*'\([^']*\)'.*/\1/" | head -1)
if [[ -n "$ACTUAL_VERSION" ]]; then
echo "✅ Detected Hello Theme version from functions.php: $ACTUAL_VERSION"
echo "hello-theme-version=$ACTUAL_VERSION" >> $GITHUB_OUTPUT
# Enhanced retry logic for npm ci with registry fallbacks and cache clearing
for i in {1..3}; do
echo "🔄 Attempt $i/3: Installing npm dependencies..."

# Try npm ci first
if npm ci --prefer-offline --no-audit --no-fund --silent; then
echo "✅ npm ci succeeded on attempt $i"
break
else
echo "⚠️ Could not detect version from functions.php, using input: $HELLO_THEME_VERSION"
echo "hello-theme-version=$HELLO_THEME_VERSION" >> $GITHUB_OUTPUT
echo "❌ npm ci failed on attempt $i"

# Check if it's a 403/registry error and clear cache
if [ $i -lt 3 ]; then
echo "🧹 Clearing npm cache to resolve potential registry issues..."
npm cache clean --force 2>/dev/null || true
echo "⏳ Waiting 30 seconds before retry..."
sleep 30
else
echo "⚠️ npm ci failed all attempts, trying advanced fallbacks..."

# Fallback 1: Clear cache and try npm install
echo "🔄 Fallback 1: Clearing cache and using npm install..."
npm cache clean --force 2>/dev/null || true
if npm install --legacy-peer-deps --no-audit --no-fund; then
echo "✅ npm install fallback succeeded"
break
fi

# Fallback 2: Use different registry
echo "🔄 Fallback 2: Trying with public registry explicitly..."
if NPM_CONFIG_REGISTRY=https://registry.npmjs.org/ npm install --legacy-peer-deps --no-audit --no-fund; then
echo "✅ Public registry fallback succeeded"
break
fi

# Fallback 3: Install without package-lock
echo "🔄 Fallback 3: Installing without package-lock.json..."
mv package-lock.json package-lock.json.backup 2>/dev/null || true
if npm install --legacy-peer-deps --no-audit --no-fund; then
echo "✅ No-lock installation succeeded"
mv package-lock.json.backup package-lock.json 2>/dev/null || true
break
fi
mv package-lock.json.backup package-lock.json 2>/dev/null || true

echo "💥 All npm installation methods failed"
exit 1
fi
fi
else
echo "⚠️ functions.php not found, using input: $HELLO_THEME_VERSION"
echo "hello-theme-version=$HELLO_THEME_VERSION" >> $GITHUB_OUTPUT
fi

- name: Install npm dependencies
shell: bash
run: |
export PUPPETEER_SKIP_DOWNLOAD=true
npm ci
done

- name: Install composer dependencies
shell: bash
run: |
composer install --no-dev --no-scripts --optimize-autoloader
composer install --no-dev --no-scripts --optimize-autoloader --quiet

- name: Set package version
shell: bash
env:
HELLO_THEME_VERSION: ${{ steps.set-version.outputs.hello-theme-version }}
PACKAGE_VERSION: ${{ inputs.PACKAGE_VERSION }}
run: |
echo "HELLO_THEME_VERSION=${HELLO_THEME_VERSION}" >> $GITHUB_ENV
echo "Building Hello Theme version: ${HELLO_THEME_VERSION}"
echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_ENV
echo "Building Hello Theme version: ${PACKAGE_VERSION}"

- name: Build Hello Theme
shell: bash
Expand All @@ -124,33 +100,20 @@ runs:
- name: Package Hello Theme
shell: bash
env:
HELLO_THEME_VERSION: ${{ steps.set-version.outputs.hello-theme-version }}
PACKAGE_VERSION: ${{ inputs.PACKAGE_VERSION }}
run: |
# Create zip file with proper naming (following Hello Theme's pattern)
# Hello Theme generates: hello-elementor.{version}.zip
if [ -f "hello-elementor.${HELLO_THEME_VERSION}.zip" ]; then
# Use existing zip from npm run zip
mv "hello-elementor.${HELLO_THEME_VERSION}.zip" "/tmp/hello-theme-builds/"
echo "✅ Found and moved existing zip: hello-elementor.${HELLO_THEME_VERSION}.zip"
elif [ -f "hello-elementor.zip" ]; then
# Rename generic zip to versioned
mv "hello-elementor.zip" "/tmp/hello-theme-builds/hello-elementor.${HELLO_THEME_VERSION}.zip"
echo "✅ Renamed hello-elementor.zip to hello-elementor.${HELLO_THEME_VERSION}.zip"
else
# Create zip manually if npm run zip didn't work as expected
echo "⚠️ No existing zip found, creating manually..."
zip -r "/tmp/hello-theme-builds/hello-elementor.${HELLO_THEME_VERSION}.zip" . \
-x "node_modules/*" "test-results/*" "tests/*" ".git/*" "*.zip" \
"playwright-report/*" ".wp-env.json.*" ".wp-env" "vendor/*"
fi
# Create zip file with proper naming (following Hello Commerce pattern)
zip -r "/tmp/hello-theme-builds/hello-elementor-${PACKAGE_VERSION}.zip" . \
-x "node_modules/*" "test-results/*" "tests/*" ".git/*" "*.zip" \
"playwright-report/*" ".wp-env.json.*" ".wp-env"

- name: Move build to workspace
shell: bash
env:
HELLO_THEME_VERSION: ${{ steps.set-version.outputs.hello-theme-version }}
PACKAGE_VERSION: ${{ inputs.PACKAGE_VERSION }}
run: |
mv "/tmp/hello-theme-builds/hello-elementor.${HELLO_THEME_VERSION}.zip" \
"./hello-elementor.${HELLO_THEME_VERSION}.zip"
mv "/tmp/hello-theme-builds/hello-elementor-${PACKAGE_VERSION}.zip" \
"./hello-elementor-${PACKAGE_VERSION}.zip"

echo "✅ Hello Theme build completed: hello-elementor.${HELLO_THEME_VERSION}.zip"
ls -la hello-elementor.*.zip
echo "✅ Hello Theme build completed: hello-elementor-${PACKAGE_VERSION}.zip"
ls -la hello-elementor-*.zip
Loading
Loading