Skip to content

Commit fa10c2c

Browse files
committed
Add test action from GH marketplace and update docs
1 parent ed1fd02 commit fa10c2c

File tree

8 files changed

+158
-16
lines changed

8 files changed

+158
-16
lines changed

.github/workflows/publish-docker-image.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
workflow_dispatch:
55
push:
66
branches: [ main ]
7+
tags: [ 'v*' ]
78
paths-ignore:
89
- "**.md"
910
schedule:
@@ -37,6 +38,7 @@ jobs:
3738
uses: docker/metadata-action@v4
3839
with:
3940
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
flavor: latest=true
4042
- name: Build and push Docker image
4143
uses: docker/build-push-action@v4
4244
with:
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Test GitHub action from GH Marketplace
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
paths-ignore:
8+
- "**.md"
9+
schedule:
10+
- cron: '0 0 * * 0' # Once a week: "At 00:00 on Sunday."
11+
12+
defaults:
13+
run:
14+
shell: pwsh
15+
16+
jobs:
17+
test-success:
18+
name: Test success
19+
permissions:
20+
contents: read
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Dump github context for debug purposes
24+
env:
25+
GITHUB_CONTEXT: ${{ toJSON(github) }}
26+
run: $env:GITHUB_CONTEXT
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+
$random = Get-Random
35+
$delimiter = "EOF_$random"
36+
Write-Output "issue-body<<$delimiter" >> $env:GITHUB_OUTPUT
37+
Write-Output $issueBody >> $env:GITHUB_OUTPUT
38+
Write-Output $delimiter >> $env:GITHUB_OUTPUT
39+
Write-Output "template-filepath=$templateFilepath" >> $env:GITHUB_OUTPUT
40+
- name: Dump outputs from previous step
41+
env:
42+
STEP_OUTPUT: ${{ toJSON(steps.args.outputs) }}
43+
run: $env:STEP_OUTPUT
44+
- name: Run GitHub issue forms parser
45+
id: issue-parser
46+
uses: edumserrano/github-issue-forms-parser@v1
47+
with:
48+
template-filepath: '${{ steps.args.outputs.template-filepath }}'
49+
issue-form-body: '${{ steps.args.outputs.issue-body }}'
50+
- name: Dump outputs from previous step
51+
env:
52+
STEP_OUTPUT: ${{ toJSON(steps.issue-parser.outputs) }}
53+
run: $env:STEP_OUTPUT
54+
- name: Output and assert parsed issue
55+
run: |
56+
$issue = '${{ steps.issue-parser.outputs.parsed-issue }}' | ConvertFrom-Json
57+
$issueAsJsonIndented = ConvertTo-Json $issue
58+
$expectedIssueAsJson = '{
59+
"nuget-id": "dotnet-sdk-extensions",
60+
"nuget-version": "1.0.13-alpha",
61+
"auto-generate-release-notes": "Yes",
62+
"push-nuget": "",
63+
"custom-release-notes": "## Custom release notes\n\nTest 123\n\nAnother line:\n- point 1\n- point 2\n- point 3",
64+
"operating-systems": {
65+
"macos": true,
66+
"windows": true,
67+
"linux": false,
68+
"i-dont-know": false
69+
}
70+
}'
71+
72+
Write-Output $issueAsJsonIndented
73+
if($expectedIssueAsJson -eq $issueAsJsonIndented)
74+
{
75+
Write-Output "::notice title=Action check::Action produced the expected output. See the output from the step 'Output and assert parsed issue'."
76+
}
77+
else
78+
{
79+
Write-Output "::error title=Action check::Action didn't produce expected output. See the output from the step 'Output and assert parsed issue'."
80+
Exit -1
81+
}
82+
83+
test-failure:
84+
name: Test failure
85+
permissions:
86+
contents: read
87+
runs-on: ubuntu-latest
88+
steps:
89+
- name: Dump github context for debug purposes
90+
env:
91+
GITHUB_CONTEXT: ${{ toJSON(github) }}
92+
run: $env:GITHUB_CONTEXT
93+
- uses: actions/checkout@v3
94+
- name: Run GitHub issue forms parser with bad input
95+
id: issue-parser-bad-input
96+
uses: edumserrano/github-issue-forms-parser@v1
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![Build and test](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/build-test.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/build-test.yml)
44
[![Test GitHub action](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action.yml)
5+
[![Test GitHub action from GH Marketplace](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action-gh-marketplace.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action-gh-marketplace.yml)
56
[![Publish Docker image](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/publish-docker-image.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/publish-docker-image.yml)
67
[![codecov](https://codecov.io/gh/edumserrano/github-issue-forms-parser/branch/main/graph/badge.svg?token=B9nrGE2Ine)](https://codecov.io/gh/edumserrano/github-issue-forms-parser)
78
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-GitHub%20issue%20forms%20parser-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/marketplace/actions/github-issue-forms-parser)

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ outputs:
1515
description: 'The parsed issue form as a JSON string.'
1616
runs:
1717
using: 'docker'
18-
image: 'docker://ghcr.io/edumserrano/github-issue-forms-parser:main'
18+
image: 'docker://ghcr.io/edumserrano/github-issue-forms-parser:v1'
1919
args:
2020
- parse-issue-form
2121
- --template-filepath

docs/dev-notes/README.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,17 @@ To pass arguments to the app when debugging you can use the `commandLineArgs` in
6969
The steps below show how to run the Docker container action against a set of test data provided by the repo. However you can follow the same steps and provide any data you wish to test.
7070

7171
1) Clone the repo and browse to the repo's directory.
72-
2) Run `docker build -t github-issue-parser .`
73-
3) Read the test issue form body into the variable `$issueBody` by doing: `$issueBody = Get-Content GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/IssueBody.md -Raw`
74-
4) Run the docker container by executing:
72+
2) Create an empty file named `github-step-output.txt` that will store the GitHub step output of the action. To create an empty file you can do something like `echo $null >> github-step-output.txt`.
73+
3) Run `docker build -t github-issue-parser .`
74+
4) Read the test issue form body into the variable `$issueBody` by doing: `$issueBody = Get-Content GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/IssueBody.md -Raw`
75+
5) Run the docker container by executing:
7576

