Skip to content

Commit 08ff556

Browse files
authored
(build) - fix dockerhub readme publish (#4281)
move the publish event to the release stage
1 parent 84f2e38 commit 08ff556

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

.github/workflows/_docker.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,4 @@ jobs:
7575
docker_registry_username: ${{ secrets.DOCKER_USERNAME }}
7676
docker_registry_password: ${{ secrets.DOCKER_PASSWORD }}
7777
github_registry_username: ${{ github.repository_owner }}
78-
github_registry_password: ${{ secrets.DOCKER_GITHUB_TOKEN }}
79-
-
80-
name: DockerHub Publish Readme
81-
if: success() && github.event_name != 'pull_request' && github.repository_owner == 'GitTools' && github.ref_name == 'main'
82-
shell: pwsh
83-
run: dotnet run/docker.dll --target=DockerHubReadmePublish
84-
env:
85-
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
86-
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
87-
78+
github_registry_password: ${{ secrets.DOCKER_GITHUB_TOKEN }}

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ jobs:
137137
name: Attetstation
138138
if: ${{ github.event_name == 'repository_dispatch' }}
139139
uses: ./.github/actions/artifacts-attest
140+
-
141+
name: DockerHub Publish Readme
142+
if: ${{ github.event_name == 'repository_dispatch' }}
143+
shell: pwsh
144+
run: dotnet run/docker.dll --target=DockerHubReadmePublish
145+
env:
146+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
147+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
140148
-
141149
name: '[Release]'
142150
shell: pwsh

build/docker/Tasks/DockerHubReadmePublish.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class DockerHubReadmePublish : FrostingTask<BuildContext>;
1111

1212
[TaskName(nameof(DockerHubReadmePublishInternal))]
1313
[TaskDescription("Publish the DockerHub updated README.md")]
14-
public class DockerHubReadmePublishInternal : FrostingTask<BuildContext>
14+
public class DockerHubReadmePublishInternal : AsyncFrostingTask<BuildContext>
1515
{
1616
public override bool ShouldRun(BuildContext context)
1717
{
@@ -24,20 +24,23 @@ public override bool ShouldRun(BuildContext context)
2424
return shouldRun;
2525
}
2626

27-
public override void Run(BuildContext context)
27+
public override async Task RunAsync(BuildContext context)
2828
{
2929
ArgumentNullException.ThrowIfNull(context.Credentials?.DockerHub);
3030
var readme = GetReadmeContent(context);
3131

32-
var response = context.HttpPost("https://hub.docker.com/v2/users/login", settings =>
32+
context.Information("Publishing README.md to DockerHub");
33+
34+
context.Information("Logging in to DockerHub");
35+
var response = await context.HttpPostAsync("https://hub.docker.com/v2/users/login", settings =>
3336
{
3437
var credentials = context.Credentials.DockerHub;
3538
settings
3639
.SetContentType("application/json")
3740
.SetJsonRequestBody(new { username = credentials.Username, password = credentials.Password });
3841
});
3942

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

5155
private static string GetReadmeContent(BuildContextBase context)

0 commit comments

Comments
 (0)