Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
uses: docker/build-push-action@v4
with:
context: .
push: true
Expand Down
26 changes: 25 additions & 1 deletion .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ defaults:
run:
shell: pwsh

env:
# Need to checkout the same commit from the workflow run that triggered this workflow.
# By default the checkout step gets the latest from master but that's not what we want.
# Without checking out the workflow run head sha the errors that we get into are like:
# - Create a PR, that will run the workflows that trigger this one but then, instead of
# checking commit from the PR, we get the commit from master. This would mean we would
# run this workflow which builds the docker image and runs tests using the incorrect commit.
WORKFLOW_HEAD_SHA : ${{ github.event.workflow_run.head_sha }}

jobs:
trigger-info:
name: Trigger info
Expand All @@ -39,6 +48,8 @@ jobs:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: $env:GITHUB_CONTEXT
- uses: actions/checkout@v3
with:
ref: ${{ env.WORKFLOW_HEAD_SHA }}
- name: Run markdown link check log parser with only errors set to true
id: mlc-log-parser
uses: ./action-local
Expand Down Expand Up @@ -132,6 +143,8 @@ jobs:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: $env:GITHUB_CONTEXT
- uses: actions/checkout@v3
with:
ref: ${{ env.WORKFLOW_HEAD_SHA }}
- name: Run markdown link check log parser with only errors set to true
id: mlc-log-parser
uses: ./action-local
Expand Down Expand Up @@ -200,6 +213,8 @@ jobs:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: $env:GITHUB_CONTEXT
- uses: actions/checkout@v3
with:
ref: ${{ env.WORKFLOW_HEAD_SHA }}
- name: Run markdown link check log parser with markdown step output
id: mlc-log-parser
uses: ./action-local
Expand Down Expand Up @@ -268,6 +283,8 @@ jobs:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: $env:GITHUB_CONTEXT
- uses: actions/checkout@v3
with:
ref: ${{ env.WORKFLOW_HEAD_SHA }}
- name: Run markdown link check log parser with only errors set to false
id: mlc-log-parser
uses: ./action-local
Expand Down Expand Up @@ -361,6 +378,8 @@ jobs:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: $env:GITHUB_CONTEXT
- uses: actions/checkout@v3
with:
ref: ${{ env.WORKFLOW_HEAD_SHA }}
- name: Run markdown link check log parser with only errors set to false
id: mlc-log-parser
uses: ./action-local
Expand Down Expand Up @@ -429,6 +448,8 @@ jobs:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: $env:GITHUB_CONTEXT
- uses: actions/checkout@v3
with:
ref: ${{ env.WORKFLOW_HEAD_SHA }}
- name: Run markdown link check log parser with markdown step output
id: mlc-log-parser
uses: ./action-local
Expand Down Expand Up @@ -497,6 +518,8 @@ jobs:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: $env:GITHUB_CONTEXT
- uses: actions/checkout@v3
with:
ref: ${{ env.WORKFLOW_HEAD_SHA }}
- name: Run markdown link check log parser with default action args
uses: ./action-local
id: mlc-log-parser
Expand Down Expand Up @@ -524,6 +547,8 @@ jobs:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: $env:GITHUB_CONTEXT
- uses: actions/checkout@v3
with:
ref: ${{ env.WORKFLOW_HEAD_SHA }}
- name: Run markdown link check log parser with bad input
id: mlc-log-parser-bad-input
uses: ./action-local
Expand Down Expand Up @@ -566,7 +591,6 @@ jobs:
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: $env:GITHUB_CONTEXT
- uses: actions/checkout@v3
- name: Create GitHub status on PR
run: |
$onlyErrorsTrueFilesOutputJobResult = '${{ needs.only-errors-true-files-output.result }}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ namespace MarkdownLinkCheckLogParserCli.GitHub.Exceptions;

