Skip to content

Refactor GitHub Actions workflow for improved deployment handling #26

Refactor GitHub Actions workflow for improved deployment handling

Refactor GitHub Actions workflow for improved deployment handling #26

Workflow file for this run

name: Deploy to GitHub Pages
on:
push:
branches:
- main
- dev
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages-${{ github.ref }}"
cancel-in-progress: true
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Determine deployment path
id: deploy-path
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "path=." >> $GITHUB_OUTPUT
echo "environment=production" >> $GITHUB_OUTPUT
else
echo "path=dev" >> $GITHUB_OUTPUT
echo "environment=development" >> $GITHUB_OUTPUT
fi
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Prepare deployment directory
run: |
mkdir -p _site/${{ steps. deploy-path.outputs.path }}
if [ "${{ steps. deploy-path.outputs.path }}" == "." ]; then
cp -r * _site/ 2>/dev/null || true
cp -r .??* _site/ 2>/dev/null || true
rm -rf _site/.git _site/.github
else
cp -r * _site/${{ steps.deploy-path.outputs.path }}/ 2>/dev/null || true
rm -rf _site/${{ steps.deploy-path.outputs.path }}/.git
fi
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Comment deployment URL
run: |
if [ "${{ steps.deploy-path.outputs.environment }}" == "production" ]; then
echo "✅ Production deployed to main site"
else
echo "✅ Development deployed to /dev subdirectory"
fi