Alexa custom skill workflow using Github Actions
Tags: actionshackathon21, aws, javascript, iot
Published: 2021-12-09 05:24:05

[Instructions]: # (To submit to the GitHub Actions x DEV Hackathon 2021, please fill out all sections.)


### My Workflow
Project link: 

{% github https://github.com/sania-dsouza/devto-gha-hack2021 %}

License: MIT 

####What is this about?
> This project is the development of a custom Alexa skill using the Jovo platform that 'enables professional teams to build and run apps that work across smart speakers, the web, mobile, and more.'

* The app is a nutrition planner that takes meal inputs from the user; the app currently accepts input from the user for breakfast, lunch and dinner and provides hard-coded replies for the same right now (see picture below as seen in the Jovo debugger) 
* While not implemented in this project, the goal is to save the user's input and count the number of calories consumed by the user in a day, for health monitoring. 
* Aside from creating the app and using Github Actions for the workflow, the skill was built and deployed to the Alexa Developer Console too for registration and further testing (a screenshot is attached later in this post).
* Now for where Github Actions comes in! 
The following Actions have been used throughout the workflow: 
~ `checkout@v2` : To checkout code 
~ `setup-node@v2` : To get node installed 
~ `upload-artifact@v2` : To upload important artifacts such as the whole skill code and test reports to the workflow run 
~ `codecov-action@v2` : To report test coverage code to Codecov -- the code coverage tool 
~ `appleboy/lambda-action@master` : To deploy zipped code to AWS Lambda 

* A number of secrets have been used to run the workflow as expected such as the AWS_ACCESS_KEY_ID, AWS_REGION etc. 

* The list of jobs in the workflow are below: 
~ `build`
~ `static-code-analysis`
~ `unit-test`
~ `code-coverage`
~ `virtual-alexa-tests`
~ `deploy-skill`
~ `store-artifacts`

Codecov: 
![Codecov](https://devto-gha-hack2021-dev-serverlessdeploymentbucket-cyop4jq1fr3i.s3.amazonaws.com/Screen+Shot+2021-12-09+at+12.22.25+AM.png)

Jovo Debugger: 
![Jovo Debugger Test run] (https://devto-gha-hack2021-dev-serverlessdeploymentbucket-cyop4jq1fr3i.s3.amazonaws.com/Screen+Shot+2021-12-08+at+11.30.34+PM.png)

Github Actions run: 
![Latest Workflow run] (https://devto-gha-hack2021-dev-serverlessdeploymentbucket-cyop4jq1fr3i.s3.amazonaws.com/Screen+Shot+2021-12-08+at+11.26.55+PM.png)

### Submission Category : 
####_Interesting IoT_####

### Yaml File: 

```
name: Node.js CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    name: Build
    strategy:
      matrix:
        node-version: [14.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'
    - run: npm install

  static-code-analysis: 
    runs-on: ubuntu-latest
    name: Static code analysis 
    needs: build
    steps: 
    - name: Checkout
      uses: actions/checkout@v2
    - run: |
        npm install
        npm run eslint

  unit-test: 
    runs-on: ubuntu-latest
    name: Unit test using Jest
    needs: static-code-analysis
    steps: 
    - name: Checkout
      uses: actions/checkout@v2
    - run: |
        npm install
        npm run test
    - name: Upload results
      uses: actions/upload-artifact@v2
      with:
        name: unit-test-report
        path: reports/test-report.html

  code-coverage: 
    runs-on: ubuntu-latest
    name: Code Coverage using Codecov
    needs: unit-test
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - run: |
        npm install
        npm run codecov
    - name: Codecov push results
      uses: codecov/codecov-action@v2
      with:
          token: ${{ secrets.CODECOV_TOKEN }} 

  virtual-alexa-tests: 
    runs-on: ubuntu-latest
    name: Test on Virtual Alexa
    needs: code-coverage
    steps: 
    - name: Checkout
      uses: actions/checkout@v2
    - run: |
        npm install
        npm run test-virtual
    - name: Upload results
      uses: actions/upload-artifact@v2
      with:
        name: virtual-test-report
        path: reports/test-report.html  

  deploy-skill: 
    name: Build and deploy lambda
    needs: virtual-alexa-tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Install dependencies and zip folder contents
        run: |
          npm install && zip -r bundle.zip .
      - name: deploy zip to aws lambda
        uses: appleboy/lambda-action@master
        with:
          aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws_region: ${{ secrets.AWS_REGION }}
          function_name: 'devto-gha-hack2021-dev-handler'
          zip_file: bundle.zip

  store-artifacts:
    name: Store skill code
    if: always()
    runs-on: ubuntu-latest
    needs: deploy-skill
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Upload code
        uses: actions/upload-artifact@v2
        with:
          name: code
          path: ${{ github.workspace }}
```

### Additional Resources / Info

A screenshot of the skill in action on the Alexa Developer Console: 

![Alexa Developer skill](https://devto-gha-hack2021-dev-serverlessdeploymentbucket-cyop4jq1fr3i.s3.amazonaws.com/Screen+Shot+2021-12-09+at+12.10.04+AM.png)


Author: 
{% user saniadsouza %}