Getting Started
This tutorial walks you through creating a GitHub Actions workflow for a Node.js project. You'll learn how to run tests, lint code, and deploy automatically.
-
Prerequisites:
- GitHub account
- Existing Node.js repository
- Basic Git knowledge
-
Step 1: Create Workflow File
Navigate to your repository and create
.github/workflows/main.yml
file.name: Node.js CI/CD on: push: branches: [main] workflow_dispatch: jobs: build: runs-on: ubuntu-latest steps: - name: Checkout Code uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '18' - name: Install Dependencies run: npm install - name: Lint Code run: npm run lint - name: Run Tests run: npm test - name: Build Project run: npm run build
-
Step 2: Customize Triggers
Add the
on
section to define event triggers. In the example above, the workflow runs on pushes to themain
branch. -
Step 3: Push Changes
Commit your workflow file and push changes to GitHub.
git add .github/workflows/main.yml
git commit -m "Add GitHub Actions pipeline"
git push origin main
-
Step 4: Monitor Results
View execution status in GitHub under Actions tab. Green checkmarks mean success, red means failures.
Automated Deployment
Extend your workflow to production deployment. Add these steps to the main.yml
file:
- name: Deploy to Vercel uses: vercel/actions/deploy@v20 with: token: ${{ secrets.VERCEL_TOKEN }} project: ${{ env.VERCEL_PROJECT }}
Configure secrets in Settings > Secrets. Create API tokens for your deployment platform and store them here.