You've already forked wc-licensed-product
Rewrite workflow to match working reference implementations
All checks were successful
Create Release Package / build-release (push) Successful in 57s
All checks were successful
Create Release Package / build-release (push) Successful in 57s
Simplified workflow based on wp-fedistream and wc-tier-and-package-prices which have working CI/CD pipelines with same project structure. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,11 +9,10 @@ jobs:
|
|||||||
build-release:
|
build-release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code with submodules
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
@@ -22,25 +21,23 @@ jobs:
|
|||||||
extensions: mbstring, xml, zip, intl, gettext
|
extensions: mbstring, xml, zip, intl, gettext
|
||||||
tools: composer:v2
|
tools: composer:v2
|
||||||
|
|
||||||
- name: Extract version from tag
|
- name: Get version from tag
|
||||||
id: version
|
id: version
|
||||||
run: |
|
run: |
|
||||||
VERSION=${GITHUB_REF#refs/tags/v}
|
VERSION=${GITHUB_REF_NAME#v}
|
||||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||||
echo "Building version: $VERSION"
|
echo "Building version: $VERSION"
|
||||||
|
|
||||||
- name: Validate composer.json
|
- name: Validate composer.json
|
||||||
run: composer validate --no-check-lock --no-check-all
|
run: composer validate --no-check-lock --no-check-all
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install Composer dependencies (production)
|
||||||
run: composer install --no-dev --optimize-autoloader --prefer-dist
|
|
||||||
|
|
||||||
- name: Verify and fix vendor directory
|
|
||||||
run: |
|
run: |
|
||||||
echo "=== Checking vendor directory ==="
|
composer config platform.php 8.3.0
|
||||||
ls -la vendor/ || echo "vendor/ not found!"
|
composer install --no-dev --optimize-autoloader --no-interaction
|
||||||
ls -la vendor/magdev/ || echo "vendor/magdev/ not found!"
|
|
||||||
|
|
||||||
|
- name: Fix vendor symlink
|
||||||
|
run: |
|
||||||
# If client is a symlink, replace with actual files
|
# If client is a symlink, replace with actual files
|
||||||
if [ -L "vendor/magdev/wc-licensed-product-client" ]; then
|
if [ -L "vendor/magdev/wc-licensed-product-client" ]; then
|
||||||
echo "Found symlink, replacing with actual files..."
|
echo "Found symlink, replacing with actual files..."
|
||||||
@@ -48,28 +45,27 @@ jobs:
|
|||||||
rm vendor/magdev/wc-licensed-product-client
|
rm vendor/magdev/wc-licensed-product-client
|
||||||
cp -r "$TARGET" vendor/magdev/wc-licensed-product-client
|
cp -r "$TARGET" vendor/magdev/wc-licensed-product-client
|
||||||
fi
|
fi
|
||||||
|
ls -la vendor/magdev/
|
||||||
|
|
||||||
ls -la vendor/magdev/wc-licensed-product-client/ || echo "Client directory not found!"
|
- name: Install gettext
|
||||||
|
run: apt-get update && apt-get install -y gettext
|
||||||
- name: Install gettext for translation compilation
|
|
||||||
run: sudo apt-get update && sudo apt-get install -y gettext
|
|
||||||
|
|
||||||
- name: Compile translations
|
- name: Compile translations
|
||||||
run: |
|
run: |
|
||||||
for po in languages/*.po; do
|
for po in languages/*.po; do
|
||||||
if [ -f "$po" ]; then
|
if [ -f "$po" ]; then
|
||||||
mo="${po%.po}.mo"
|
mo="${po%.po}.mo"
|
||||||
echo "Compiling $po -> $mo"
|
echo "Compiling $po to $mo"
|
||||||
msgfmt -o "$mo" "$po"
|
msgfmt -o "$mo" "$po"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: Verify version in plugin header
|
- name: Verify plugin version matches tag
|
||||||
run: |
|
run: |
|
||||||
PLUGIN_VERSION=$(grep -oP 'Version:\s*\K[0-9]+\.[0-9]+\.[0-9]+' wc-licensed-product.php | head -1)
|
PLUGIN_VERSION=$(grep -oP "Version:\s*\K[0-9]+\.[0-9]+\.[0-9]+" wc-licensed-product.php | head -1)
|
||||||
TAG_VERSION=${{ steps.version.outputs.version }}
|
TAG_VERSION=${{ steps.version.outputs.version }}
|
||||||
if [ "$PLUGIN_VERSION" != "$TAG_VERSION" ]; then
|
if [ "$PLUGIN_VERSION" != "$TAG_VERSION" ]; then
|
||||||
echo "Version mismatch! Plugin header: $PLUGIN_VERSION, Tag: $TAG_VERSION"
|
echo "Error: Plugin version ($PLUGIN_VERSION) does not match tag version ($TAG_VERSION)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Version verified: $PLUGIN_VERSION"
|
echo "Version verified: $PLUGIN_VERSION"
|
||||||
@@ -79,165 +75,140 @@ jobs:
|
|||||||
|
|
||||||
- name: Build release package
|
- name: Build release package
|
||||||
run: |
|
run: |
|
||||||
PLUGIN_NAME="wc-licensed-product"
|
|
||||||
VERSION=${{ steps.version.outputs.version }}
|
VERSION=${{ steps.version.outputs.version }}
|
||||||
|
PLUGIN_NAME="wc-licensed-product"
|
||||||
RELEASE_FILE="releases/${PLUGIN_NAME}-${VERSION}.zip"
|
RELEASE_FILE="releases/${PLUGIN_NAME}-${VERSION}.zip"
|
||||||
|
|
||||||
# Debug: show current directory structure
|
|
||||||
echo "Current directory: $(pwd)"
|
|
||||||
echo "Contents:"
|
|
||||||
ls -la
|
|
||||||
echo "Vendor contents:"
|
|
||||||
ls -la vendor/
|
|
||||||
|
|
||||||
# Create temp directory structure for proper zip packaging
|
|
||||||
cd ..
|
cd ..
|
||||||
mkdir -p "${PLUGIN_NAME}-build"
|
|
||||||
cp -r "${GITHUB_WORKSPACE}" "${PLUGIN_NAME}-build/${PLUGIN_NAME}"
|
|
||||||
|
|
||||||
# Create zip from temp directory
|
|
||||||
cd "${PLUGIN_NAME}-build"
|
|
||||||
zip -r "${PLUGIN_NAME}/${RELEASE_FILE}" "${PLUGIN_NAME}" \
|
zip -r "${PLUGIN_NAME}/${RELEASE_FILE}" "${PLUGIN_NAME}" \
|
||||||
-x "${PLUGIN_NAME}/.git/*" \
|
-x "${PLUGIN_NAME}/.git/*" \
|
||||||
-x "${PLUGIN_NAME}/.gitea/*" \
|
-x "${PLUGIN_NAME}/.gitea/*" \
|
||||||
-x "${PLUGIN_NAME}/.gitmodules" \
|
-x "${PLUGIN_NAME}/.github/*" \
|
||||||
-x "${PLUGIN_NAME}/.gitignore" \
|
-x "${PLUGIN_NAME}/.vscode/*" \
|
||||||
-x "${PLUGIN_NAME}/lib/*" \
|
-x "${PLUGIN_NAME}/.claude/*" \
|
||||||
-x "${PLUGIN_NAME}/releases/*" \
|
|
||||||
-x "${PLUGIN_NAME}/vendor/magdev/wc-licensed-product-client/.git" \
|
|
||||||
-x "${PLUGIN_NAME}/vendor/magdev/wc-licensed-product-client/.git/*" \
|
|
||||||
-x "${PLUGIN_NAME}/vendor/*/.git/*" \
|
|
||||||
-x "${PLUGIN_NAME}/tests/*" \
|
|
||||||
-x "${PLUGIN_NAME}/CLAUDE.md" \
|
-x "${PLUGIN_NAME}/CLAUDE.md" \
|
||||||
-x "${PLUGIN_NAME}/*.po~" \
|
|
||||||
-x "${PLUGIN_NAME}/wp-core" \
|
-x "${PLUGIN_NAME}/wp-core" \
|
||||||
|
-x "${PLUGIN_NAME}/wp-core/*" \
|
||||||
-x "${PLUGIN_NAME}/wp-plugins" \
|
-x "${PLUGIN_NAME}/wp-plugins" \
|
||||||
-x "${PLUGIN_NAME}/composer.lock"
|
-x "${PLUGIN_NAME}/wp-plugins/*" \
|
||||||
|
-x "${PLUGIN_NAME}/releases/*" \
|
||||||
|
-x "${PLUGIN_NAME}/composer.lock" \
|
||||||
|
-x "${PLUGIN_NAME}/*.log" \
|
||||||
|
-x "${PLUGIN_NAME}/.gitignore" \
|
||||||
|
-x "${PLUGIN_NAME}/.gitmodules" \
|
||||||
|
-x "${PLUGIN_NAME}/.editorconfig" \
|
||||||
|
-x "${PLUGIN_NAME}/phpcs.xml*" \
|
||||||
|
-x "${PLUGIN_NAME}/phpunit.xml*" \
|
||||||
|
-x "${PLUGIN_NAME}/tests/*" \
|
||||||
|
-x "${PLUGIN_NAME}/*.po~" \
|
||||||
|
-x "${PLUGIN_NAME}/*.bak" \
|
||||||
|
-x "${PLUGIN_NAME}/lib/*" \
|
||||||
|
-x "${PLUGIN_NAME}/lib/*/.git/*" \
|
||||||
|
-x "${PLUGIN_NAME}/vendor/magdev/*/.git/*" \
|
||||||
|
-x "${PLUGIN_NAME}/vendor/magdev/*/CLAUDE.md" \
|
||||||
|
-x "*.DS_Store"
|
||||||
|
|
||||||
# Move zip back to original releases directory
|
cd "${PLUGIN_NAME}"
|
||||||
mv "${PLUGIN_NAME}/${RELEASE_FILE}" "${GITHUB_WORKSPACE}/${RELEASE_FILE}"
|
echo "Created: ${RELEASE_FILE}"
|
||||||
cd "${GITHUB_WORKSPACE}"
|
ls -lh "${RELEASE_FILE}"
|
||||||
|
|
||||||
echo "Created release package: ${RELEASE_FILE}"
|
- name: Generate checksums
|
||||||
|
|
||||||
- name: Generate SHA256 checksum
|
|
||||||
run: |
|
run: |
|
||||||
VERSION=${{ steps.version.outputs.version }}
|
VERSION=${{ steps.version.outputs.version }}
|
||||||
|
PLUGIN_NAME="wc-licensed-product"
|
||||||
|
|
||||||
cd releases
|
cd releases
|
||||||
sha256sum "wc-licensed-product-${VERSION}.zip" > "wc-licensed-product-${VERSION}.zip.sha256"
|
sha256sum "${PLUGIN_NAME}-${VERSION}.zip" > "${PLUGIN_NAME}-${VERSION}.zip.sha256"
|
||||||
cat "wc-licensed-product-${VERSION}.zip.sha256"
|
echo "SHA256:"
|
||||||
|
cat "${PLUGIN_NAME}-${VERSION}.zip.sha256"
|
||||||
|
|
||||||
- name: Verify package structure
|
- name: Verify package structure
|
||||||
run: |
|
run: |
|
||||||
|
set +o pipefail
|
||||||
VERSION=${{ steps.version.outputs.version }}
|
VERSION=${{ steps.version.outputs.version }}
|
||||||
echo "=== Package contents ==="
|
PLUGIN_NAME="wc-licensed-product"
|
||||||
unzip -l "releases/wc-licensed-product-${VERSION}.zip" | head -50 || true
|
|
||||||
|
|
||||||
echo ""
|
echo "Package contents (first 50 entries):"
|
||||||
echo "=== Verification checks ==="
|
unzip -l "releases/${PLUGIN_NAME}-${VERSION}.zip" | head -50 || true
|
||||||
|
|
||||||
# Check main plugin file exists
|
# Verify main plugin file exists
|
||||||
if unzip -l "releases/wc-licensed-product-${VERSION}.zip" | grep -q "wc-licensed-product/wc-licensed-product.php"; then
|
if unzip -l "releases/${PLUGIN_NAME}-${VERSION}.zip" | grep -q "${PLUGIN_NAME}/${PLUGIN_NAME}.php"; then
|
||||||
echo "Main plugin file: OK"
|
echo "Main plugin file: OK"
|
||||||
else
|
else
|
||||||
echo "ERROR: Main plugin file not found!"
|
echo "ERROR: Main plugin file not found!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check vendor directory exists
|
# Verify vendor directory included
|
||||||
if unzip -l "releases/wc-licensed-product-${VERSION}.zip" | grep -q "wc-licensed-product/vendor/"; then
|
if unzip -l "releases/${PLUGIN_NAME}-${VERSION}.zip" | grep -q "${PLUGIN_NAME}/vendor/"; then
|
||||||
echo "Vendor directory: OK"
|
echo "Vendor directory: OK"
|
||||||
else
|
else
|
||||||
echo "ERROR: Vendor directory not found!"
|
echo "ERROR: Vendor directory not found!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check lib directory is excluded
|
# Verify lib directory excluded
|
||||||
if unzip -l "releases/wc-licensed-product-${VERSION}.zip" | grep -q "wc-licensed-product/lib/"; then
|
if unzip -l "releases/${PLUGIN_NAME}-${VERSION}.zip" | grep -q "${PLUGIN_NAME}/lib/"; then
|
||||||
echo "ERROR: lib/ directory should be excluded!"
|
echo "WARNING: lib/ directory should be excluded"
|
||||||
exit 1
|
|
||||||
else
|
else
|
||||||
echo "lib/ excluded: OK"
|
echo "lib/ excluded: OK"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check .git directories are excluded
|
- name: Extract changelog for release notes
|
||||||
if unzip -l "releases/wc-licensed-product-${VERSION}.zip" | grep -q "\.git"; then
|
|
||||||
echo "WARNING: .git files found in package"
|
|
||||||
else
|
|
||||||
echo ".git excluded: OK"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Extract changelog for release
|
|
||||||
id: changelog
|
id: changelog
|
||||||
run: |
|
run: |
|
||||||
VERSION=${{ steps.version.outputs.version }}
|
VERSION=${{ steps.version.outputs.version }}
|
||||||
# Extract changelog section for this version
|
NOTES=$(sed -n "/^## \[${VERSION}\]/,/^## \[/p" CHANGELOG.md | sed '$ d' | tail -n +2)
|
||||||
CHANGELOG=$(awk "/^## \[?${VERSION}\]?/,/^## \[?[0-9]+\.[0-9]+\.[0-9]+\]?/" CHANGELOG.md | head -n -1)
|
if [ -z "$NOTES" ]; then
|
||||||
if [ -z "$CHANGELOG" ]; then
|
NOTES="Release version ${VERSION}"
|
||||||
CHANGELOG="Release v${VERSION}"
|
|
||||||
fi
|
fi
|
||||||
# Escape for GitHub Actions
|
echo "$NOTES" > release_notes.txt
|
||||||
echo "changelog<<EOF" >> $GITHUB_OUTPUT
|
echo "Release notes extracted"
|
||||||
echo "$CHANGELOG" >> $GITHUB_OUTPUT
|
|
||||||
echo "EOF" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Create Gitea Release
|
- name: Create Gitea Release
|
||||||
id: create_release
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.SRC_GITEA_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
VERSION=${{ steps.version.outputs.version }}
|
VERSION=${{ steps.version.outputs.version }}
|
||||||
TAG_NAME=${{ github.ref_name }}
|
TAG_NAME=${{ github.ref_name }}
|
||||||
|
PLUGIN_NAME="wc-licensed-product"
|
||||||
|
|
||||||
# Determine if prerelease
|
PRERELEASE="false"
|
||||||
if [[ "$TAG_NAME" == *"-"* ]]; then
|
if [[ "$TAG_NAME" == *-* ]]; then
|
||||||
PRERELEASE=true
|
PRERELEASE="true"
|
||||||
else
|
|
||||||
PRERELEASE=false
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Escape changelog for JSON
|
BODY=$(cat release_notes.txt)
|
||||||
CHANGELOG_ESCAPED=$(echo '${{ steps.changelog.outputs.changelog }}' | jq -Rs .)
|
|
||||||
|
|
||||||
# Create release via Gitea API
|
# Create release via Gitea API
|
||||||
RESPONSE=$(curl -s -X POST \
|
RELEASE_RESPONSE=$(curl -s -X POST \
|
||||||
-H "Authorization: token ${{ secrets.SRC_GITEA_TOKEN }}" \
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
"${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases" \
|
-d "{\"tag_name\": \"${TAG_NAME}\", \"name\": \"Release ${VERSION}\", \"body\": $(echo "$BODY" | jq -Rs .), \"draft\": false, \"prerelease\": ${PRERELEASE}}" \
|
||||||
-d "{
|
"${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases")
|
||||||
\"tag_name\": \"${TAG_NAME}\",
|
|
||||||
\"name\": \"v${VERSION}\",
|
|
||||||
\"body\": ${CHANGELOG_ESCAPED},
|
|
||||||
\"draft\": false,
|
|
||||||
\"prerelease\": ${PRERELEASE}
|
|
||||||
}")
|
|
||||||
|
|
||||||
# Extract release ID
|
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | jq -r '.id')
|
||||||
RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id')
|
|
||||||
echo "Release ID: $RELEASE_ID"
|
|
||||||
echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
if [ "$RELEASE_ID" == "null" ] || [ -z "$RELEASE_ID" ]; then
|
if [ "$RELEASE_ID" == "null" ] || [ -z "$RELEASE_ID" ]; then
|
||||||
echo "Failed to create release"
|
echo "Failed to create release:"
|
||||||
echo "$RESPONSE"
|
echo "$RELEASE_RESPONSE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Upload Release Assets
|
echo "Created release ID: $RELEASE_ID"
|
||||||
run: |
|
|
||||||
VERSION=${{ steps.version.outputs.version }}
|
|
||||||
RELEASE_ID=${{ steps.create_release.outputs.release_id }}
|
|
||||||
|
|
||||||
# Upload zip file
|
# Upload release assets
|
||||||
|
for file in "releases/${PLUGIN_NAME}-${VERSION}.zip" "releases/${PLUGIN_NAME}-${VERSION}.zip.sha256"; do
|
||||||
|
if [ -f "$file" ]; then
|
||||||
|
FILENAME=$(basename "$file")
|
||||||
|
echo "Uploading $FILENAME..."
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
-H "Authorization: token ${{ secrets.SRC_GITEA_TOKEN }}" \
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
-H "Content-Type: application/octet-stream" \
|
-H "Content-Type: application/octet-stream" \
|
||||||
"${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=wc-licensed-product-${VERSION}.zip" \
|
--data-binary "@$file" \
|
||||||
--data-binary @"releases/wc-licensed-product-${VERSION}.zip"
|
"${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${FILENAME}"
|
||||||
|
echo "Uploaded $FILENAME"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Upload checksum file
|
echo "Release created: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases/tag/${TAG_NAME}"
|
||||||
curl -s -X POST \
|
|
||||||
-H "Authorization: token ${{ secrets.SRC_GITEA_TOKEN }}" \
|
|
||||||
-H "Content-Type: application/octet-stream" \
|
|
||||||
"${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=wc-licensed-product-${VERSION}.zip.sha256" \
|
|
||||||
--data-binary @"releases/wc-licensed-product-${VERSION}.zip.sha256"
|
|
||||||
|
|
||||||
echo "Assets uploaded successfully"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user