Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Implementing ChatOps on GitHub Actions
[
{
"@type":"HttpPOST",
"name":"Distribute to App Center",
"target":"${{ steps.kvsecrets.outputs.ApprovalTargetUri }}",
"headers":[
{
"name":"x-functions-key",
"value":"${{ steps.kvsecrets.outputs.ApprovalTargetAuthKey }}"
}
],
"bodyContentType":"application/json",
"body":"{ \"event_type\": \"distribute-appcenter\", \"client_payload\": { \"action\": \"distribute\", \"artifact\": { \"version\": \"${{ steps.buildnumber.outputs.build_number }}\", \"name\": \"UnicornDash\" } } }"
}
]
public static class ActionInvokeHttpTrigger
{
[FunctionName("ActionInvokeHttpTrigger")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string body = await new StreamReader(req.Body).ReadToEndAsync();
using (var client = new HttpClient())
using (var content = new StringContent(body))
{
var authKey = "<AUTH_KEY>";
var requestUri = "https://api.github.com/repos/<OWNER>/<REPOSITORY>/dispatches";
var accept = "application/vnd.github.v3+json";
var userAgent = "<MY_USER_AGENT_NAME>";
client.DefaultRequestHeaders.Add("Authorization", authKey);
client.DefaultRequestHeaders.Add("Accept", accept);
client.DefaultRequestHeaders.Add("User-Agent", userAgent);
using (var response = await client.PostAsync(requestUri, content).ConfigureAwait(false))
{
try
{
response.EnsureSuccessStatusCode();
req.HttpContext.Response.Headers.Add("CARD-ACTION-STATUS", $"Distribution of the app, {payload.client_payload.artifact.name}, to App Center has been invoked.");
}
catch
{
req.HttpContext.Response.Headers.Add("CARD-ACTION-STATUS", "Oops, something goes wrong!");
}
}
}
var result = new OkObjectResult(body);
return result;
}
}
- name: Send a message to Microsoft Teams
uses: aliencube/microsoft-teams-actions@v0.8.0
with:
webhook-uri: https://outlook.office.com/webhook/<GUID>/IncomingWebhook/<GUID>
title: <Message Title>
summary: <Message Summary>
text: <Message Text>
theme-color: <Message Theme Color>
sections: '[{ "activityTitle": "hello world" }, { ... }]'
actions: '[{ "@type": "OpenUri", "name": "lorem ipsum", "targets": [{ "os": "default", "uri": "https://localhost" }] }, { ... }]'
- name: Send a message to Microsoft Teams
uses: aliencube/microsoft-teams-actions@v0.8.0
with:
webhook_uri: ${{ steps.kvsecrets.outputs.TeamsWebhookUri }}
title: ''
summary: 'Artifact for ${{ matrix.targetPlatform }}, version ${{ github.event.client_payload.artifact.version }}, has been distributed to App Center'
text: ''
theme_color: ''
sections: '[{ "activityImage": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png", "activityTitle": "Artifact Distributed to App Center", "activityText": "Artifact for ${{ matrix.targetPlatform }}, version ${{ github.event.client_payload.artifact.version }}, has been distributed to App Center" }]'
actions: '[{ "@type": "OpenUri", "name": "Go to App Center", "targets": [{ "os": "default", "uri": "${{ format(steps.kvsecrets.outputs.AppCenterUri, steps.kvsecrets.outputs.AppName, matrix.targetPlatform) }}" }] }]'
- name: Send a message to Microsoft Teams
uses: aliencube/microsoft-teams-actions@v0.8.0
with:
webhook_uri: ${{ steps.kvsecrets.outputs.TeamsWebhookUri }}
title: ''
summary: 'Artifacts version ${{ steps.buildnumber.outputs.build_number }} have been published to Azure Blob Storage'
text: ''
theme_color: ''
sections: '[{ "activityImage": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png", "activityTitle": "Artifacts Published", "activityText": "Artifacts version ${{ steps.buildnumber.outputs.build_number }} have been published to Azure Blob Storage" }]'
actions: '[{ "@type": "HttpPOST", "name": "Distribute to App Center", "target": "${{ steps.kvsecrets.outputs.ApprovalTargetUri }}", "headers": [{ "name": "x-functions-key", "value": "${{ steps.kvsecrets.outputs.ApprovalTargetAuthKey }}" }], "bodyContentType": "application/json", "body": "{ \"event_type\": \"distribute-appcenter\", \"client_payload\": { \"action\": \"distribute\", \"artifact\": { \"version\": \"${{ steps.buildnumber.outputs.build_number }}\", \"name\": \"UnicornDash\" } } }" }]'
{
"event_type":"distribute-appcenter",
"client_payload":{
"action":"distribute",
"artifact":{
"version":"${{ steps.buildnumber.outputs.build_number }}",
"name":"UnicornDash"
}
}
}
name: Distribute Unity Apps to App Center
on: repository_dispatch
jobs:
distribute-to-appcenter:
name: Distribute the ${{ matrix.targetPlatform }} app to App Center
if: github.event.client_payload.action == 'distribute'
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.