Skip to content

(build) - fix dockerhub readme publish #4281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2024
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
11 changes: 1 addition & 10 deletions .github/workflows/_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,4 @@ jobs:
docker_registry_username: ${{ secrets.DOCKER_USERNAME }}
docker_registry_password: ${{ secrets.DOCKER_PASSWORD }}
github_registry_username: ${{ github.repository_owner }}
github_registry_password: ${{ secrets.DOCKER_GITHUB_TOKEN }}
-
name: DockerHub Publish Readme
if: success() && github.event_name != 'pull_request' && github.repository_owner == 'GitTools' && github.ref_name == 'main'
shell: pwsh
run: dotnet run/docker.dll --target=DockerHubReadmePublish
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

github_registry_password: ${{ secrets.DOCKER_GITHUB_TOKEN }}
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ jobs:
name: Attetstation
if: ${{ github.event_name == 'repository_dispatch' }}
uses: ./.github/actions/artifacts-attest
-
name: DockerHub Publish Readme
if: ${{ github.event_name == 'repository_dispatch' }}
shell: pwsh
run: dotnet run/docker.dll --target=DockerHubReadmePublish
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
-
name: '[Release]'
shell: pwsh
Expand Down
12 changes: 8 additions & 4 deletions build/docker/Tasks/DockerHubReadmePublish.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class DockerHubReadmePublish : FrostingTask<BuildContext>;

[TaskName(nameof(DockerHubReadmePublishInternal))]
[TaskDescription("Publish the DockerHub updated README.md")]
public class DockerHubReadmePublishInternal : FrostingTask<BuildContext>
public class DockerHubReadmePublishInternal : AsyncFrostingTask<BuildContext>
{
public override bool ShouldRun(BuildContext context)
{
Expand All @@ -24,20 +24,23 @@ public override bool ShouldRun(BuildContext context)
return shouldRun;
}

public override void Run(BuildContext context)
public override async Task RunAsync(BuildContext context)
{
ArgumentNullException.ThrowIfNull(context.Credentials?.DockerHub);
var readme = GetReadmeContent(context);

var response = context.HttpPost("https://hub.docker.com/v2/users/login", settings =>
context.Information("Publishing README.md to DockerHub");

context.Information("Logging in to DockerHub");
var response = await context.HttpPostAsync("https://hub.docker.com/v2/users/login", settings =>
{
var credentials = context.Credentials.DockerHub;
settings
.SetContentType("application/json")
.SetJsonRequestBody(new { username = credentials.Username, password = credentials.Password });
});


context.Information("Updating README.md on DockerHub");
context.HttpPatch("https://hub.docker.com/v2/repositories/gittools/gitversion", settings =>
{
var token = context.ParseJson(response).Value<string>("token");
Expand All @@ -46,6 +49,7 @@ public override void Run(BuildContext context)
.SetAuthorization("JWT", token)
.SetJsonRequestBody(new { full_description = readme });
});
context.Information("README.md updated on DockerHub");
}

private static string GetReadmeContent(BuildContextBase context)
Expand Down