Skip to content

Created deploy.yml

Created deploy.yml #5

Workflow file for this run

name: CI/CD for Developer Community React Project
on:
push:
branches:
- main # Trigger when changes are pushed to the main branch
pull_request:
branches:
- main # Trigger on PRs to the main branch
jobs:
test:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Set up Node.js (React 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: Run tests
- name: Run tests
run: npm test -- --ci --silent --coverage
check-additions:
runs-on: ubuntu-latest
needs: test # Ensure it runs only after tests pass
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Ensure only additions
run: |
git fetch --depth=2
MODIFIED_FILES=$(git diff --name-only HEAD HEAD~1)
if git diff --cached --name-only | grep -E '\.js|\.jsx|\.css|\.html|\.md'; then
echo "Files modified, not just added!"
exit 1
else
echo "Only additions are allowed!"
fi
deploy:
runs-on: ubuntu-latest
needs: check-additions # Deploy only after the additions check
steps:
# Step 1: Checkout the code again
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Build the React project
- name: Build the project
run: npm run build # This assumes you have a build script in your package.json
# Step 3: Deploy to GitHub Pages
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build # This is the default build directory for React