Update build_joomla_zip.yml
This commit is contained in:
323
.github/workflows/build_joomla_zip.yml
vendored
323
.github/workflows/build_joomla_zip.yml
vendored
@@ -27,6 +27,7 @@
|
|||||||
# BRIEF: Build a Joomla ZIP from /src and optionally attach it to a GitHub Release.
|
# BRIEF: Build a Joomla ZIP from /src and optionally attach it to a GitHub Release.
|
||||||
# NOTE: Zips the contents of /src (not the folder) to avoid nested ZIP structures.
|
# NOTE: Zips the contents of /src (not the folder) to avoid nested ZIP structures.
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
#
|
||||||
# Script details
|
# Script details
|
||||||
# - Builds a ZIP artifact from the repository /src folder.
|
# - Builds a ZIP artifact from the repository /src folder.
|
||||||
# - Runs automatically when a GitHub Release is created.
|
# - Runs automatically when a GitHub Release is created.
|
||||||
@@ -36,194 +37,194 @@
|
|||||||
|
|
||||||
name: Build Joomla ZIP from src
|
name: Build Joomla ZIP from src
|
||||||
|
|
||||||
on:
|
"on":
|
||||||
release:
|
release:
|
||||||
types: [created]
|
types: [created]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
attach_to_release:
|
attach_to_release:
|
||||||
description: "Attach the generated ZIP to a GitHub Release"
|
description: "Attach the generated ZIP to a GitHub Release"
|
||||||
required: false
|
required: false
|
||||||
default: "false"
|
default: "false"
|
||||||
type: choice
|
type: choice
|
||||||
options:
|
options:
|
||||||
- "false"
|
- "false"
|
||||||
- "true"
|
- "true"
|
||||||
release_tag:
|
release_tag:
|
||||||
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:
|
zip_name:
|
||||||
description: "ZIP base name without extension (defaults to repository name)"
|
description: "ZIP base name without extension (defaults to repository name)"
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
zip_suffix:
|
zip_suffix:
|
||||||
description: "Optional suffix appended after version (example rc1, beta, build.5)"
|
description: "Optional suffix appended after version (example rc1, beta, build.5)"
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
prerelease:
|
prerelease:
|
||||||
description: "Mark the uploaded asset as prerelease when attaching to a Release"
|
description: "Mark the uploaded asset as prerelease when attaching to a Release"
|
||||||
required: false
|
required: false
|
||||||
default: "false"
|
default: "false"
|
||||||
type: choice
|
type: choice
|
||||||
options:
|
options:
|
||||||
- "false"
|
- "false"
|
||||||
- "true"
|
- "true"
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-zip:
|
build-zip:
|
||||||
name: Build ZIP
|
name: Build ZIP
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Validate src folder exists
|
- name: Validate src folder exists
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
if [ ! -d "src" ]; then
|
if [ ! -d "src" ]; then
|
||||||
echo "ERROR: Required folder 'src' not found at repository root." >&2
|
echo "ERROR: Required folder 'src' not found at repository root." >&2
|
||||||
echo "Expected: ./src" >&2
|
echo "Expected: ./src" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Resolve build parameters
|
- name: Resolve build parameters
|
||||||
id: params
|
id: params
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
||||||
|
|
||||||
ZIP_BASE_INPUT="${{ github.event.inputs.zip_name }}"
|
ZIP_BASE_INPUT="${{ github.event.inputs.zip_name }}"
|
||||||
if [ -n "${ZIP_BASE_INPUT}" ]; then
|
if [ -n "${ZIP_BASE_INPUT}" ]; then
|
||||||
ZIP_BASE="${ZIP_BASE_INPUT}"
|
ZIP_BASE="${ZIP_BASE_INPUT}"
|
||||||
else
|
else
|
||||||
ZIP_BASE="${REPO_NAME}"
|
ZIP_BASE="${REPO_NAME}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
VERSION=""
|
VERSION=""
|
||||||
SUFFIX_INPUT="${{ github.event.inputs.zip_suffix }}"
|
SUFFIX_INPUT="${{ github.event.inputs.zip_suffix }}"
|
||||||
PRERELEASE_INPUT="${{ github.event.inputs.prerelease }}"
|
PRERELEASE_INPUT="${{ github.event.inputs.prerelease }}"
|
||||||
ATTACH_INPUT="${{ github.event.inputs.attach_to_release }}"
|
ATTACH_INPUT="${{ github.event.inputs.attach_to_release }}"
|
||||||
|
|
||||||
if [ "${GITHUB_EVENT_NAME}" = "release" ]; then
|
if [ "${GITHUB_EVENT_NAME}" = "release" ]; then
|
||||||
ATTACH="true"
|
ATTACH="true"
|
||||||
TAG_NAME="${{ github.event.release.tag_name }}"
|
TAG_NAME="${{ github.event.release.tag_name }}"
|
||||||
VERSION="${TAG_NAME##*/}"
|
VERSION="${TAG_NAME##*/}"
|
||||||
PRERELEASE="${{ github.event.release.prerelease }}"
|
PRERELEASE="${{ github.event.release.prerelease }}"
|
||||||
else
|
else
|
||||||
if [ "${ATTACH_INPUT}" = "true" ]; then
|
if [ "${ATTACH_INPUT}" = "true" ]; then
|
||||||
ATTACH="true"
|
ATTACH="true"
|
||||||
else
|
else
|
||||||
ATTACH="false"
|
ATTACH="false"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TAG_INPUT="${{ github.event.inputs.release_tag }}"
|
TAG_INPUT="${{ github.event.inputs.release_tag }}"
|
||||||
if [ -n "${TAG_INPUT}" ]; then
|
if [ -n "${TAG_INPUT}" ]; then
|
||||||
TAG_NAME="${TAG_INPUT}"
|
TAG_NAME="${TAG_INPUT}"
|
||||||
VERSION="${TAG_NAME##*/}"
|
VERSION="${TAG_NAME##*/}"
|
||||||
else
|
else
|
||||||
if [ ! -f "src/templateDetails.xml" ]; then
|
if [ ! -f "src/templateDetails.xml" ]; then
|
||||||
echo "ERROR: src/templateDetails.xml not found and release_tag not provided." >&2
|
echo "ERROR: src/templateDetails.xml not found and release_tag not provided." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
VERSION=$(grep -Eo '<version>[0-9]+(\.[0-9]+)*</version>' src/templateDetails.xml | head -n1 | sed -E 's#</?version>##g')
|
VERSION=$(grep -Eo '<version>[0-9]+(\.[0-9]+)*</version>' src/templateDetails.xml | head -n1 | sed -E 's#</?version>##g')
|
||||||
if [ -z "${VERSION}" ]; then
|
if [ -z "${VERSION}" ]; then
|
||||||
echo "ERROR: Unable to extract <version> from src/templateDetails.xml." >&2
|
echo "ERROR: Unable to extract <version> from src/templateDetails.xml." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TAG_NAME="dev/${VERSION}"
|
TAG_NAME="dev/${VERSION}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${PRERELEASE_INPUT}" = "true" ]; then
|
if [ "${PRERELEASE_INPUT}" = "true" ]; then
|
||||||
PRERELEASE="true"
|
PRERELEASE="true"
|
||||||
else
|
else
|
||||||
PRERELEASE="false"
|
PRERELEASE="false"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${VERSION}" ]; then
|
if [ -n "${VERSION}" ]; then
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
echo "ERROR: VERSION could not be resolved." >&2
|
echo "ERROR: VERSION could not be resolved." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${SUFFIX_INPUT}" ]; then
|
if [ -n "${SUFFIX_INPUT}" ]; then
|
||||||
ZIP_NAME="${ZIP_BASE}-${VERSION}-${SUFFIX_INPUT}.zip"
|
ZIP_NAME="${ZIP_BASE}-${VERSION}-${SUFFIX_INPUT}.zip"
|
||||||
else
|
else
|
||||||
ZIP_NAME="${ZIP_BASE}-${VERSION}.zip"
|
ZIP_NAME="${ZIP_BASE}-${VERSION}.zip"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "zip_name=${ZIP_NAME}" >> "$GITHUB_OUTPUT"
|
echo "zip_name=${ZIP_NAME}" >> "$GITHUB_OUTPUT"
|
||||||
echo "attach=${ATTACH}" >> "$GITHUB_OUTPUT"
|
echo "attach=${ATTACH}" >> "$GITHUB_OUTPUT"
|
||||||
echo "tag_name=${TAG_NAME}" >> "$GITHUB_OUTPUT"
|
echo "tag_name=${TAG_NAME}" >> "$GITHUB_OUTPUT"
|
||||||
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
||||||
echo "prerelease=${PRERELEASE}" >> "$GITHUB_OUTPUT"
|
echo "prerelease=${PRERELEASE}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
echo "Resolved parameters:" >&2
|
echo "Resolved parameters:" >&2
|
||||||
echo "- ZIP_NAME: ${ZIP_NAME}" >&2
|
echo "- ZIP_NAME: ${ZIP_NAME}" >&2
|
||||||
echo "- ATTACH_TO_RELEASE: ${ATTACH}" >&2
|
echo "- ATTACH_TO_RELEASE: ${ATTACH}" >&2
|
||||||
echo "- TAG_NAME: ${TAG_NAME}" >&2
|
echo "- TAG_NAME: ${TAG_NAME}" >&2
|
||||||
echo "- VERSION: ${VERSION}" >&2
|
echo "- VERSION: ${VERSION}" >&2
|
||||||
echo "- PRERELEASE: ${PRERELEASE}" >&2
|
echo "- PRERELEASE: ${PRERELEASE}" >&2
|
||||||
|
|
||||||
- name: Preflight checks
|
- name: Preflight checks
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
if [ "${{ steps.params.outputs.attach }}" = "true" ] && [ -z "${{ steps.params.outputs.tag_name }}" ]; then
|
if [ "${{ steps.params.outputs.attach }}" = "true" ] && [ -z "${{ steps.params.outputs.tag_name }}" ]; then
|
||||||
echo "ERROR: tag_name is required when attach_to_release=true on workflow_dispatch." >&2
|
echo "ERROR: tag_name is required when attach_to_release=true on workflow_dispatch." >&2
|
||||||
echo "Provide 'release_tag' input, or run on a Release created event." >&2
|
echo "Provide 'release_tag' input, or run on a Release created event." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "src directory listing:" >&2
|
echo "src directory listing:" >&2
|
||||||
ls -la src >&2
|
ls -la src >&2
|
||||||
|
|
||||||
- name: Build ZIP from src contents
|
- name: Build ZIP from src contents
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
ZIP_NAME="${{ steps.params.outputs.zip_name }}"
|
ZIP_NAME="${{ steps.params.outputs.zip_name }}"
|
||||||
|
|
||||||
rm -f "${ZIP_NAME}"
|
rm -f "${ZIP_NAME}"
|
||||||
|
|
||||||
# Zip the contents of src, not the folder itself.
|
# Zip the contents of src, not the folder itself.
|
||||||
# This avoids producing a ZIP with a top-level src/ directory.
|
# This avoids producing a ZIP with a top-level src/ directory.
|
||||||
( cd src && zip -r -q "../${ZIP_NAME}" . )
|
( cd src && zip -r -q "../${ZIP_NAME}" . )
|
||||||
|
|
||||||
if [ ! -f "${ZIP_NAME}" ]; then
|
if [ ! -f "${ZIP_NAME}" ]; then
|
||||||
echo "ERROR: ZIP build failed. Output file not found: ${ZIP_NAME}" >&2
|
echo "ERROR: ZIP build failed. Output file not found: ${ZIP_NAME}" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Built ZIP:" >&2
|
echo "Built ZIP:" >&2
|
||||||
ls -la "${ZIP_NAME}" >&2
|
ls -la "${ZIP_NAME}" >&2
|
||||||
|
|
||||||
- name: Upload build artifact to workflow run
|
- name: Upload build artifact to workflow run
|
||||||
if: steps.params.outputs.attach != 'true'
|
if: steps.params.outputs.attach != 'true'
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: joomla-zip
|
name: joomla-zip
|
||||||
path: ${{ steps.params.outputs.zip_name }}
|
path: ${{ steps.params.outputs.zip_name }}
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
- name: Attach ZIP to GitHub Release
|
- name: Attach ZIP to GitHub Release
|
||||||
if: steps.params.outputs.attach == 'true'
|
if: steps.params.outputs.attach == 'true'
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ steps.params.outputs.tag_name }}
|
tag_name: ${{ steps.params.outputs.tag_name }}
|
||||||
prerelease: ${{ steps.params.outputs.prerelease == 'true' }}
|
prerelease: ${{ steps.params.outputs.prerelease == 'true' }}
|
||||||
files: ${{ steps.params.outputs.zip_name }}
|
files: ${{ steps.params.outputs.zip_name }}
|
||||||
fail_on_unmatched_files: true
|
fail_on_unmatched_files: true
|
||||||
|
|||||||
Reference in New Issue
Block a user