Streamline Your App Development with Automated Testing and Deployment
What Are GitHub Actions?
GitHub Actions are instructions you create in your repository to automate certain processes in your project. They enable you to build, test, and deploy your code directly from GitHub. With GitHub Actions, you can automate workflows based on specified events, such as push, new release, issue creation, and more.
What Is Netlify?
Netlify is a static deployment platform for automating modern web projects. It offers features like continuous deployment, serverless form handling, AWS Lambda support, and more. With Netlify, you can ship your web applications in three quick steps: connect your repository, configure your build settings, and deploy your site.
Building a Vue.js App
First, we’ll scaffold our app using the Vue CLI. We won’t focus too much on how Vue.js works or how to test Vue apps. For a deeper dive, check out our tutorial on testing Vue components with Vue Testing Library.
Setting Up Unit Tests in Vue.js
We’ll use the Vue CLI to set up unit tests for our app. We’ll create a new project, select the unit tests option, and install the necessary packages. Then, we’ll write tests for our App component using Jest.
import { shallowMount } from '@vue/test-utils'
import App from './App.vue'
describe('App', () => {
it('renders correctly', () => {
const wrapper = shallowMount(App)
expect(wrapper.text()).toBe('Hello World!')
})
})
Deploying to Netlify with GitHub Actions
Next, we’ll deploy our app to Netlify using GitHub Actions. We’ll create a new site on Netlify, connect our repository, and configure our build settings. We’ll also disable automatic builds on Netlify and set up secret keys to deploy our site outside of Netlify.
Prepping for Deployment with GitHub Actions
We’ll use GitHub Actions to run our tests and deploy our app to Netlify. We’ll create two workflows: one to run on pull requests to the master branch and build, test, and merge the code to master, and another to run on commits to the master branch to build, test, and deploy our app.
How to Use GitHub Actions
We’ll create a file named autodeploy.yml
in our project’s root folder and add a job to build, test, and deploy our app. We’ll also create a file named automerge.yml
to automatically merge pull requests.
name: autodeploy
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Deploy to Netlify
uses: netlify/actions/deploy@v1
with:
token: ${{ secrets.NETLIFY_TOKEN }}
site-id: ${{ secrets.NETLIFY_SITE_ID }}
production-branch: master
name: automerge
on:
pull_request:
branches:
- master
jobs:
merge:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Merge pull request
uses: actions/merge-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Pushing Your Repository to GitHub
Finally, we’ll push our local repository to GitHub, create new labels on GitHub, and test our automerge workflow.
- Create a new repository on GitHub
- Push your local repository to GitHub using
git push -u origin master
- Create new labels on GitHub, such as “automerge” and “autodeploy”
- Test your automerge workflow by creating a new pull request
By following this tutorial, you’ll learn how to automate testing and deployment for your Vue.js app using GitHub Actions and Netlify. Say goodbye to manual testing and deployment, and hello to faster and more efficient development!