Setting up Your Project on Github Actions

We are going to use Github Actions to automate our serverless deployments and manage our environments. This is based on the example to deploy to circleci.

Start by going to your Github Project here.

Let's Add github actions to your project.

Add github actions to project screenshot

Now add a simple workflow to your project .

Create simple workflow screenshot

First we create the master pipeline that triggers when changes are pushed to the master branch. This will deploy the changes to production. The pipeline includes the setup of

TODO: use the deployed asset of the pull request stage instead of rebuilding it.

{% raw %}

name: Master CI/CD
on:
push:
branches:
- master
jobs:
primary:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-[email protected]
with:
node-version: 12.x
- name: install dependencies
run: yarn install
- name: lint
run: yarn lint
- name: test
run: yarn test
- name: serverless deploy
run: npx serverless deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}

{% endraw %}

Notice, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Github deploys to your AWS account on your behalf. You should create a separate IAM user with exact permissions that your project needs. You can read more about this here. But for now we'll simply use the one we've used in this tutorial. For that we will need to configure these in our Github repository secrets section in the next step.

This pipeline installs the dependencies, lints and test the code then deploys it. You'll recall that we had added a couple of tests back in the [unit tests]({% link _chapters/unit-tests-in-serverless.md %}) chapter.

However, before we run the pipeline that, we'll need to add our secret environment variables.

Further improvements could also be: