GitHub Actions + Power Automate + Teams

Anoop
6 min readAug 11, 2021

--

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

GitHub Actions can be thought of as a workflow that runs when certain event occurs in GitHub. An event might be for e.g. someone pushes code to a repository, or someone creates an issue etc. When such events occur, we can run some tasks or actions — e.g. sending an email or deploying code to a site etc.

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

Let’s start by creating a flow. Note: We use a trigger that requires a premium license. So please make sure a right license has been purchased/subscribed to. (If premium features of Flow need to be avoided then we can think of using SharePoint list item triggers.)

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

Now we need to create a workflow in GitHub which will send the required issues to the flow we created above.

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

If a quick test needs to be performed, then please we need to update the trigger in the YAML file. To do that, please comment line number 4 and 6 and write “push” instead — which means every time a file is pushed, the workflow runs.

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

In the workflow above we are using a GitHub action which gets all the required issues and posts some JSON data (in a particular format) to a Flow. If this feels a bit restricted i.e. if the JSON format needs to be updated or say if the Flow can be skipped entirely then the following options can be looked at.

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

The code for the get-issues-http-post GitHub Action is written in Typescript. The important file in the project is main.ts . This file has code to get issues of the repository where the workflow runs. This is done with the help of octokit client as shown in the code below.

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

GitHub Actions are very powerful and provide a fantastic ability to automate lot of tasks. In this post we have seen how we can communicate between GitHub and Teams via Actions and Power Automate. Communicating between GitHub and Microsoft 365 becomes much simpler as soon as Actions and Power Automate come into picture. Hope in future more and more workflows and actions get developed so that more and more tasks can be automated.

--

--

Anoop
Anoop

Written by Anoop

Microsoft MVP. M365 Developer Architect at Content+Cloud.

No responses yet