Update build_zip.yml

This commit is contained in:
2025-12-16 18:05:12 -06:00
parent 73c5c45e15
commit e47aeee188

View File

@@ -1,92 +1,65 @@
name: Build ZIP from src name: Build ZIP from folder
on: on:
release:
types: [prereleased, released]
workflow_dispatch: workflow_dispatch:
inputs: inputs:
source_dir: target_folder:
description: "Folder to zip (relative to repo root)" description: "Folder to zip (relative to repo root)"
required: false required: false
default: "src" default: "src"
zip_prefix:
description: "ZIP filename prefix (default repo name)" permissions:
required: false contents: read
default: ""
zip_name: actions:
description: "Override full ZIP filename (without .zip)" contents: read
required: false
default: ""
jobs: jobs:
zip:
build-zip: name: Package folder as ZIP
name: Build ZIP from src
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
DEFAULT_SOURCE_DIR: src
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Resolve build parameters - name: Validate target folder
id: cfg shell: bash
run: | run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.source_dir }}" ]; then set -euo pipefail
SRC_DIR="${{ github.event.inputs.source_dir }}"
else TARGET_FOLDER="${{ github.event.inputs.target_folder }}"
SRC_DIR="${DEFAULT_SOURCE_DIR}" if [[ -z "$TARGET_FOLDER" ]]; then
TARGET_FOLDER="src"
fi fi
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.zip_prefix }}" ]; then if [[ ! -d "$TARGET_FOLDER" ]]; then
PREFIX="${{ github.event.inputs.zip_prefix }}" echo "ERROR: Folder does not exist: $TARGET_FOLDER" >&2
else
PREFIX="${GITHUB_REPOSITORY##*/}"
fi
if [ "${{ github.event_name }}" = "release" ]; then
REF_NAME="${GITHUB_REF_NAME}"
else
REF_NAME="${GITHUB_SHA::7}"
fi
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.zip_name }}" ]; then
ZIP_NAME="${{ github.event.inputs.zip_name }}"
else
ZIP_NAME="${PREFIX}-${REF_NAME}"
fi
echo "src_dir=${SRC_DIR}" >> "$GITHUB_OUTPUT"
echo "zip_name=${ZIP_NAME}" >> "$GITHUB_OUTPUT"
- name: Validate source directory
run: |
if [ ! -d "${{ steps.cfg.outputs.src_dir }}" ]; then
echo "Source directory '${{ steps.cfg.outputs.src_dir }}' does not exist."
exit 1 exit 1
fi fi
- name: Prepare dist folder echo "TARGET_FOLDER=$TARGET_FOLDER" >> "$GITHUB_ENV"
run: |
mkdir -p dist
- name: Build ZIP from folder contents - name: Create ZIP archive
shell: bash
run: | run: |
cd "${{ steps.cfg.outputs.src_dir }}" set -euo pipefail
zip -r "../dist/${{ steps.cfg.outputs.zip_name }}.zip" .
- name: Upload artifact to workflow run REPO_NAME="${GITHUB_REPOSITORY##*/}"
SAFE_FOLDER_NAME="$(echo "$TARGET_FOLDER" | tr '/' '-')"
ZIP_NAME="${REPO_NAME}-${SAFE_FOLDER_NAME}.zip"
rm -f "$ZIP_NAME"
cd "$TARGET_FOLDER"
zip -r "../$ZIP_NAME" . \
-x "*.DS_Store" \
-x "__MACOSX/*"
echo "ZIP_NAME=$ZIP_NAME" >> "$GITHUB_ENV"
- name: Upload ZIP artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: ${{ steps.cfg.outputs.zip_name }} name: packaged-folder
path: dist/${{ steps.cfg.outputs.zip_name }}.zip path: ${{ env.ZIP_NAME }}
- name: Attach ZIP to GitHub Release
if: github.event_name == 'release'
uses: softprops/action-gh-release@v2
with:
files: dist/${{ steps.cfg.outputs.zip_name }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}