DEV Community

Kevan Y
Kevan Y

Posted on

Lab 9 - GitHub Actions Workflow

Intro

For my ninth lab, I have to set up GitHub Action for my text ssg project. Then pick another student that has GitHub Actions setup and create a PR to his repo.
In my previous I had a bit of experience with GitHub Action, I had a chance to set up with my mentor a GitHub Action to enable e2e testing with Cypress on the new build application when a PR is created, to have continuous integration.

Setup GitHub Action

First of all, I create a folder called .github/workflows, this folder contains the file for setup for GitHub Action.

I created a file called ci_workflow.yml and put

name: CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [16.x]

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
    - name: npm install and test
      run: |
        npm install
        npm run test-silent
Enter fullscreen mode Exit fullscreen mode

To make it simple, this file means, on push to main or create PR to be pushed to main will run this workflow.
The job of this workflow is to run a node-version 16.x on a ubuntu-latest system, and install all my application dependencies and run a test.
If test fails it will return -1, if pass it will return 0.
Image description

Add more test cases to another student repo

I pick Andre repo, I created an issue stating, to separate generate HTML into a function, then add test case for that function.
After finishing my fix. I created a PR, I see that the workflow Andre setup is working correctly.
Image description

Conclusion

GitHub action is a powerful tool, it enables developers to shift some manual work into automation. Yet I still have a lot to learn of GitHub Actions.

Top comments (0)