Have you heard about CI/CD but don’t know where to begin?
Maybe you saw the word “pipeline” and thought it was only for DevOps experts?
Don’t worry! With GitHub Actions, you can automate tests and deployments directly from your GitHub repository. And the best part? It’s easy to start!
What is CI/CD ?
CI (Continuous Integration): Every time you push code, tests run automatically.
CD (Continuous Delivery): When the code is approved, it is automatically deployed to production or staging.
This saves time and helps you avoid manual mistakes in your deployments
How to start using GitHub Actions?
- Create a folder named
.github/workflows
in your project - Add a file called
ci.yml
with the content below:
name: CI Pipeline on: push: branches: [main] # Runs on push to the main branch jobs: test: runs-on: ubuntu-latest # Linux environment steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: '20' - name: Install dependencies run: npm install - name: Run tests run: npm run test
Explaning each part
-
on.push.branches
: When the workflow runs (in this case, on push tomain
) -
runs-on
: Which OS to use (Ubuntu, Windows, etc.) -
steps
: Each action in you pipeline:
- checkout: Clones you repo
- setup-node: installs Node.js
- npm install: Installs packages
- npm run test: Runs your tests
What happens Next?
Every time you git push
to the main branch
, GitHub will:
Run your tests
Show the result in the Actions tab
Notify you if something fails!
What about deployment?
After your tests work, you can add deployment steps
Example 1: Deploy to Laravel Forge
- name: Deploy to Laravel Forge run: curl -X POST ${{ secrets.FORGE_DEPLOY_HOOK }}
In forge, enable the deploy hook and save the URL in GitHub secrets as FORGE_DEPLOY_HOOK
.
Example 2: Deploy to Vercel
- name: Deploy to Vercel run: npx vercel --prod --token=$VERCEL_TOKEN env: VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
Generate a personal token at Vercel and save it in GitHub secrets as VERCEL_TOKEN
Full pipeline (tests + deploy to Forge):
name: CI + Deploy on: push: branches: [main] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Node uses: actions/setup-node@v4 with: node-version: '20' - run: npm install - run: npm run test - name: Deploy to Forge run: curl -X POST ${{ secrets.FORGE_DEPLOY_HOOK }}
Final Tip
Start Small:
- First, configure your tests
- Then add your deploy steps
- Later, include security checks, build, lint, etc.
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.