GitHub Actions + Power Automate + Teams

In this blog post we will look at how we can integrate GitHub Actions with Power Automate and Microsoft Teams. We will look at an example in which using GitHub Actions we post all the open issues (that are marked as important) on to a Teams channel and then send a mobile notification about the same. The result would be like the image shown below:

GitHub Actions

If GitHub Actions are new to you, please have a quick look at this short video to understand what GitHub actions are and then have a look at this video by GitHub to understand more details.

In this post we will create a workflow that will run on a schedule. The action that it will perform are:

  1. Get all the issues in the repository that are marked as important
  2. Pass those issues to a Power Automate flow
  3. The flow then posts a message in a Teams channel and sends a notification

The diagram below shows the overall process.

Power Automate

You can import the flow provided here so that everything will be setup. Once imported, the flow should look as shown below (The flow uses simple steps and is self-explanatory)

There are 2 items that need to be done after importing:

  1. Edit the “Post issues in a Team channel” step in the flow to point to the required Team and channel.
  2. Save the flow so that it generates the HTTP POST URL in the first step. Please copy this URL as it will be needed later.

GitHub workflow

To do that, navigate to the GitHub repository from which you need to send weekly report of the issues. Click on “Actions” tab. GitHub will recognize project type and will show us some predefined workflows which can be used. However, we will not use a predefined one and instead start from scratch. So, click on “Set up a workflow yourself”.

This will open a YAML file with some code in it. Delete all the code and enter the following

This is a YAML file in which we do the following:

  1. Run the workflow on every Monday at 9AM
  2. While running
  • Use latest version of Ubuntu OS
  • Calls a GitHub action (anoopt/get-issues-and-call-flow) which will
  • Get all the issues that are open and have the label as ‘bug’
  • Build an object to hold all the issues and some other information
  • Post all the issues to the flow we created earlier

We need to update the following lines in the file as per our requirement:

  1. Line number 16 — At the moment this says ‘bug’ which means we get the issues that are labelled with ‘bug’. If a different label is needed, please change this accordingly.
  2. Line number 18 — Please enter the flow HTTP POST URL that was copied in the previous section.

Commit this file to save the changes.

Performing a quick test

Save that file and then click on “Actions” tab, we should the see the workflow running

Once the run is complete, make sure that the message is posted in Teams and a notification is received.

If all is ok, please revert the workflow file (YAML) to the way it was earlier i.e. removing the push trigger and uncommenting lines 4 and 6.

Other options for workflow

Writing custom script in the workflow

Instead of calling the action in the workflow, we can write our script which gets the required issues and then we build the JSON in the format we need. After that we can post that JSON to Flow. One such sample workflow can be found here.

Creating an Action using Graph API

The action used in the workflow (anoopt/get-issues-http-post) calls a Flow using the flow URL. Instead of that, we can think of creating a new Javascript action or Typescript action which uses Graph API to post a message to Teams. So, the idea would be to get all the required issues first like “anoopt/get-issues-and-call-flow” does and then post that JSON to Teams using Graph API. Once that action is built, we can use that new action in the workflow.

Creating an Action using Teams API

This option is similar to the previous one except that we use Teams API instead of Graph API.

Using Logic App

Instead of a the Power Automate flow, a logic app can be used which performs similar steps.

Using adaptive cards

The Power Automate flow can be edited and actions related to adaptive cards can be added to post to Teams.

Details of the GitHub Action

Once the issues are obtained, we extract only the required properties, form an array of the same and send it to the HTTP endpoint using node-fetch.

Summary

SharePoint developer at Content+Cloud.