This content originally appeared on DEV Community and was authored by Danilo Assis
Photo by Andrea De Santis on Unsplash
TL;DR
Learn how to implement the dependabot to update your dependencies automatically, a github action to merge the pull requests opened by dependabot automatically and a github action to run all of your tests inside each pull request.
Daily Issues as a Developer
Being a dev remind to technology, doing things like Hollywood movies, being the person inside the family can resolve problems from century 21.
But, being a dev is like most jobs. We resolve issues every day. We start new issues every day. And, like any other job we have daily issues that could take time from our day.
And as with any other job, daily issues are normally. Imagine having a restaurant. Every day that you come into your restaurant you must: open the windows, turn on the lights, clear the floor, wash some dishes, open the chairs, whatever, as I said: daily issues.
As a dev, every day is an opportunity to automate a daily issue inside your routine. Two of them inside of mine are so important that it is like having another person doing this job to me.
These issues are:
- running my tests inside of each pull request
- updating the dependencies of my application.
These two issues are concurrent to me as a dev inside my job.
Automating
Working with GitHub actions, these issues are easier to abstract. Let's run automatically one configuration for dependabot and two GitHub Actions.
This flow works together. So, it is important to write tests to have the dependabot working every day and these tests being responsible to identify problems with the updates.
Dependabot Config
Let's add a configuration to run daily a dependabot looking for updates from dependencies inside the application.
- inside your project on root probably it will have a folder named
.github
. If don't create manually by now. - create a new file inside of it and name as dependabot.yml
- place the code below
version: 2
updates:
- package-ecosystem: npm
directory: '/'
schedule:
interval: daily
time: '01:00'
open-pull-requests-limit: 10
Dependabot auto-merge GitHub action
Let's create the GitHub action responsible to merge automatically the pull requests opened by dependabot
inside of .github
.
- create a new folder and name as workflows
- create a new file inside of workflows and name as
auto-merge.yml
- place the code below
name: auto-merge
on:
pull_request_target:
branches:
- main
jobs:
auto-merge:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- uses: ahmadnassri/action-dependabot-auto-merge@v2.4
with:
github-token: ${{ secrets.AUTOMERGE_TOKEN }}
command: 'squash and merge'
target: minor
Test GitHub action
important: this flow is responsible to run your application tests. So, it is expected a jest environment is already configured.
let's create the GitHub action responsible to run all tests inside your application inside each pull request
- inside of workflow create a new file and name as
test.yml
- place the code below
name: tests
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "14"
- run: yarn
- run: yarn jest
The .github
folder should looks like this:
Update this changes inside a new pull request and start to see the magic happens.
use this pull request as example about the content above https://github.com/daniloab/graphql-real-world-server/pull/69
Welcome to the Automation
Now, your application already has new automation to help you with your daily issues, and with the time that you need to invest doing them manually, you can start to invest in new things to your application.
Why automate
You need to write more tests to start to spend less time writing tests. You need to update the dependencies of your application daily otherwise you will have a legacy application sooner than you think.
Feel free to call my DM on Twitter if having any doubt or insight into this flow.
- Learn How to Learn in Public.
Get into my discord to have mentorship for free about all of my content.
This content originally appeared on DEV Community and was authored by Danilo Assis
Danilo Assis | Sciencx (2022-02-10T13:29:01+00:00) Using Github actions to improve your developer experience. Retrieved from https://www.scien.cx/2022/02/10/using-github-actions-to-improve-your-developer-experience/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.