From 712df2e4b0b6007f1e7af261659a90a2a3b276d9 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Tue, 25 Jun 2019 19:22:11 +0900 Subject: [PATCH] Add image --- Dockerfile | 18 ++++++++++++++++++ entrypoint.sh | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 Dockerfile create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7a3fcd8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM peterevans/curl-jq:1.0.0 + +LABEL \ + maintainer="Peter Evans " \ + repository="https://github.com/peter-evans/dockerhub-description" \ + homepage="https://github.com/peter-evans/dockerhub-description" + +LABEL \ + com.github.actions.name="Docker Hub Description" \ + com.github.actions.description="An action to update a Docker Hub repository description from README.md" \ + com.github.actions.icon="upload" \ + com.github.actions.color="blue" + +COPY LICENSE README.md + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..44fd8de --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/sh -l +set -euo pipefail +IFS=$'\n\t' + +# Set the default path to README.md +README_FILEPATH=${README_FILEPATH:="./README.md"} + +# Acquire a token for the Docker Hub API +echo "Acquiring token" +LOGIN_PAYLOAD="{\"username\": \"${DOCKERHUB_USERNAME}\", \"password\": \"${DOCKERHUB_PASSWORD}\"}" +TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d ${LOGIN_PAYLOAD} https://hub.docker.com/v2/users/login/ | jq -r .token) + +# Send a PATCH request to update the description of the repository +echo "Sending PATCH request" +REPO_URL="https://hub.docker.com/v2/repositories/${DOCKERHUB_USERNAME}/${DOCKERHUB_REPOSITORY}/" +RESPONSE_CODE=$(curl -s --write-out %{response_code} --silent --output /dev/null -H "Authorization: JWT ${TOKEN}" -X PATCH --data-urlencode full_description@${README_FILEPATH} ${REPO_URL}) +echo "Received response code: $RESPONSE_CODE" + +if [ $RESPONSE_CODE -eq 200 ]; then + exit 0 +else + exit 1 +fi