DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Reactive Programming
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • Automating the Migration From JS to TS for the ZK Framework

Trending

  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Reactive Programming
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • Automating the Migration From JS to TS for the ZK Framework
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. GitHub Action for Using the ASK CLI and Bespoken Tools

GitHub Action for Using the ASK CLI and Bespoken Tools

In this article, we discuss how to implement a GitHub Action to run ASK CLI and Bespoken Commands to reuse it in your GitHub Actions Workflows.

Xavier Portilla Edo user avatar by
Xavier Portilla Edo
CORE ·
Sep. 21, 20 · Tutorial
Like (2)
Save
Tweet
Share
4.67K Views

Join the DZone community and get the full member experience.

Join For Free

It is always good practice in the world of programming to try to develop things that are reusable. So anyone can integrate what has been developed and can quickly start using it.

This is the philosophy behind a GitHub Action. Small individual and reusable tasks that we can combine to create jobs and customize our GitHub Actions workflows.

Prerequisites

Here are the technologies used in this project:

  1. Amazon Developer Account - How to create an account
  2. AWS Account - Sign up here for free
  3. ASK CLI - Install and configure ASK CLI
  4. GitHub Account - Sign up here for free
  5. Visual Studio Code

The Alexa Skills Kit Command Line Interface (ASK CLI) is a tool for us to manage our Alexa Skills and its related resources, such as AWS Lambda functions. With the ASK CLI, we have access to the Skill Management API, which allows us to manage Alexa Skills through the command line.

GitHub Actions

actions

GitHub Actions helps us to automate tasks within the software development lifecycle. GitHub Actions is event-driven, which means that we can run a series of commands after a specific event has occurred. For example, whenever someone creates a pull request for a repository, we can automatically run a pipeline on GitHub Actions.

An event automatically triggers the workflow, which contains one or more jobs. Then the jobs use steps to control the order in which the actions are executed. These actions are the commands that automate certain processes.

GitHub Action to Run ASK CLI and Bespoken Commands

Github action

An Action is an individual task that we can combine to create jobs and customize our GitHub Actions workflows. We can create our own Actions or use and customize Actions shared by the GitHub community.

We can create an Action by writing custom code that interacts with the repositories in any way we want, including integrating with GitHub APIs and any publicly available third-party APIs. For example, an Action can publish npm modules, send SMS alerts when there is an urgent problem in the pipeline, or deploy our code if it is ready for production.

To share the Actions that we have created, the repository must be public.

Actions can be run directly on a machine or in a Docker container. We have to define the inputs, outputs and environment variables of an Action.

With eveyrthing explained, let’s look at the GitHub Action configuration file found in the action.yml file.

YAML
 




x
20


 
1
  # action.yml
2
  name: 'Alexa ASK AWS CLI Action'
3
  author: 'Xavier Portilla Edo'
4
  description: 'GitHub Action using Docker image for ASK and AWS CLI '
5
  branding:
6
    icon: 'activity'  
7
    color: 'blue'
8
  inputs:
9
    command:  # id of input
10
      description: 'Command to execute'
11
      required: true
12
      default: 'ask --version'
13
  outputs:
14
    result: # id of output
15
      description: 'The result of the command'
16
  runs:
17
    using: 'docker'
18
    image: './.github/action/Dockerfile'
19
    args:
20
      - ${{ inputs.command }}


As seen in the previous file, the GitHub Action has as input a parameter called command which will be the ASK CLI or Bespoken command that we want to execute. This command will run on a specific docker container whose Dockerfile is specified in the run section of the GitHub Action. This Docker executor will be passed the command entered through the command input parameter for later execution and will return the result of the execution in the result output parameter of the GitHub Action.

This GitHub Action is based on the Docker image that we have been using throughout the series of posts about Devops and you can find here. Note that this image already has the ASK CLI, the Bespoken Tools, Python, Git, the AWS CLI, among others installed.

However, this new Docker image that GitHub Action uses extends from the original Docker image previously commented.

This second Docker image is exactly the same as the one mentioned but an entrypoint has been added to it.

This new Docker image can be found in .github/action/Dockerfile:

Dockerfile
 




x


 
1
  # Original source from https://hub.docker.com/repository/docker/xavidop/alexa-ask-aws-cli
2
  FROM xavidop/alexa-ask-aws-cli:latest
3
  LABEL maintainer="Xavier Portilla Edo <xavierportillaedo@gmail.com>"
4

           
5
  ADD --chown=node:node entrypoint.sh /home/node/entrypoint.sh
6

           
7
  RUN chmod 777 /home/node/entrypoint.sh
8

           
9
  ENTRYPOINT ["/home/node/entrypoint.sh"]


The new entrypoint that we have added to this new Dockerfile, the only thing it will do is execute the command that is passed through the input parameter of the GitHub Action called command:

Shell
 




x


 
1
  #!/bin/bash
2
  result=$($1)
3
  echo "::set-output name=result::$result"


As output, the entrypoint will return the result of the execution of the command received from the GitHub Action through the command parameter in the format required by GitHub.

This format is as follows:::set-outpt name={ID_OUTPUT_PARAMETER}::{VALUE_OUTPUT_PARAMETER}.

NOTE: It is important to add that the GitHub Action uses the latest version of ASK CLI.

Example of Use

We can use the following example:

YAML
 




x
14


 
1
  - name: Alexa ASK AWS CLI Action
2
    uses: xavidop/alexa-ask-aws-cli-docker@v1.0.6
3
    id: command
4
    with:
5
      command: 'ask --version'
6
    env: # Or as an environment variable
7
      ASK_ACCESS_TOKEN: ${{ secrets.ASK_ACCESS_TOKEN }}
8
      ASK_REFRESH_TOKEN: ${{ secrets.ASK_REFRESH_TOKEN }}
9
      ASK_VENDOR_ID: ${{ secrets.ASK_VENDOR_ID }}
10
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
11
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
12
  # Use the output from the `hello` step
13
  - name: Get the output
14
    run: echo "The result was ${{ steps.command.outputs.result }}"


NOTE: It is important to mention that to run the GitHub Action we must pass all the environment variables that the ASK CLI needs as seen in the previous example.

Using the Action in a GitHub Actions Workflow

This is an example of how GitHub Action can be integrated into a GitHub Actions workflow:

YAML
 




x
25


 
1
  on: [push]
2

           
3
  jobs:
4
    test-action:
5
      runs-on: ubuntu-latest
6
      name: Test Action
7
      steps:
8
        # To use this repository's private action,
9
        # you must check out the repository
10
        - name: Checkout
11
          uses: actions/checkout@v2
12
        - name: Test action step
13
          uses: xavidop/alexa-ask-aws-cli-docker@v1.0.6
14
          id: ask
15
          with:
16
            command: 'ask --version'
17
          env: # Or as an environment variable
18
            ASK_ACCESS_TOKEN: ${{ secrets.ASK_ACCESS_TOKEN }}
19
            ASK_REFRESH_TOKEN: ${{ secrets.ASK_REFRESH_TOKEN }}
20
            ASK_VENDOR_ID: ${{ secrets.ASK_VENDOR_ID }}
21
            AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
22
            AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23
        # Use the output from the `hello` step
24
        - name: Get the output
25
          run: echo "The result was ${{ steps.ask.outputs.result }}"


Test the GitHub Action On Every Commit

In turn, we have created a GitHub Actions workflow that its only purpose is to verify that the Action works in each new commit made to the repo. Thus we can detect that the new changes that are made will not break the current behaviour of the Action.

This workflow can be found in .github/workflows/main.yaml:

YAML
 




x
26


 
1
on: [push]
2

           
3
jobs:
4
  test-action:
5
    runs-on: ubuntu-latest
6
    name: Test Action
7
    steps:
8
      # To use this repository's private action,
9
      # you must check out the repository
10
      - name: Checkout
11
        uses: actions/checkout@v2
12
      - name: Test action step
13
        uses: ./
14
        id: ask
15
        with:
16
          command: 'ask --version'
17
        env: # Or as an environment variable
18
          ASK_ACCESS_TOKEN: ${{ secrets.ASK_ACCESS_TOKEN }}
19
          ASK_REFRESH_TOKEN: ${{ secrets.ASK_REFRESH_TOKEN }}
20
          ASK_VENDOR_ID: ${{ secrets.ASK_VENDOR_ID }}
21
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
22
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23
          SKILL_ID: ${{ secrets.SKILL_ID }}
24
      # Use the output from the `hello` step
25
      - name: Get the output
26
        run: echo "The result was ${{ steps.ask.outputs.result }}"


As you can see, in the uses property of the Test action step of the workflow, it is forced to take the Action from the repository root directory (./) Instead of taking it from the marketplace version (xavidop/alexa-ask-aws-cli-docker@v1.0.6)

Resources

  • DevOps Wikipedia - Wikipedia
  • Node.js SDK Official Documentation - Node.js SDK Official Documentation
  • Official documentation of the Alexa Skills Kit - Official documentation of the Alexa Skills Kit
  • Official GitHub Actions documentation - Official GitHub Actions documentation

Conclusion

By creating this GitHub Action we enable any developer to execute commands from the ASK CLI and Bespoken and thus to automate their Alexa Skills processes in a very simple way by creating GitHub Actions workflows.

You can find the code in my GitHub and the GitHub Action on the official GitHub Actions marketplace.

That’s it!

I hope you find it useful! If you have any doubts or questions, feel free to contact me or post a comment below.

Happy coding!

Feel free to join to the Voice Devs Community by clicking here.


Command-line interface GitHub Docker (software)

Opinions expressed by DZone contributors are their own.

Trending

  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Reactive Programming
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • Automating the Migration From JS to TS for the ZK Framework

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: