From c3cf7b4a1b2bd9e110a85e589cef5249ffdbbedf Mon Sep 17 00:00:00 2001 From: Nicholas McDonnell <50747025+mcdonnnj@users.noreply.github.com> Date: Mon, 10 Feb 2025 15:54:53 -0500 Subject: [PATCH 1/2] Use a GitHub Action to update the Docker Hub description Use the peter-evans/dockerhub-description Action to update the Docker Hub description instead of a bash script. --- .github/workflows/build.yml | 13 ++++++++----- push_readme.sh | 33 --------------------------------- 2 files changed, 8 insertions(+), 38 deletions(-) delete mode 100755 push_readme.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c8dd000..50419d7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -439,11 +439,14 @@ jobs: tags: ${{ needs.prepare.outputs.tags }} # For a list of pre-defined annotation keys and value types see: # https://github.com/opencontainers/image-spec/blob/master/annotations.md - - name: Publish README.md to Docker Hub - env: - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - run: ./push_readme.sh + - name: Update the Docker Hub description + uses: peter-evans/dockerhub-description@v4 + with: + description: README.md + password: ${{ secrets.DOCKER_PASSWORD }} + repository: ${{ env.IMAGE_NAME }} + short-description: ${{ github.event.repository.description }} + username: ${{ secrets.DOCKER_USERNAME }} - name: Setup tmate debug session uses: mxschmitt/action-tmate@v3 if: env.RUN_TMATE diff --git a/push_readme.sh b/push_readme.sh deleted file mode 100755 index 29b12aa..0000000 --- a/push_readme.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash - -# Push the README.md file to the Docker Hub repository - -# Requires the following environment variables to be set: -# DOCKER_PASSWORD, DOCKER_USERNAME, IMAGE_NAME - -set -o nounset -set -o errexit -set -o pipefail - -echo "Logging in and requesting JWT..." -token=$(curl --silent --request POST \ - --header "Content-Type: application/json" \ - --data \ - '{"username": "'"$DOCKER_USERNAME"'", "password": "'"$DOCKER_PASSWORD"'"}' \ - https://hub.docker.com/v2/users/login/ | jq --raw-output .token) - -echo "Pushing README file..." -code=$(jq --null-input --arg msg "$(< README.md)" \ - '{"registry":"registry-1.docker.io","full_description": $msg }' \ - | curl --silent --output /dev/null --location --write-out "%{http_code}" \ - https://hub.docker.com/v2/repositories/"${IMAGE_NAME}"/ \ - --data @- --request PATCH \ - --header "Content-Type: application/json" \ - --header "Authorization: JWT ${token}") - -if [[ "${code}" = "200" ]]; then - printf "Successfully pushed README to Docker Hub" -else - printf "Unable to push README to Docker Hub, response code: %s\n" "${code}" - exit 1 -fi From 6c655fcacebed40ba70476d7b352eddf4a6c3514 Mon Sep 17 00:00:00 2001 From: Nicholas McDonnell <50747025+mcdonnnj@users.noreply.github.com> Date: Mon, 10 Feb 2025 16:00:36 -0500 Subject: [PATCH 2/2] Limit when the Docker Hub description is updated Instead of updating the description whenever the `build` workflow is run we will only update the description on `push` events to the `develop` branch. This will ensure that only approved edits are pushed to Docker Hub. --- .github/workflows/build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 50419d7..c1697e5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -439,7 +439,8 @@ jobs: tags: ${{ needs.prepare.outputs.tags }} # For a list of pre-defined annotation keys and value types see: # https://github.com/opencontainers/image-spec/blob/master/annotations.md - - name: Update the Docker Hub description + - if: ${{ github.ref_name == 'develop' && github.event_name == 'push' }} + name: Update the Docker Hub description uses: peter-evans/dockerhub-description@v4 with: description: README.md