deploy-build #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 artifact | |
| run: | | |
| set -euo pipefail | |
| ARTIFACT_URL="${{ github.event.client_payload.artifact_url }}" | |
| TOKEN="${{ secrets.BETA_PAT_TOKEN }}" | |
| echo "Downloading artifact from: ${ARTIFACT_URL}" | |
| curl -L -H "Authorization: token ${TOKEN}" -o outer-artifact.zip "${ARTIFACT_URL}" | |
| - name: Extract artifact(s) | |
| run: | | |
| set -euo pipefail | |
| mkdir -p temp-build | |
| echo "Unzipping outer artifact to temp-build..." | |
| unzip -q outer-artifact.zip -d temp-build | |
| # Find any zip inside temp-build (inner/packaged zip). Support any name. | |
| INNER_ZIP="$(find temp-build -maxdepth 2 -type f -name '*.zip' -print -quit || true)" | |
| if [ -n "${INNER_ZIP:-}" ]; then | |
| echo "Found inner zip: ${INNER_ZIP}" | |
| unzip -q "${INNER_ZIP}" -d temp-build | |
| rm -f "${INNER_ZIP}" | |
| else | |
| echo "No inner zip found under temp-build; maybe outer zip directly contained files." | |
| fi | |
| # Clean up the downloaded outer zip | |
| rm -f outer-artifact.zip | |
| - name: Place Build/dist contents into subfolder | |
| run: | | |
| set -euo pipefail | |
| SUBFOLDER="${{ github.event.client_payload.subfolder }}" | |
| echo "Target subfolder: ${SUBFOLDER}" | |
| # Ensure subfolder exists | |
| mkdir -p "${SUBFOLDER}" | |
| # Clear subfolder including hidden files (but keep the dir) | |
| echo "Clearing existing contents of ${SUBFOLDER}" | |
| find "${SUBFOLDER}" -mindepth 1 -maxdepth 1 -print0 | xargs -0 --no-run-if-empty rm -rf -- | |
| # Determine source dist path | |
| # Look for Build/dist under temp-build | |
| DIST_DIR="$(find temp-build -type d -path '*/Build/dist' -print -quit || true)" | |
| # If not found, also look for any directory named 'dist' | |
| if [ -z "${DIST_DIR:-}" ]; then | |
| DIST_DIR="$(find temp-build -type d -name 'dist' -print -quit || true)" | |
| fi | |
| if [ -z "${DIST_DIR:-}" ]; then | |
| echo "ERROR: could not find a 'Build/dist' or 'dist' directory under temp-build:" | |
| find temp-build -maxdepth 4 -print | |
| exit 1 | |
| fi | |
| echo "Using dist source: ${DIST_DIR}" | |
| # Move contents of dist into subfolder (preserve dotfiles) | |
| shopt -s dotglob nullglob | |
| files=( "${DIST_DIR}"/* ) | |
| if [ ${#files[@]} -gt 0 ]; then | |
| echo "Moving ${#files[@]} items from ${DIST_DIR} -> ${SUBFOLDER}" | |
| mv "${files[@]}" "${SUBFOLDER}/" | |
| else | |
| echo "Warning: ${DIST_DIR} is empty; nothing to move." | |
| fi | |
| - 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' | |
| # Stage only the subfolder (including deletions) | |
| git add -A "${SUBFOLDER}" | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| echo "Changes detected; committing..." | |
| git status --porcelain | |
| git commit -m "Deploy ${SOURCE_REPO} build to ${SUBFOLDER}" | |
| git push origin main | |
| fi |