From b93f6fad1d7d4bf9907b5121c4824e0a085abe81 Mon Sep 17 00:00:00 2001 From: Chase Pierce Date: Mon, 29 Jun 2020 19:47:16 -0600 Subject: [PATCH 1/3] add env compatibility with DOCKER_ prefixes --- README.md | 6 +++--- action.yml | 12 +++++++++++- entrypoint.sh | 22 +++++++++++++++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 72fcef7..91ee064 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ This is useful if you `docker push` your images to Docker Hub. It provides an ea #### Required environment variables -- `DOCKERHUB_USERNAME` - Docker Hub username. If updating a Docker Hub repository belonging to an organization, this user must have `Admin` permissions for the repository. -- `DOCKERHUB_PASSWORD` - Docker Hub password. -- `DOCKERHUB_REPOSITORY` - The Docker Hub repository to update in the format `/`. May also be passed as a secret if considered sensitive. +- `DOCKERHUB_USERNAME` - Docker Hub username. If updating a Docker Hub repository belonging to an organization, this user must have `Admin` permissions for the repository. Aliases: `DOCKER_USERNAME` +- `DOCKERHUB_PASSWORD` - Docker Hub password. Fallback to `DOCKER_PASSWORD` if set. Aliases: `DOCKER_PASSWORD` +- `DOCKERHUB_REPOSITORY` - The Docker Hub repository to update in the format `/`. May also be passed as a secret if considered sensitive. Aliases: `DOCKER_REPOSITORY`, `GITHUB_REPOSITORY` **Note**: Docker Hub [Personal Access Tokens](https://docs.docker.com/docker-hub/access-tokens/) cannot be used as they are not supported by the API. See [here](https://github.com/docker/hub-feedback/issues/1927) and [here](https://github.com/docker/hub-feedback/issues/1914) for further details. Unfortunately, this means that enabling the new 2FA feature on Docker Hub will prevent the action from working. diff --git a/action.yml b/action.yml index 1d99d5c..3010b66 100644 --- a/action.yml +++ b/action.yml @@ -5,5 +5,15 @@ runs: using: 'docker' image: 'docker://peterevans/dockerhub-description:2.1.1' branding: - icon: 'upload' + icon: 'upload' color: 'blue' +inputs: + dockerhubUsername: + description: Username to login to Docker Hub. Aliases: DOCKER_USERNAME + required: false + dockerhubPassword: + description: Password to login to Docker Hub. Aliases: DOCKER_PASSWORD + required: false + dockerhubRepository: + description: Explicit Docker Hub repository name. Aliases: DOCKER_REPOSITORY, GITHUB_REPOSITORY + required: false diff --git a/entrypoint.sh b/entrypoint.sh index f70aaf8..88d3db9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,27 @@ #!/bin/sh -l -set -euo pipefail +set -eo pipefail IFS=$'\n\t' +# Allow DOCKERHUB_* variables to be set from their DOCKER_* variant +DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-${DOCKER_USERNAME}} +DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD:-${DOCKER_PASSWORD}} +DOCKERHUB_REPOSITORY=${DOCKERHUB_REPOSITORY:-${DOCKER_REPOSITORY}} + +# If the repository isn't explicitly defined, infer it from GitHub if possible +DOCKERHUB_REPOSITORY=${DOCKERHUB_REPOSITORY:-${GITHUB_REPOSITORY}} + +# Validate we can authenticate +if [ -z "$DOCKERHUB_USERNAME" ] || [ -z "$DOCKERHUB_PASSWORD" ]; then + echo 'Unable to authenticate with Docker Hub, set a valid $DOCKERHUB_USERNAME and $DOCKERHUB_PASSWORD' + exit 1 +fi + +# Validate we have the repository name +if [ -z "$DOCKERHUB_REPOSITORY" ]; then + echo 'Unable to determine Docker Hub repository name, set with $DOCKERHUB_REPOSITORY' + exit 1 +fi + # Set the default path to README.md README_FILEPATH=${README_FILEPATH:="./README.md"} From 852d8b4b1ff133bb1681a9134ff2781aa54816f0 Mon Sep 17 00:00:00 2001 From: Chase Pierce Date: Mon, 29 Jun 2020 22:29:36 -0600 Subject: [PATCH 2/3] documentings envs as comments --- action.yml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/action.yml b/action.yml index 3010b66..54d5bfd 100644 --- a/action.yml +++ b/action.yml @@ -1,19 +1,22 @@ name: 'Docker Hub Description' author: 'Peter Evans' description: 'An action to update a Docker Hub repository description from README.md' +# env: +# DOCKERHUB_USERNAME: +# description: Username to login to Docker Hub. Aliases: DOCKER_USERNAME +# required: false +# DOCKERHUB_PASSWORD: +# description: Password to login to Docker Hub. Aliases: DOCKER_PASSWORD +# required: false +# DOCKERHUB_REPOSITORY: +# description: Explicit Docker Hub repository name. Aliases: DOCKER_REPOSITORY, GITHUB_REPOSITORY +# required: false +# README_FILEPATH: +# description: Path to the repository readme. +# default: ./README.md runs: using: 'docker' image: 'docker://peterevans/dockerhub-description:2.1.1' branding: icon: 'upload' color: 'blue' -inputs: - dockerhubUsername: - description: Username to login to Docker Hub. Aliases: DOCKER_USERNAME - required: false - dockerhubPassword: - description: Password to login to Docker Hub. Aliases: DOCKER_PASSWORD - required: false - dockerhubRepository: - description: Explicit Docker Hub repository name. Aliases: DOCKER_REPOSITORY, GITHUB_REPOSITORY - required: false From 9313daeb2f0dcc801a43dfbe39b2902255154b5f Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Tue, 30 Jun 2020 14:58:32 +0900 Subject: [PATCH 3/3] Update required property in env comments --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 54d5bfd..28cc492 100644 --- a/action.yml +++ b/action.yml @@ -4,13 +4,13 @@ description: 'An action to update a Docker Hub repository description from READM # env: # DOCKERHUB_USERNAME: # description: Username to login to Docker Hub. Aliases: DOCKER_USERNAME -# required: false +# required: true # DOCKERHUB_PASSWORD: # description: Password to login to Docker Hub. Aliases: DOCKER_PASSWORD -# required: false +# required: true # DOCKERHUB_REPOSITORY: # description: Explicit Docker Hub repository name. Aliases: DOCKER_REPOSITORY, GITHUB_REPOSITORY -# required: false +# required: true # README_FILEPATH: # description: Path to the repository readme. # default: ./README.md