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