Skip to content

Commit 4d7914a

Browse files
committed
update docs and workflow
1 parent c1e8021 commit 4d7914a

File tree

6 files changed

+159
-95
lines changed

6 files changed

+159
-95
lines changed

.github/workflows/build-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ jobs:
3333
TEST_RESULTS_ARTIFACT_NAME: test-results
3434
CODE_COVERAGE_ARTIFACT_NAME: code-coverage-report
3535
steps:
36+
- name: Dump github context for debug purposes
37+
env:
38+
GITHUB_CONTEXT: ${{ toJSON(github) }}
39+
run: $env:GITHUB_CONTEXT
3640
- name: Checkout repository
3741
uses: actions/checkout@v3
3842
- name: Setup .NET

.github/workflows/test-action.yml

Lines changed: 87 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -18,76 +18,95 @@ defaults:
1818
shell: pwsh
1919

2020
jobs:
21-
main:
22-
name: Test GitHub action
21+
test-success:
22+
name: Test success
2323
permissions:
2424
contents: read
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v3
28-
- name: Get test input args
29-
id: args
30-
run: |
31-
$templateFilepath = './GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/Template.yml'
32-
# using -Raw is needed or else the newlines are not preserved and the action will fail to parse the body
33-
$issueBody = Get-Content ./GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/IssueBody.md -Raw
34-
$issueBody = $issueBody -replace "\n","%0A" # The content must be escaped to preserve newlines. See https://github.community/t/set-output-truncates-multiline-strings/16852/3
35-
Write-Output "::set-output name=issue-body::$issueBody"
36-
Write-Output "::set-output name=template-filepath::$templateFilepath"
37-
- name: Dump outputs from previous step
38-
env:
39-
STEP_OUTPUT: ${{ toJSON(steps.args.outputs) }}
40-
run: $env:STEP_OUTPUT
41-
- name: Run GitHub issue forms parser
42-
id: issue-parser
43-
uses: ./
44-
with:
45-
template-filepath: '${{ steps.args.outputs.template-filepath }}'
46-
issue-form-body: '${{ steps.args.outputs.issue-body }}'
47-
- name: Dump outputs from previous step
48-
env:
49-
STEP_OUTPUT: ${{ toJSON(steps.issue-parser.outputs) }}
50-
run: $env:STEP_OUTPUT
51-
- name: Output and assert parsed issue
52-
run: |
53-
$issue = '${{ steps.issue-parser.outputs.parsed-issue }}' | ConvertFrom-Json
54-
$issueAsJsonIndented = ConvertTo-Json $issue
55-
$expectedIssueAsJson = '{
56-
"nuget-id": "dotnet-sdk-extensions",
57-
"nuget-version": "1.0.13-alpha",
58-
"auto-generate-release-notes": "Yes",
59-
"push-nuget": "",
60-
"custom-release-notes": "## Custom release notes\n\nTest 123\n\nAnother line:\n- point 1\n- point 2\n- point 3",
61-
"operating-systems": {
62-
"macos": true,
63-
"windows": true,
64-
"linux": false,
65-
"i-dont-know": false
66-
}
67-
}'
68-
69-
Write-Output $issueAsJsonIndented
70-
if($expectedIssueAsJson -eq $issueAsJsonIndented) {
71-
Write-Output "::notice title=Action check::Action produced the expected output. See the output from the step 'Output and assert parsed issue'."
27+
- name: Dump github context for debug purposes
28+
env:
29+
GITHUB_CONTEXT: ${{ toJSON(github) }}
30+
run: $env:GITHUB_CONTEXT
31+
- uses: actions/checkout@v3
32+
- name: Get test input args
33+
id: args
34+
run: |
35+
$templateFilepath = './GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/Template.yml'
36+
# using -Raw is needed or else the newlines are not preserved and the action will fail to parse the body
37+
$issueBody = Get-Content ./GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/IssueBody.md -Raw
38+
$issueBody = $issueBody -replace "\n","%0A" # The content must be escaped to preserve newlines. See https://github.community/t/set-output-truncates-multiline-strings/16852/3
39+
Write-Output "::set-output name=issue-body::$issueBody"
40+
Write-Output "::set-output name=template-filepath::$templateFilepath"
41+
- name: Dump outputs from previous step
42+
env:
43+
STEP_OUTPUT: ${{ toJSON(steps.args.outputs) }}
44+
run: $env:STEP_OUTPUT
45+
- name: Run GitHub issue forms parser
46+
id: issue-parser
47+
uses: ./
48+
with:
49+
template-filepath: '${{ steps.args.outputs.template-filepath }}'
50+
issue-form-body: '${{ steps.args.outputs.issue-body }}'
51+
- name: Dump outputs from previous step
52+
env:
53+
STEP_OUTPUT: ${{ toJSON(steps.issue-parser.outputs) }}
54+
run: $env:STEP_OUTPUT
55+
- name: Output and assert parsed issue
56+
run: |
57+
$issue = '${{ steps.issue-parser.outputs.parsed-issue }}' | ConvertFrom-Json
58+
$issueAsJsonIndented = ConvertTo-Json $issue
59+
$expectedIssueAsJson = '{
60+
"nuget-id": "dotnet-sdk-extensions",
61+
"nuget-version": "1.0.13-alpha",
62+
"auto-generate-release-notes": "Yes",
63+
"push-nuget": "",
64+
"custom-release-notes": "## Custom release notes\n\nTest 123\n\nAnother line:\n- point 1\n- point 2\n- point 3",
65+
"operating-systems": {
66+
"macos": true,
67+
"windows": true,
68+
"linux": false,
69+
"i-dont-know": false
7270
}
73-
else {
74-
Write-Output "::error title=Action check::Action didn't produce expected output. See the output from the step 'Output and assert parsed issue'."
75-
Exit -1
76-
}
77-
- name: Run GitHub issue forms parser with bad input
78-
id: issue-parser-bad-input
79-
uses: ./
80-
continue-on-error: true
81-
with:
82-
template-filepath: '${{ steps.args.outputs.template-filepath }}'
83-
issue-form-body: '{}'
84-
- name: The action should fail if it fails to parse
85-
run: |
86-
$parseStepWithBadInputOutcome = '${{ steps.issue-parser-bad-input.outcome }}'
87-
if($parseStepWithBadInputOutcome -eq 'success') {
88-
Write-Output "::error title=Action check:Action should have failed the workflow because of invalid input but it didn't."
89-
Exit 1
90-
}
91-
else {
92-
Write-Output "::notice title=Action check::Action would have failed the workflow given invalid input. You should see an error message on the action's Annotations."
93-
}
71+
}'
72+
73+
Write-Output $issueAsJsonIndented
74+
if($expectedIssueAsJson -eq $issueAsJsonIndented)
75+
{
76+
Write-Output "::notice title=Action check::Action produced the expected output. See the output from the step 'Output and assert parsed issue'."
77+
}
78+
else
79+
{
80+
Write-Output "::error title=Action check::Action didn't produce expected output. See the output from the step 'Output and assert parsed issue'."
81+
Exit -1
82+
}
83+
84+
test-failure:
85+
name: Test failure
86+
permissions:
87+
contents: read
88+
runs-on: ubuntu-latest
89+
steps:
90+
- name: Dump github context for debug purposes
91+
env:
92+
GITHUB_CONTEXT: ${{ toJSON(github) }}
93+
- uses: actions/checkout@v3
94+
- name: Run GitHub issue forms parser with bad input
95+
id: issue-parser-bad-input
96+
uses: ./
97+
continue-on-error: true
98+
with:
99+
template-filepath: '${{ steps.args.outputs.template-filepath }}'
100+
issue-form-body: '{}'
101+
- name: The action should fail if it fails to parse
102+
run: |
103+
$parseStepWithBadInputOutcome = '${{ steps.issue-parser-bad-input.outcome }}'
104+
if($parseStepWithBadInputOutcome -eq 'success')
105+
{
106+
Write-Output "::error title=Action check:Action should have failed the workflow because of invalid input but it didn't."
107+
Exit 1
108+
}
109+
else
110+
{
111+
Write-Output "::notice title=Action check::Action would have failed the workflow given invalid input. You should see an error message on the action's Annotations."
112+
}

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
[![GitHub Sponsors](https://img.shields.io/github/sponsors/edumserrano)](https://github.com/sponsors/edumserrano)
1010
[![LinkedIn](https://img.shields.io/badge/LinkedIn-Eduardo%20Serrano-blue.svg)](https://www.linkedin.com/in/eduardomserrano/)
1111

12+
- [Description](#description)
13+
- [Usage](#usage)
14+
- [Action inputs](#action-inputs)
15+
- [Action outputs](#action-outputs)
16+
- [Example output for a given issue form template and body](#example-output-for-a-given-issue-form-template-and-body)
17+
- [Example usages of this action in GitHub workflows](#example-usages-of-this-action-in-github-workflows)
18+
- [I can't figure out the structure of the JSON object produced by the parser](#i-cant-figure-out-the-structure-of-the-json-object-produced-by-the-parser)
19+
- [Dev notes](#dev-notes)
20+
21+
## Description
22+
1223
A Docker container [GitHub action](https://docs.github.com/en/actions/learn-github-actions/finding-and-customizing-actions) that can be used to parse [GitHub issue forms](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema).
1324

1425
## Usage
@@ -31,14 +42,14 @@ A Docker container [GitHub action](https://docs.github.com/en/actions/learn-gith
3142
...
3243
```
3344
34-
### Action inputs
45+
## Action inputs
3546
3647
| Name | Description | Required
3748
| --- | --- | --- |
3849
| `template-filepath` | The filepath to the [issue form template](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository#creating-issue-forms). | yes |
3950
| `issue-form-body` | The body of the issue to parse. | yes |
4051

41-
### Action outputs
52+
## Action outputs
4253

4354
| Name | Description
4455
| --- | --- |

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ runs:
1717
using: 'docker'
1818
image: 'Dockerfile'
1919
args:
20+
- parse-issue-form
21+
- --template-filepath
2022
- ${{ inputs.template-filepath }}
23+
- --issue-body
2124
- ${{ inputs.issue-form-body }}

docs/dev-notes/README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Dev notes
22

3+
- [Building the GitHubIssueFormsParser solution](#building-the-githubissueformsparser-solution)
4+
- [Building with Visual Studio](#building-with-visual-studio)
5+
- [Building with dotnet CLI](#building-with-dotnet-cli)
6+
- [Running GitHubIssueFormsParser solution tests](#running-githubissueformsparser-solution-tests)
7+
- [Run tests with Visual Studio](#run-tests-with-visual-studio)
8+
- [Run tests with dotnet CLI](#run-tests-with-dotnet-cli)
9+
- [Debugging the `GitHubIssuesParserCli` project using Visual Studio](#debugging-the-githubissuesparsercli-project-using-visual-studio)
10+
- [Building and running the Docker container action using Powershell against a set of test data](#building-and-running-the-docker-container-action-using-powershell-against-a-set-of-test-data)
11+
- [Projects wide configuration](#projects-wide-configuration)
12+
- [Deterministic Build configuration](#deterministic-build-configuration)
13+
- [Repository configuration](#repository-configuration)
14+
- [GitHub Workflows](#github-workflows)
15+
- [GitHub marketplace](#github-marketplace)
16+
- [Note about the Docker container action](#note-about-the-docker-container-action)
17+
- [As of writing this, the log for building the docker action looks as follows](#as-of-writing-this-the-log-for-building-the-docker-action-looks-as-follows)
18+
- [As of writing this, the log for running the docker action looks as follows](#as-of-writing-this-the-log-for-running-the-docker-action-looks-as-follows)
19+
- [Other notes](#other-notes)
20+
321
## Building the GitHubIssueFormsParser solution
422

523
### Building with Visual Studio
@@ -53,7 +71,14 @@ The steps below show how to run the Docker container action against a set of tes
5371
1) Clone the repo and browse to the repo's directory.
5472
2) Run `docker build -t github-issue-parser .`
5573
3) Read the test issue form body into the variable `$issueBody` by doing: `$issueBody = Get-Content GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/IssueBody.md -Raw`
56-
4) Run the docker container by executing `docker run --rm -v ${pwd}:/workspace --workdir /workspace github-issue-parser GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/Template.yml $issueBody`.
74+
4) Run the docker container by executing:
75+
76+
```
77+
docker run --rm -v ${pwd}:/workspace --workdir /workspace github-issue-parser `
78+
parse-issue-form `
79+
--template-filepath GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/Template.yml `
80+
--issue-body $issueBody
81+
```
5782

5883
**Notes:**
5984

entrypoint.ps1

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
param ($templateFilepath, $issueFormBody)
1+
function Main()
2+
{
3+
[OutputType([Void])]
4+
param ([string[]] $inputArgs)
25

3-
Write-Output "::group::GitHub issue form template"
4-
Write-Output "Template filepath: '$templateFilepath'"
5-
$template = Get-Content $templateFilepath
6-
Write-Output $template
7-
Write-Output "::endgroup::"
8-
9-
Write-Output "::group::GitHub issue form body"
10-
Write-Output $issueFormBody
11-
Write-Output "::endgroup::"
12-
13-
Write-Output "::group::Run dotnet GitHub issue form parser"
14-
$output = dotnet '/app/GitHubIssuesParserCli.dll' parse-issue-form -t $templateFilepath -i $issueFormBody
15-
if($LASTEXITCODE -ne 0 ) {
6+
Write-Output "::group::Input arguments"
7+
Write-Output $inputArgs
8+
Write-Output "::endgroup::"
9+
10+
Write-Output "::group::Run dotnet GitHub issue form parser"
11+
$output = dotnet '/app/GitHubIssuesParserCli.dll' $inputArgs
12+
if ($LASTEXITCODE -ne 0 )
13+
{
1614
Write-Output "::error::GitHub issue form parser didn't complete successfully. See the step's log for more details."
1715
exit $LASTEXITCODE
18-
}
19-
Write-Output "::set-output name=parsed-issue::$output"
20-
Write-Output "::endgroup::"
16+
}
17+
Write-Output "::set-output name=parsed-issue::$output"
18+
Write-Output "::endgroup::"
2119

22-
Write-Output "::group::dotnet GitHub issue form parser output"
23-
Write-Output $output
24-
Write-Output "::endgroup::"
20+
Write-Output "::group::dotnet GitHub issue form parser output"
21+
Write-Output $output
22+
Write-Output "::endgroup::"
23+
24+
Write-Output "::group::dotnet GitHub issue form parser output indented"
25+
$outputAsJson = ConvertFrom-Json $output
26+
COnvertTo-Json $outputAsJson
27+
Write-Output "::endgroup::"
28+
}
2529

26-
Write-Output "::group::dotnet GitHub issue form parser output indented"
27-
$outputAsJson = ConvertFrom-Json $output
28-
COnvertTo-Json $outputAsJson
29-
Write-Output "::endgroup::"
30+
# invoke entrypoint function
31+
Main $args

0 commit comments

Comments
 (0)