Alexa, trigger my deployment. My second submission to the #actionsHackathon for @ThePracticalDev. Run your @github action with @alexa99 voice command.03:05 AM - 19 Aug 2020
My Workflow
The "on voice" workflow uses the workflow_dispatch event to trigger the github action via the github rest api. This action is just a proof of concept for allowing you to interact with your repo by voice, and is not used anywhere except the repo I've created for this actionsHackathon submissions.
Submission Category:
Interesting IoT
Yaml File or Link to Code
Additional Resources / Info
The code used in the action is really nothing special. I've left it as the "default" action template but just changed the event trigger to "workflow_dispatch". This allows me to call the rest api targeted at the "onvoice.yml" file, which in turn would kick off any deployment defined within. The idea here is that you could tell alexa to trigger {your project name} deployment, and have it kickoff this process.
To set this up, you'll need an IFTTT account, and add the Alexa service.
Once you connect the Alexa service, setup a new trigger for "say a specific phrase".
Fill out the form with something like "my deployment" - when you interact with alexa you'll say "Alexa, trigger my deployment"
Then, for the action - search for "webhook" and set the action as "make a web request"
This is where things got a little funky. I could not get this web request action to properly authenticate to the github rest api. I tried doing basic auth in the url with https://user:pat@api.github.com... which works with curl but not via ifttt. Unfortunately the ifttt interface doesn't give you a lot of options for customizing your http request, so I ended up setting up an azure function to bypass this problem. My webhook instead calls the function app URL, which in turn calls the workflow dispatch. The curl for the call looks like this:
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/{USER}/{REPOSITORY}/actions/workflows/{WORKFLOW_ID_OR_YML_FILE_NAME}/dispatches \
-d '{"ref":"{BRANCH_NAME}"}' \
-u {USER}:{PAT}
Anything surrounded with curly braces {} would be specific to your account/repository. Learn how to make a Personal Access Token (PAT) here: Create a PAT. You can read up on the workflow_dispatch event here: Workflow Dispatch Trigger Event and the github rest api for calling the workflow dispatch event here: Workflow Dispatch Rest Api Call.
Top comments (0)