public class GitHubHttpClientException : Exception
{
internal GitHubHttpClientException(HttpStatusCode statusCode, HttpMethod method, Uri? requestUri)
: base($"Failed to download workflow run logs. Got {(int)statusCode} {statusCode} from {method} {requestUri}.")
internal GitHubHttpClientException(HttpMethod method, Uri? requestUri, HttpStatusCode statusCode, string responseBody)
: base($"Failed to download workflow run logs. Got {(int)statusCode} {statusCode} from {method} {requestUri}.{Environment.NewLine}With response body:{Environment.NewLine}{responseBody}")
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public async Task<ZipArchive> DownloadWorkflowRunLogsAsync(GitHubRepository repo
var httpResponse = await _httpClient.SendAsync(httpRequest, HttpCompletionOption.ResponseHeadersRead);
if (!httpResponse.IsSuccessStatusCode)
{
throw new GitHubHttpClientException(httpResponse.StatusCode, httpRequest.Method, httpRequest.RequestUri);
var errorResponseBody = await httpResponse.Content.ReadAsStringAsync();
throw new GitHubHttpClientException(httpRequest.Method, httpRequest.RequestUri, httpResponse.StatusCode, errorResponseBody);
}

var responseStream = await httpResponse.Content.ReadAsStreamAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ namespace MarkdownLinkCheckLogParserCli.Tests.Auxiliary;
internal sealed class StatusCodeHandler : DelegatingHandler
{
private readonly HttpStatusCode _statusCode;
private readonly string _responseBody;

public StatusCodeHandler(HttpStatusCode statusCode)
public StatusCodeHandler(HttpStatusCode statusCode, string responseBody)
{
_statusCode = statusCode;
_responseBody = responseBody;
}

protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var httpResponseMessage = new HttpResponseMessage(_statusCode);
var httpResponseMessage = new HttpResponseMessage(_statusCode)
{
Content = new StringContent(_responseBody),
};
return Task.FromResult(httpResponseMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class ParseLogCommandDependencyErrorTests
[InlineData(HttpStatusCode.InternalServerError)]
public async Task GitHubHttpClientFailsToDownloadLogs(HttpStatusCode gitHubHttpClientResponseStatusCode)
{
using var handler = new StatusCodeHandler(gitHubHttpClientResponseStatusCode);
const string errorResponseBody = "Oops, something went wrong.";
using var handler = new StatusCodeHandler(gitHubHttpClientResponseStatusCode, errorResponseBody);
using var httpClient = new HttpClient(handler)
{
BaseAddress = new Uri("https://api.github.com"),
Expand All @@ -34,11 +35,13 @@ public async Task GitHubHttpClientFailsToDownloadLogs(HttpStatusCode gitHubHttpC
var exception = await Should.ThrowAsync<CommandException>(() => command.ExecuteAsync(console).AsTask());
var expectedErrorMessage = @$"An error occurred trying to execute the command to parse the log from a Markdown link check step.
Error:
- Failed to download workflow run logs. Got {(int)gitHubHttpClientResponseStatusCode} {gitHubHttpClientResponseStatusCode} from GET https://api.github.com/repos/repo-name/actions/runs/run-id/logs.";
- Failed to download workflow run logs. Got {(int)gitHubHttpClientResponseStatusCode} {gitHubHttpClientResponseStatusCode} from GET https://api.github.com/repos/repo-name/actions/runs/run-id/logs.
With response body:
{errorResponseBody}";
exception.Message.ShouldBe(expectedErrorMessage);
exception.InnerException.ShouldNotBeNull();
exception.InnerException.ShouldBeAssignableTo<GitHubHttpClientException>();
exception.InnerException.Message.ShouldBe($"Failed to download workflow run logs. Got {(int)gitHubHttpClientResponseStatusCode} {gitHubHttpClientResponseStatusCode} from GET https://api.github.com/repos/repo-name/actions/runs/run-id/logs.");
exception.InnerException.Message.ShouldBe($"Failed to download workflow run logs. Got {(int)gitHubHttpClientResponseStatusCode} {gitHubHttpClientResponseStatusCode} from GET https://api.github.com/repos/repo-name/actions/runs/run-id/logs.{Environment.NewLine}With response body:{Environment.NewLine}{errorResponseBody}");
}

/// <summary>
Expand Down