Created
February 19, 2020 03:41
-
-
Save justinyoo/073ed7a27a21786f922b6c8aca9b1729 to your computer and use it in GitHub Desktop.
Building Custom GitHub Action with .NET Core
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: <Name of Custom GitHub Action> | |
description: <Short description of Action> | |
inputs: | |
input_parameter: | |
description: <Short description of input parameter> | |
required: <true|false> | |
default: <default value> | |
runs: | |
using: docker | |
image: Dockerfile | |
env: | |
INPUT_PARAMETER: {{ inputs.input_parameter }} |
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
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build | |
WORKDIR /app | |
COPY *.sln . | |
COPY src/ ./src/ | |
ADD entrypoint.sh /entrypoint.sh | |
RUN chmod +x /entrypoint.sh | |
ENTRYPOINT ["/entrypoint.sh"] |
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
#!/bin/sh -l | |
cd /app | |
dotnet restore | |
dotnet build | |
dotnet run --project src/GitHubActions.Teams.ConsoleApp -- \ | |
--input-parameter "$INPUT_PARAMETER" |
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 Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var card = new MessageCard() | |
{ | |
Title = args[1], | |
Summary = args[2], | |
Text = args[3], | |
ThemeColor = args[4], | |
Sections = ParseCollection<Section>(args[5]), | |
Actions = ParseCollection<BaseAction>(args[6]) | |
}; | |
var converted = JsonConvert.SerializeObject(card); | |
var message = (string)null; | |
var requestUri = args[0]; | |
using (var client = new HttpClient()) | |
using (var content = new StringContent(converted, Encoding.UTF8, "application/json")) | |
using (var response = await client.PostAsync(requestUri, content).ConfigureAwait(false)) | |
{ | |
response.EnsureSuccessStatusCode(); | |
} | |
} | |
private static List<T> ParseCollection<T>(string value) | |
{ | |
var parsed = string.IsNullOrWhiteSpace(value) | |
? null | |
: JsonConvert.DeserializeObject<List<T>>(value, settings); | |
return parsed; | |
} | |
} |
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: Build and Test GitHub actions | |
on: push | |
jobs: | |
build_and_test: | |
name: Build and test the GitHub Action | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v1 | |
- name: Run the private action | |
uses: ./ | |
with: | |
input_parameter: <Input parameter value> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment