Skip to content

deploy-build

deploy-build #31

name: Deploy Build from Source
on:
repository_dispatch:
types: [deploy-build]
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout beta repo
uses: actions/checkout@v4
with:
ref: main
- name: Download and extract build
run: |
set -euo pipefail
ARTIFACT_URL="${{ github.event.client_payload.artifact_url }}"
TOKEN="${{ secrets.BETA_PAT_TOKEN }}"
ZIP_NAME="${{ github.event.client_payload.zip_name }}"
echo "Downloading artifact:"
echo " URL: ${ARTIFACT_URL}"
echo " ZIP_NAME: ${ZIP_NAME}"
# Fallback name if for some reason zip_name is empty
OUTER_ZIP="${ZIP_NAME:-build-artifact.zip}"
curl -L -H "Authorization: token ${TOKEN}" -o "${OUTER_ZIP}" "${ARTIFACT_URL}"
echo "Unzipping outer artifact into temp-build..."
mkdir -p temp-build
unzip -q "${OUTER_ZIP}" -d temp-build
echo "Looking for inner build zip inside temp-build..."
INNER_ZIP="$(find temp-build -maxdepth 2 -type f -name '*.zip' | head -n 1 || true)"
if [ -z "${INNER_ZIP}" ]; then
echo "ERROR: No inner zip found under temp-build"
echo "Tree under temp-build:"
find temp-build -maxdepth 5 -print
exit 1
fi
echo "Found inner zip: ${INNER_ZIP}"
echo "Unzipping inner build zip..."
unzip -q "${INNER_ZIP}" -d temp-build
# clean up zips
rm -f "${OUTER_ZIP}"
rm -f "${INNER_ZIP}"
- name: Replace subfolder with Build/dist contents
run: |
set -euo pipefail
SUBFOLDER="${{ github.event.client_payload.subfolder }}"
echo "Target subfolder: ${SUBFOLDER}"
mkdir -p "${SUBFOLDER}"
# Clear subfolder (including hidden files) but keep the dir itself
if [ -d "${SUBFOLDER}" ]; then
echo "Clearing existing contents of ${SUBFOLDER}"
find "${SUBFOLDER}" -mindepth 1 -maxdepth 1 -print0 | xargs -0 rm -rf -- || true
fi
# Ensure we have Build/dist in temp-build
if [ ! -d "temp-build/Build/dist" ]; then
echo "ERROR: temp-build/Build/dist does not exist"
echo "Actual temp-build structure:"
find temp-build -maxdepth 6 -print
exit 1
fi
echo "Copying Build/dist contents into ${SUBFOLDER}"
shopt -s dotglob nullglob
mv temp-build/Build/dist/* "${SUBFOLDER}/"
- name: Commit and push
run: |
set -euo pipefail
SUBFOLDER="${{ github.event.client_payload.subfolder }}"
SOURCE_REPO="${{ github.event.client_payload.source_repo }}"
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add *
if git diff --staged --quiet; then
echo "No changes to commit"
else
echo "Changes detected; committing..."
git status
git commit -m "Deploy beta ${SUBFOLDER} build."
git push origin main
fi
generate-links:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: List folders and create JSON
run: |
# List directories, exclude .github, and create JSON array
folders=$(ls -d */ 2>/dev/null | sed 's|/$||' | grep -v '^\.github$' || true)
if [ -n "$folders" ]; then
json_array=$(echo "$folders" | jq -R . | jq -s .)
echo "$json_array" > links.json
else
echo "[]" > links.json
fi
- name: Commit and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add links.json
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Update links.json with current folders"
git push
fi