7677
```
77-
docker run --rm -v ${pwd}:/workspace --workdir /workspace github-issue-parser `
78-
parse-issue-form `
78+
docker run --env GITHUB_OUTPUT=/workspace/github-step-output.txt `
79+
-v ${pwd}:/workspace `
80+
-v ${pwd}/github-step-output.txt:/workspace/github-step-output.txt `
81+
--workdir /workspace `
82+
github-issue-parser parse-issue-form `
7983
--template-filepath GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/TestFiles/Template.yml `
8084
--issue-body $issueBody
8185
```
@@ -126,6 +130,12 @@ To understand better how the action builds and executes the Docker container loo
126130

127131
### As of writing this, the log for building the docker action looks as follows
128132

133+
> **Note**
134+
>
135+
> This is the log when building the docker image for the action, which only happens on the [test-action workflow](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action.yml) because using the published action from GitHub Marketplace will download the package from the GitHub packages and so the log will look different.
136+
>
137+
> The information mentioned here is still valuable to understand more about how GitHub Docker actions work.
138+
129139
```
130140
/usr/bin/docker build
131141
-t 2bcf09:d996dfb6f4ec40c1a59c1e244bdd3374
@@ -145,6 +155,12 @@ This way it can successfully build the Dockerfile for this action which would ot
145155

146156
### As of writing this, the log for running the docker action looks as follows
147157

158+
> **Note**
159+
>
160+
> This is the log when building the docker image for the action, which only happens on the [test-action workflow](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action.yml) because using the published action from GitHub Marketplace will download the package from the GitHub packages and so the log will look different.
161+
>
162+
> The information mentioned here is still valuable to understand more about how GitHub Docker actions work.
163+
148164
```
149165
/usr/bin/docker run
150166
--name bcf09d996dfb6f4ec40c1a59c1e244bdd3374_381201

docs/dev-notes/workflows/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
There are two workflows setup on this repo:
44

