This file contains 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: Continuous Integration and README Update | |
# Define the events that trigger this workflow | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Setup Node.js 20 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: "20" | |
# Step 2: Checkout code from the repository | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
# Step 3: Change directory to ui-fundamentals | |
- name: Change directory to ui-fundamentals | |
run: cd ui-fundamentals && ls -la | |
# Step 4: Check for merge conflicts | |
- name: Check for merge conflicts | |
run: | | |
# Check if there are any merge conflicts | |
if git diff --quiet; then | |
echo "No merge conflicts found" | |
else | |
# Display merge conflicts and fail the workflow | |
echo "Merge conflicts found. Please resolve conflicts and try again." | |
git status | |
exit 1 | |
fi | |
# Step 5: Install project dependencies in ui-fundamentals | |
- name: Install dependencies in ui-fundamentals | |
working-directory: ui-fundamentals | |
run: npm install | |
# Step 6: Run tests in ui-fundamentals | |
- name: Run tests in ui-fundamentals | |
working-directory: ui-fundamentals | |
run: npm test | |
# Step 7: Lint code in ui-fundamentals | |
- name: Lint code in ui-fundamentals | |
working-directory: ui-fundamentals | |
run: npm run lint # Make sure your project has ESLint configured and installed as a dependency | |
# Step 8: Check commit format in ui-fundamentals | |
- name: Check commit format in ui-fundamentals | |
working-directory: ui-fundamentals | |
run: npm run commitlint # Assuming you have a script for commit message linting | |
# Step 9: Update README with download and pull request counts | |
- name: Update README with counts | |
run: | | |
DOWNLOAD_COUNT=$(curl -s "https://api.github.com/repos/ksachin7/React-practices/releases" | jq '.[] | .assets | .[] | .download_count' | jq -s add) | |
PULL_REQUEST_COUNT=$(curl -s "https://api.github.com/repos/ksachin7/React-practices/pulls?state=all" | jq 'length') | |
sed -i "s/^### Download Count:.*/### Download Count: $DOWNLOAD_COUNT/" README.md | |
sed -i "s/^### Pull Request Count:.*/### Pull Request Count: $PULL_REQUEST_COUNT/" README.md | |
git add README.md | |
git commit -m "Update README with latest download and pull request counts" || echo "No changes to commit" | |
git push | |
deploy_to_vercel: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
# Checkout code including submodules | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
submodules: recursive | |
# Change directory to ui-fundamentals | |
- name: Change directory to ui-fundamentals | |
run: cd ui-fundamentals | |
# Deploy ui-fundamentals to Vercel | |
- name: Deploy to Vercel | |
uses: amondnet/vercel-action@v2 | |
with: | |
vercel-token: ${{ secrets.VERCEL_TOKEN }} | |
vercel-project-name: ui-fundamentals |