RDSHDT-1583: Public Repo Support #28
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: PR (Non-Prod) | |
| on: | |
| pull_request: | |
| permissions: | |
| id-token: write | |
| contents: write | |
| pages: write | |
| jobs: | |
| deploy-non-prod: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Prepare preview content in /tmp (read-only) | |
| run: | | |
| STAGING_DIR="/tmp/preview/non-prod" | |
| mkdir -p "$STAGING_DIR" | |
| INDEX_FILE="$STAGING_DIR/index.html" | |
| echo '<!DOCTYPE html> | |
| <html><head><meta charset="utf-8"><title>Non-Prod Scripts</title></head><body><ul>' > "$INDEX_FILE" | |
| for file in scripts/*; do | |
| if [ -f "$file" ]; then | |
| filename="${file##*/}" | |
| # Copy to staging | |
| cp "$file" "$STAGING_DIR/$filename" | |
| echo "<li><a href=\"./$filename\">$filename</a></li>" >> "$INDEX_FILE" | |
| fi | |
| done | |
| echo '</ul></body></html>' >> "$INDEX_FILE" | |
| # root-level index.html with a link to non-prod | |
| echo '<!DOCTYPE html> | |
| <html><head><meta charset="utf-8"><title>Script Index</title></head><body> | |
| <h1>Available Environments</h1> | |
| <ul> | |
| <li><a href="./non-prod/index.html">Non-Prod</a></li> | |
| </ul> | |
| </body></html>' > /tmp/preview/index.html | |
| - name: Switch to preview branch and push content | |
| run: | | |
| STAGING_DIR="/tmp/preview" | |
| git config --global user.name "github-actions" | |
| git config --global user.email "github-actions@github.com" | |
| git fetch origin non-prod-preview || true | |
| git switch non-prod-preview || git checkout -b non-prod-preview | |
| # Clean repo and copy from staging | |
| find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} + | |
| cp -r "$STAGING_DIR"/* . | |
| # Add a dummy change to force commit (timestamp) | |
| echo "Updated at $(date --utc +'%Y-%m-%dT%H:%M:%SZ')" > .last_update | |
| git add . | |
| git commit -m "🔁 Update non-prod preview for PR #${{ github.event.pull_request.number }} at $(date --utc +'%Y-%m-%dT%H:%M:%SZ')" | |
| git push origin HEAD:non-prod-preview | |