5-
| Worflow | Status and link | Description |
6-
| --------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------: |
7-
| [build-and-test](/.github/workflows/build-test.yml) | [![Build and test](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/build-test.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/build-test.yml) | Builds the solution and runs tests |
8-
| [test-action](/.github/workflows/test-action.yml) | [![Test GitHub action](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action.yml) | Builds and tests the GitHub action |
9-
| [publish-docker-image](/.github/workflows/publish-docker-image.yml) | [![Publish Docker image](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/publish-docker-image.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/publish-docker-image.yml) | Publishes Docker image used by this action to GitHub packages |
10-
| [package-retention-policy](/.github/workflows/package-retention-policy.yml) | [![Package retention policy](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/package-retention-policy.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/package-retention-policy.yml) | Removes old Docker images used by this action from GitHub packages |
5+
| Worflow | Status and link | Description |
6+
| ------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------ |
7+
| [build-and-test](/.github/workflows/build-test.yml) | [![Build and test](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/build-test.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/build-test.yml) | Builds the solution and runs tests |
8+
| [test-action](/.github/workflows/test-action.yml) | [![Test GitHub action](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action.yml) | Builds and tests the GitHub action. Builds the action from this repo. |
9+
| [test-action-gh-marketplace](/.github/workflows/test-action-gh-marketplace.yml) | [![Test GitHub action from GH Marketplace](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action-gh-marketplace.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action-gh-marketplace.yml) | Builds and tests the GitHub action. Uses the published version to GitHub Marketplace. |
10+
| [publish-docker-image](/.github/workflows/publish-docker-image.yml) | [![Publish Docker image](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/publish-docker-image.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/publish-docker-image.yml) | Publishes Docker image used by this action to GitHub packages |
11+
| [package-retention-policy](/.github/workflows/package-retention-policy.yml) | [![Package retention policy](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/package-retention-policy.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/package-retention-policy.yml) | Removes old Docker images used by this action from GitHub packages |
1112

1213
## Workflows' documentation
1314

1415
- [build-and-test](/docs/dev-notes/workflows/build-and-test-workflow.md)
1516
- [test-action](/docs/dev-notes/workflows/test-action-workflow.md)
17+
- [test-action-gh-marketplace](/docs/dev-notes/workflows/test-action-gh-marketplace-workflow.md)
1618
- [publish-docker-image](/docs/dev-notes/workflows/publish-docker-image.md)
1719
- [package-retention-policy](/docs/dev-notes/workflows/package-retention-policy.md)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# test-action workflow
2+
3+
[![Test GitHub action from GH Marketplace](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action-gh-marketplace.yml/badge.svg)](https://github.com/edumserrano/github-issue-forms-parser/actions/workflows/test-action-gh-marketplace.yml)
4+
5+
[This workflow](/.github/workflows/test-action-gh-marketplace.yml):
6+
7+
- Is a copy of the [test-action workflow](/.github/workflows/test-action.yml). See the [documentation for that workflow](/docs/dev-notes/workflows/test-action-workflow.md) for more info.
8+
- The main difference from this workflow and the `test-action workflow` are:
9+
- Tests the GitHub action from the Marketplace instead of building it from this repo. It makes sure that the published version is working.
10+
- Does not run against PRs because it shouldn't add a status check to PRs.
11+

entrypoint.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ function Main()
77
Write-Output $inputArgs
88
Write-Output "::endgroup::"
99

10-
Write-Output "::group::Run dotnet GitHub issue form parser"
1110
$output = dotnet '/app/GitHubIssuesParserCli.dll' $inputArgs
1211
if ($LASTEXITCODE -ne 0 )
1312
{
@@ -20,13 +19,12 @@ function Main()
2019
Write-Output "parsed-issue<<$delimiter" >> $env:GITHUB_OUTPUT
2120
Write-Output $output >> $env:GITHUB_OUTPUT
2221
Write-Output $delimiter >> $env:GITHUB_OUTPUT
23-
Write-Output "::endgroup::"
2422

25-
Write-Output "::group::dotnet GitHub issue form parser output"
23+
Write-Output "::group::GitHub issue form parser output"
2624
Write-Output $output
2725
Write-Output "::endgroup::"
2826

29-
Write-Output "::group::dotnet GitHub issue form parser output indented"
27+
Write-Output "::group::GitHub issue form parser output indented"
3028
$outputAsJson = ConvertFrom-Json $output
3129
COnvertTo-Json $outputAsJson
3230
Write-Output "::endgroup::"

0 commit comments

Comments
 (0)