Skip to content

Updated Deploy workflow #43

Updated Deploy workflow

Updated Deploy workflow #43

Workflow file for this run

name: Deploy to GitHub Pages
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code from the repository
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Set up Node.js environment
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
# Step 3: Install dependencies
- name: Install dependencies
run: npm install
# Step 4: Set the GitHub API Token as an environment variable for React build
- name: Set GitHub API Token
run: echo "REACT_APP_STATS_API_TOKEN=${{ secrets.STATS_API_TOKEN }}" >> $GITHUB_ENV
# Step 5: Build the React application
- name: Build the project
run: npm run build
# Step 6: Backup .github/workflows directory
- name: Backup Workflows Directory
run: |
mkdir -p backup
cp -r .github/workflows backup/
# Step 7: Checkout gh-pages branch
- name: Checkout gh-pages branch
run: |
git fetch
git checkout gh-pages
# Step 8: Copy build files to the gh-pages branch
- name: Copy Build Files
run: |
rsync -av --delete ./build/ ./ # Copy build files into root directory
# Step 9: Restore .github/workflows directory
- name: Restore Workflows Directory
run: |
cp -r backup/workflows .github/
# Step 10: Commit and Push changes to gh-pages branch
- name: Commit changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Update GitHub Pages with new build and restore workflows [skip ci]" || echo "No changes to commit"
git push origin gh-pages