Created
March 5, 2020 04:36
-
-
Save justinyoo/5d12d5df5c569df921ff614001bb48d2 to your computer and use it in GitHub Desktop.
Implementing ChatOps on GitHub Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"@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\" } } }" | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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" }] }, { ... }]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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) }}" }] }]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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\" } } }" }]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"event_type":"distribute-appcenter", | |
"client_payload":{ | |
"action":"distribute", | |
"artifact":{ | |
"version":"${{ steps.buildnumber.outputs.build_number }}", | |
"name":"UnicornDash" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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