deploy-build #13
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 and extract build | |
| 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 htmlplayer-build.zip "${ARTIFACT_URL}" | |
| echo "Unzipping outer artifact..." | |
| mkdir -p temp-build | |
| unzip -q htmlplayer-build.zip -d temp-build | |
| echo "Unzipping inner build zip..." | |
| unzip -q temp-build/htmlplayer-build.zip -d temp-build | |
| # Optional: keep workspace clean | |
| rm -f temp-build/htmlplayer-build.zip htmlplayer-build.zip | |
| echo "Resulting structure under temp-build:" | |
| find temp-build -maxdepth 3 -type d -print | |
| - name: Replace subfolder with Build/dist contents | |
| run: | | |
| set -euo pipefail | |
| SUBFOLDER="${{ github.event.client_payload.subfolder }}" | |
| echo "Target subfolder: ${SUBFOLDER}" | |
| # Ensure subfolder exists | |
| mkdir -p "${SUBFOLDER}" | |
| echo "Before replace, contents of ${SUBFOLDER}:" | |
| ls -la "${SUBFOLDER}" || true | |
| # Clear subfolder (including hidden files, but keep the dir itself) | |
| # The printf + xargs pattern avoids errors when the glob is empty. | |
| if [ -d "${SUBFOLDER}" ]; then | |
| echo "Clearing existing contents of ${SUBFOLDER}" | |
| find "${SUBFOLDER}" -mindepth 1 -maxdepth 1 -print0 | xargs -0 rm -rf -- | |
| fi | |
| # Sanity check: ensure source path exists | |
| 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 5 -print | |
| exit 1 | |
| fi | |
| echo "Copying new build contents from temp-build/Build/dist into ${SUBFOLDER}" | |
| # Move contents of dist/* directly into SUBFOLDER | |
| shopt -s dotglob nullglob | |
| mv temp-build/Build/dist/* "${SUBFOLDER}/" | |
| echo "After replace, contents of ${SUBFOLDER}:" | |
| ls -la "${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 "${SUBFOLDER}" | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| echo "Changes detected; committing..." | |
| git status | |
| git commit -m "Deploy ${SOURCE_REPO} build to ${SUBFOLDER}" | |
| git push origin main | |
| fi |