This guide explains how to use GitHub Actions for testing and deployment of this project.
-
Push Your Code to GitHub
- If you haven't already, create a GitHub repository
- Push your code to the repository
-
GitHub Actions Configuration
- The
.github/workflows/ci.ymlfile is already configured in your project - It sets up a workflow with install, lint, test, build, and deploy jobs
- The
The CI/CD workflow includes the following jobs:
- Install: Installs all dependencies and caches node modules
- Lint: Runs ESLint to check code quality
- Test: Runs Jest tests
- Build: Builds the Next.js application (only on push to main or staging)
- Deploy: Deploys to staging or production environments based on branch
For sensitive information, add GitHub Secrets:
- Go to your GitHub repository
- Click Settings > Secrets and variables > Actions
- Click "New repository secret"
- Add secrets like:
NEXT_PUBLIC_API_URL- Database credentials
- Deployment tokens
Before pushing to GitHub, you can run tests locally:
# Install dependencies
npm install
# Run tests
npm test
# Run linting
npm run lintThe workflow is configured for the following branches:
- main: Production branch, automatic testing, building, and manual deployment
- staging: Staging environment, automatic testing, building, and deployment
- develop: Development branch, automatic testing only
- Feature branches should be created from and merged into develop
You can modify the .github/workflows/ci.yml file to:
- Add more test jobs
- Configure different deployment targets
- Add custom steps or actions
The workflow is set up with placeholder deployment steps. To implement actual deployments:
- Uncomment and configure the deployment actions in the workflow file
- Add any required environment variables or secrets
- Set up your deployment environments in GitHub (Settings > Environments)
To monitor your workflows:
- Go to your GitHub repository
- Click Actions tab
- You'll see all workflow runs with their status
- Click on any run to see detailed logs and troubleshoot issues