Once upon a time there was a Denosaur...
Welcome gentl-octocats, today I wanted to create a Github Action to use IFTTT Webhooks and i know that all i need will be a simple curl in any Linux container, but, I'm a developer, and i like to try new thinks. And at the moment of the writing what is the hottest news in the Javascript environment?
You guess right! Deno.
So let's start building a github action with a Deno runner.
The image of the Denosaur
First of all we need an image with Deno, and after a simple research i have found hayd/alpine-deno:1.1.0.
So let's start writing the Dockerfile
FROM hayd/alpine-deno:1.1.0
WORKDIR /app
# Prefer not to run as root.
USER deno
# These steps will be re-run upon each file change in your working directory:
ADD . .
# Compile the main app so that it doesn't need to be compiled each startup/entry.
RUN deno cache main.ts
CMD ["run", "--allow-net", "--allow-env", "/app/main.ts"]
Using the Denosaur
The actions it's a simple ts file how will fetch a request to the webhook like this
const input = (key: string) => Deno.env.get(`INPUT_${key}`);
const eventName = input('EVENT');
const key = input('KEY');
const value1 = input('VALUE1');
const value2 = input('VALUE2');
const value3 = input('VALUE3');
console.log(`calling webhook for ${eventName} with`, value1, value2, value3);
await fetch(`https://maker.ifttt.com/trigger/${eventName}/with/key/${key}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ value1, value2, value3 }),
});
The Octocat Action
End last but not least the github action definition
# action.yml
name: 'IFTTT Webhook'
description: 'Call an IFTTT Webhook'
inputs:
event: # id of input
description: 'IFTTT webhook event'
required: true
key:
description: 'IFTTT webhook key'
required: true
value1:
description: 'IFTTT webhook optional parameter'
required: false
value2:
description: 'IFTTT webhook optional parameter'
required: false
value3:
description: 'IFTTT webhook optional parameter'
required: false
runs:
using: 'docker'
image: 'Dockerfile'
End of the story
And at the end of the story, in only 5 minutes I have made ifttt-webhook-action using Deno.
alfredosalzillo / ifttt-webhook-action
IFTTT webhook action
ifttt-webhook-action
A GitHub action that triggers an IFTTT webhooks event. This is useful for example when you want to trigger a IFTTT webhook after your deployment succeeds.
Usage
See action.yml
steps:
- uses: alfredosalzillo/ifttt-webhook-action@master
with:
event: your-webhook-event
key: your-webhook-secret-key
value1: optional-value
value2: optional-value
value3: optional-value
Top comments (1)
Nice one!
(FYI I think you have the brackets the wrong way round for your links! 🙃)