Update build_joomla_zip.yml

This commit is contained in:
2025-12-18 17:13:38 -06:00
parent 174a823be4
commit c0b06feaa4

View File

@@ -1,11 +1,47 @@
name: Build Joomla ZIP from src folder # ============================================================================
# Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
#
# This file is part of a Moko Consulting project.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# FILE INFORMATION
# DEFGROUP: MokoStandards
# INGROUP: GitHub.Workflows
# REPO: https://github.com/mokoconsulting-tech/MokoDefaults
# PATH: /.github/workflows/build_joomla_zip.yml
# VERSION: 01.00.00
# BRIEF: Build a Joomla ZIP from /src and optionally attach it to a GitHub Release.
# Script details
# - Builds a ZIP artifact from the repository /src folder.
# - Runs automatically when a GitHub Release is created.
# - Can be executed manually from the Actions menu (workflow_dispatch).
# - Optionally uploads the ZIP as a Release asset.
# - Provides CI artifacts when not attaching to a Release.
name: Build Joomla ZIP from src
on: on:
release:
types: [created]
workflow_dispatch: workflow_dispatch:
inputs: inputs:
attach_to_release: attach_to_release:
description: "Attach ZIP to a GitHub Release" description: "Attach the generated ZIP to a GitHub Release"
required: true required: false
default: "false" default: "false"
type: choice type: choice
options: options:
@@ -15,144 +51,97 @@ on:
description: "Release tag to upload to. If blank, defaults to dev/<version> using templateDetails.xml (example dev/03.02.00)" description: "Release tag to upload to. If blank, defaults to dev/<version> using templateDetails.xml (example dev/03.02.00)"
required: false required: false
default: "" default: ""
zip_name:
description: "ZIP base name without extension (defaults to repository name)"
required: false
default: ""
zip_suffix:
description: "Optional suffix appended after version (example rc1, beta, build.5)"
required: false
default: ""
prerelease:
description: "Mark the uploaded asset as prerelease when attaching to a Release"
required: false
default: "false"
type: choice
options:
- "false"
- "true"
permissions: permissions:
contents: write contents: write
jobs: jobs:
build: build-zip:
name: Package template name: Build ZIP
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
TEMPLATE_DIR: src/templates/moko-cassiopeia
SRC_LANGUAGE_DIR: src/language
SRC_MEDIA_DIR: src/media
OUT_DIR: dist
STAGE_DIR: dist/stage
ZIP_BASENAME: moko-cassiopeia
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Build staging package and ZIP - name: Validate src folder exists
id: pkg
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
if [ ! -d "src" ]; then
rm -rf "${OUT_DIR}" echo "ERROR: Required folder 'src' not found at repository root." >&2
mkdir -p "${STAGE_DIR}" echo "Expected: ./src" >&2
# Validate template source
if [ ! -f "${TEMPLATE_DIR}/templateDetails.xml" ]; then
echo "ERROR: Missing ${TEMPLATE_DIR}/templateDetails.xml"
exit 1 exit 1
fi fi
# Flatten template root into stage root - name: Resolve build parameters
cp -R "${TEMPLATE_DIR}/." "${STAGE_DIR}/" id: params
# Copy language and media to stage root if present
if [ -d "${SRC_LANGUAGE_DIR}" ]; then
cp -R "${SRC_LANGUAGE_DIR}" "${STAGE_DIR}/language"
fi
if [ -d "${SRC_MEDIA_DIR}" ]; then
cp -R "${SRC_MEDIA_DIR}" "${STAGE_DIR}/media"
fi
# Hard checks for installer-critical items
test -f "${STAGE_DIR}/templateDetails.xml"
test -f "${STAGE_DIR}/index.php"
test -f "${STAGE_DIR}/component.php"
# Read version from manifest
VERSION="$(python - << 'PY'
import xml.etree.ElementTree as ET
root = ET.parse("dist/stage/templateDetails.xml").getroot()
v = root.findtext("version") or ""
v = v.strip()
if not v:
raise SystemExit("ERROR: <version> not found in templateDetails.xml")
print(v)
PY
)"
ZIP_NAME="${ZIP_BASENAME}-${VERSION}.zip"
ZIP_PATH="${OUT_DIR}/${ZIP_NAME}"
(cd "${STAGE_DIR}" && zip -r "../${ZIP_NAME}" .)
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "zip_name=${ZIP_NAME}" >> "${GITHUB_OUTPUT}"
echo "zip_path=${ZIP_PATH}" >> "${GITHUB_OUTPUT}"
- name: Compute effective release tag
id: tag
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
INPUT_TAG="${{ github.event.inputs.release_tag }}" REPO_NAME="${GITHUB_REPOSITORY#*/}"
INPUT_TAG="$(echo "${INPUT_TAG}" | tr -d '[:space:]')"
if [ -n "${INPUT_TAG}" ]; then ZIP_BASE_INPUT="${{ github.event.inputs.zip_name }}"
EFFECTIVE_TAG="${INPUT_TAG}" if [ -n "${ZIP_BASE_INPUT}" ]; then
ZIP_BASE="${ZIP_BASE_INPUT}"
else else
EFFECTIVE_TAG="dev/${{ steps.pkg.outputs.version }}" ZIP_BASE="${REPO_NAME}"
VERSION=""
SUFFIX_INPUT="${{ github.event.inputs.zip_suffix }}"
ATTACH_INPUT="${{ github.event.inputs.attach_to_release }}"
if [ "${GITHUB_EVENT_NAME}" = "release" ]; then
ATTACH="true"
TAG_NAME="${{ github.event.release.tag_name }}"
VERSION="${TAG_NAME##*/}"
else
if [ "${ATTACH_INPUT}" = "true" ]; then
ATTACH="true"
else
ATTACH="false"
fi fi
echo "effective_tag=${EFFECTIVE_TAG}" >> "${GITHUB_OUTPUT}" TAG_INPUT="${{ github.event.inputs.release_tag }}"
if [ -n "${TAG_INPUT}" ]; then
- name: Upload workflow artifact (temporary) TAG_NAME="${TAG_INPUT}"
uses: actions/upload-artifact@v4 VERSION="${TAG_NAME##*/}"
with: else
name: ${{ steps.pkg.outputs.zip_name }} if [ ! -f "src/templateDetails.xml" ]; then
path: ${{ steps.pkg.outputs.zip_path }} echo "ERROR: src/templateDetails.xml not found and release_tag not provided." >&2
retention-days: 30
- name: Attach ZIP to GitHub Release (optional)
if: ${{ github.event.inputs.attach_to_release == 'true' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
TAG="${{ steps.tag.outputs.effective_tag }}"
ZIP="${{ steps.pkg.outputs.zip_path }}"
if [ -z "${TAG}" ]; then
echo "ERROR: release tag is empty."
exit 1 exit 1
fi fi
# Ensure the tag exists locally for release creation (optional) VERSION=$(grep -Eo '<version>[0-9]+(\.[0-9]+)*</version>' src/templateDetails.xml | head -n1 | sed -E 's#</?version>##g')
# GitHub will still allow creating a release for a tag name, but tagging is best practice. if [ -z "${VERSION}" ]; then
if ! git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null 2>&1; then echo "ERROR: Unable to extract <version> from src/templateDetails.xml." >&2
echo "INFO: Tag ${TAG} not found locally. Creating lightweight tag on current commit." exit 1
git tag "${TAG}"
git push origin "${TAG}"
fi fi
# Create release if missing, then upload asset with clobber TAG_NAME="dev/${VERSION}"
if ! gh release view "${TAG}" >/dev/null 2>&1; then fi
gh release create "${TAG}" \
--title "${TAG}" \
--notes "Automated build artifact upload." \
--draft
fi fi
# Upload asset if [ -n "${SUFFIX_INPUT}" ]; then
set +e ZIP_NAME="${ZIP_BASE}-${VERSION}-${SUFFIX_INPUT}.zip"
gh release upload "${TAG}" "${ZIP}" --clobber else
RC=$? ZIP_NAME="${ZIP_BASE}-${VERSION}.zip"
set -e
if [ $RC -ne 0 ]; then
echo "ERROR: Failed to upload asset to release ${TAG}."
echo "NOTE: GitHub may reject uploads to an immutable release. If so, create a new draft release or a new tag and retry."
exit $RC
fi fi