DEV Community

Moises
Moises

Posted on

My Blog Test with Actions

Context:

I wanted to create a new blog about React and NextJs, ensuring that if the tests didn't pass I wouldn't be able to make the margin. Hackathon only encouraged to start the project and studies

My Workflow

After using create-next-app, I configure eslint and add the script command in package.json with the linter and test commands

Submission Category:

DIY Deployments.

Yaml File or Link to Code

it's a simple yaml, but it helps me a lot

name: CI
# Controls when the action will run.
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  pull_request:
    types: [ opened, synchronize ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  lint:
    name: Lint
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: '14.15.0'
      ##################################
      ##################################

      # Runs a single command using the runners shell
      - name: Node Version
        run: node -v
      - name: Install de dependencias
        run: yarn install
      - name: Roda o Linter!
        run: yarn lint
  unit_tests:
    name: Unit Tests
    runs-on: ubuntu-latest # The type of runner that the job will run on
    steps: # Steps represent a sequence of tasks that will be executed as part of the job
      # [Pre Build-step]
      - uses: actions/checkout@v2 ## Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/setup-node@v1
        with:
          node-version: '14.15.0'
      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - uses: actions/cache@v2
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
      # ####################

      # Commands that will run:
      - name: Install Packages
        run: yarn --prefer-offline

      - name: Run Unit Tests
        run: yarn test
Enter fullscreen mode Exit fullscreen mode

Additional Resources / Info

After that, if you want the merger to be done, only if they pass, just go to the repository settings, then to the option branches > add rule
Once here choose the option Require status checks to pass before merging. For safety I also set the Require branches to be up to date before merging option.
And finally, just type the name of the work you want to run in my case Lint and Unit Tests.

Conclusion

It's a simple process but it has helped me a lot to get started with github actions and understand other workflows

Top comments (0)