53 Commits

Author SHA1 Message Date
Peter Evans
f2b0643b95 Update workflow 2020-08-22 09:52:30 +09:00
Peter Evans
a6985f583c Update action version 2020-08-22 09:51:01 +09:00
Peter Evans
b6bd2fd8c2 Check the readme file exists 2020-08-22 09:46:01 +09:00
Peter Evans
b5167ca4ba Update action version 2020-08-02 17:32:37 +09:00
Peter Evans
10e602777f Output clearer action result message 2020-08-02 17:26:51 +09:00
Peter Evans
382a87f452 Update readme 2020-06-30 15:13:36 +09:00
Peter Evans
2799bbf86a Update action version 2020-06-30 15:10:39 +09:00
Peter Evans
432cd004b3 Merge pull request #12 from syntaqx/feature/env-compatibility
Compatibility with configuration sources used by other tools
2020-06-30 14:59:38 +09:00
Peter Evans
9313daeb2f Update required property in env comments 2020-06-30 14:58:32 +09:00
Chase Pierce
852d8b4b1f documentings envs as comments 2020-06-29 22:29:36 -06:00
Chase Pierce
b93f6fad1d add env compatibility with DOCKER_ prefixes 2020-06-29 19:47:16 -06:00
Peter Evans
6ffdd6905f Update README 2020-03-28 10:14:18 +09:00
Peter Evans
2739a0900f Update action version 2020-03-28 10:05:06 +09:00
Peter Evans
84d38211e2 Check if file size exceeds the max allowed 2020-03-28 09:52:49 +09:00
Peter Evans
abea83050d Update to checkout v2 2020-01-04 09:21:19 +09:00
Peter Evans
3361358488 Update README 2019-12-29 12:28:20 +09:00
Peter Evans
2774ff3d56 Update README 2019-12-25 12:29:43 +09:00
Peter Evans
b03d823861 Update README 2019-11-10 21:59:08 +09:00
Peter Evans
6de5e14b55 Update workflow 2019-11-10 21:57:41 +09:00
Peter Evans
5b8fd77939 Update workflow 2019-10-29 00:52:05 +09:00
Peter Evans
81f3992e82 Update workflow 2019-10-29 00:50:55 +09:00
Peter Evans
5e7108e09c Update README 2019-10-03 16:52:08 +09:00
Peter Evans
f87713fbd6 Update README 2019-10-03 16:51:29 +09:00
Peter Evans
7567c7b51b Merge pull request #4 from peter-evans/container-action-update
Update for Actions v2
2019-10-03 16:46:09 +09:00
Peter Evans
861e7a6d6a Remove circleci config 2019-10-03 16:39:54 +09:00
Peter Evans
97941981d1 Update workflow 2019-10-03 16:38:36 +09:00
Peter Evans
7041d8f35d Add action.yml for Actions v2 2019-10-03 16:33:09 +09:00
Peter Evans
843595a14f Update README 2019-08-27 12:01:15 +09:00
Peter Evans
aa956b3fe8 Update README 2019-08-22 11:02:17 +09:00
Peter Evans
e27c9c84cb Update README 2019-08-22 10:56:12 +09:00
Peter Evans
26be7144b7 Update workflow 2019-08-22 10:53:31 +09:00
Peter Evans
704c6b40c4 Don't include username in repository path 2019-08-22 10:51:29 +09:00
Peter Evans
60c3aacb17 Update README 2019-08-12 17:31:07 +09:00
Peter Evans
69ba977c50 Update workflow 2019-08-12 17:30:59 +09:00
Peter Evans
a556e80cb3 Update README 2019-08-12 14:18:43 +09:00
Peter Evans
96ab422aa6 Convert main.workflow to v2 yml 2019-08-12 14:18:06 +09:00
Peter Evans
09a017779e Remove duplicate flag 2019-07-07 16:19:29 +09:00
Peter Evans
9baceaf7be Update README 2019-07-01 22:27:07 +09:00
Peter Evans
30d779d1a8 Update README 2019-06-30 13:10:08 +09:00
Peter Evans
8a5806631a Update README 2019-06-30 11:17:55 +09:00
Peter Evans
66277dfaec Add circleci config 2019-06-30 10:56:03 +09:00
Peter Evans
5a618d1434 Update base image 2019-06-29 11:08:25 +09:00
Peter Evans
ba4f12bfe1 Fix copy directive 2019-06-29 11:08:06 +09:00
Peter Evans
7f8bdc5174 Update README 2019-06-26 20:41:46 +09:00
Peter Evans
2cdc04310b Update main.workflow 2019-06-26 20:41:30 +09:00
Peter Evans
766da51375 Update main.workflow 2019-06-26 20:34:04 +09:00
Peter Evans
49d8359332 Update main.workflow 2019-06-26 20:28:22 +09:00
Peter Evans
b2856ab64f Update README 2019-06-26 07:49:55 +09:00
Peter Evans
ef7baa2fee Update README examples 2019-06-25 21:10:05 +09:00
Peter Evans
5f19c66987 Update main.workflow 2019-06-25 20:35:40 +09:00
Peter Evans
9e8150a63d Update main.workflow 2019-06-25 20:18:14 +09:00
Peter Evans
ff4c066a7a Update README 2019-06-25 19:57:50 +09:00
Peter Evans
0f1898c5f3 Update README 2019-06-25 19:53:47 +09:00
5 changed files with 158 additions and 48 deletions

View File

@@ -0,0 +1,25 @@
name: Update Docker Hub Description
on:
workflow_dispatch:
push:
branches:
- master
paths:
- README.md
- .github/workflows/dockerhub-description.yml
jobs:
dockerHubDescription:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Copy README.md to TEST.md
run: |
mkdir -p some/path
mv README.md some/path/TEST.md
- name: Docker Hub Description
uses: ./
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
README_FILEPATH: ./some/path/TEST.md

View File

@@ -1,4 +1,4 @@
FROM peterevans/curl-jq:1.0.0 FROM peterevans/curl-jq:1.0.1
LABEL maintainer="Peter Evans <mail@peterevans.dev>" LABEL maintainer="Peter Evans <mail@peterevans.dev>"
LABEL repository="https://github.com/peter-evans/dockerhub-description" LABEL repository="https://github.com/peter-evans/dockerhub-description"
@@ -9,7 +9,7 @@ LABEL com.github.actions.description="An action to update a Docker Hub repositor
LABEL com.github.actions.icon="upload" LABEL com.github.actions.icon="upload"
LABEL com.github.actions.color="blue" LABEL com.github.actions.color="blue"
COPY LICENSE README.md COPY LICENSE README.md /
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh

115
README.md
View File

@@ -1,4 +1,5 @@
# Docker Hub Description # Docker Hub Description
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Docker%20Hub%20Description-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/marketplace/actions/docker-hub-description)
A GitHub action to update a Docker Hub repository description from `README.md`. A GitHub action to update a Docker Hub repository description from `README.md`.
@@ -6,68 +7,96 @@ This is useful if you `docker push` your images to Docker Hub. It provides an ea
## Usage ## Usage
``` ```yml
action "Update Docker Hub Repository Description" { - name: Docker Hub Description
uses = "peter-evans/dockerhub-description@master" uses: peter-evans/dockerhub-description@v2
secrets = ["DOCKERHUB_USERNAME", "DOCKERHUB_PASSWORD", "DOCKERHUB_REPOSITORY"] env:
} DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
``` ```
#### Required secrets #### Required environment variables
- `DOCKERHUB_USERNAME` - Docker Hub username - `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 - `DOCKERHUB_PASSWORD` - Docker Hub password. Fallback to `DOCKER_PASSWORD` if set. Aliases: `DOCKER_PASSWORD`
- `DOCKERHUB_REPOSITORY` - The name of the Docker Hub repository to update. (This may also be an environment variable if not considered sensitive) - `DOCKERHUB_REPOSITORY` - The Docker Hub repository to update in the format `<namespace>/<name>`. 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.
#### Optionally specifying the file path #### Optionally specifying the file path
The action assumes that there is a file called `README.md` located at the root of the repository. The action assumes that there is a file called `README.md` located at the root of the repository.
If this is not the case, the path can be overridden with an environment variable. If this is not the case, the path can be overridden with an environment variable.
``` ```yml
action "Update Docker Hub Repository Description" { - name: Docker Hub Description
uses = "peter-evans/dockerhub-description@master" uses: peter-evans/dockerhub-description@v2
secrets = ["DOCKERHUB_USERNAME", "DOCKERHUB_PASSWORD", "DOCKERHUB_REPOSITORY"] env:
env = { DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
README_FILEPATH = "./some-path/README.md" DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
} DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
} README_FILEPATH: ./some-path/README.md
``` ```
#### Examples #### Examples
Updates the Docker Hub repository description whenever there is a `git push` to the `master` branch. The following workflow updates the Docker Hub repository description whenever there are changes to `README.md` and the workflow file itself on the `master` branch. This workflow assumes its location to be `.github/workflows/dockerhub-description.yml`.
```
workflow "New workflow" {
on = "push"
resolves = ["Update Docker Hub Repository Description"]
}
action "Filter master branch" { ```yml
uses = "actions/bin/filter@master" name: Update Docker Hub Description
args = "branch master" on:
} push:
branches:
action "Update Docker Hub Repository Description" { - master
needs = ["Filter master branch"] paths:
uses = "peter-evans/dockerhub-description@master" - README.md
secrets = ["DOCKERHUB_USERNAME", "DOCKERHUB_PASSWORD", "DOCKERHUB_REPOSITORY"] - .github/workflows/dockerhub-description.yml
} jobs:
dockerHubDescription:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v2
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
``` ```
Updates the Docker Hub repository description whenever a new release is created. Updates the Docker Hub repository description whenever a new release is created.
```
workflow "New workflow" {
on = "release"
resolves = ["Update Docker Hub Repository Description"]
}
action "Update Docker Hub Repository Description" { ```yml
uses = "peter-evans/dockerhub-description@master" name: Update Docker Hub Description
secrets = ["DOCKERHUB_USERNAME", "DOCKERHUB_PASSWORD", "DOCKERHUB_REPOSITORY"] on: release
} jobs:
dockerHubDescription:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v2
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
```
## Using the Docker image independently of GitHub Actions
The image can be executed in other environments independently of GitHub Actions.
Simply volume mount the location of the `README.md` file to the container and set environment variables as follows.
```bash
docker run -v $PWD:/workspace \
-e DOCKERHUB_USERNAME='user1' \
-e DOCKERHUB_PASSWORD='xxxxx' \
-e DOCKERHUB_REPOSITORY='user1/my-docker-image' \
-e README_FILEPATH='/workspace/README.md' \
peterevans/dockerhub-description:2.3
``` ```
## License ## License
MIT License - see the [LICENSE](LICENSE) file for details [MIT](LICENSE)

22
action.yml Normal file
View File

@@ -0,0 +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: true
# DOCKERHUB_PASSWORD:
# description: Password to login to Docker Hub. Aliases: DOCKER_PASSWORD
# required: true
# DOCKERHUB_REPOSITORY:
# description: Explicit Docker Hub repository name. Aliases: DOCKER_REPOSITORY, GITHUB_REPOSITORY
# required: true
# README_FILEPATH:
# description: Path to the repository readme.
# default: ./README.md
runs:
using: 'docker'
image: 'docker://peterevans/dockerhub-description:2.3.1'
branding:
icon: 'upload'
color: 'blue'

View File

@@ -1,10 +1,42 @@
#!/bin/sh -l #!/bin/sh -l
set -euo pipefail set -eo pipefail
IFS=$'\n\t' 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 # Set the default path to README.md
README_FILEPATH=${README_FILEPATH:="./README.md"} README_FILEPATH=${README_FILEPATH:="./README.md"}
# Check the file exists
if [ ! -f ${README_FILEPATH} ]; then
echo "Readme file not found"
exit 1
fi
# Check the file size
if [ $(wc -c <${README_FILEPATH}) -gt 25000 ]; then
echo "File size exceeds the maximum allowed 25000 bytes"
exit 1
fi
# Acquire a token for the Docker Hub API # Acquire a token for the Docker Hub API
echo "Acquiring token" echo "Acquiring token"
LOGIN_PAYLOAD="{\"username\": \"${DOCKERHUB_USERNAME}\", \"password\": \"${DOCKERHUB_PASSWORD}\"}" LOGIN_PAYLOAD="{\"username\": \"${DOCKERHUB_USERNAME}\", \"password\": \"${DOCKERHUB_PASSWORD}\"}"
@@ -12,12 +44,14 @@ TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d ${LOGIN_PAYLOAD}
# Send a PATCH request to update the description of the repository # Send a PATCH request to update the description of the repository
echo "Sending PATCH request" echo "Sending PATCH request"
REPO_URL="https://hub.docker.com/v2/repositories/${DOCKERHUB_USERNAME}/${DOCKERHUB_REPOSITORY}/" REPO_URL="https://hub.docker.com/v2/repositories/${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}) RESPONSE_CODE=$(curl -s --write-out %{response_code} --output /dev/null -H "Authorization: JWT ${TOKEN}" -X PATCH --data-urlencode full_description@${README_FILEPATH} ${REPO_URL})
echo "Received response code: $RESPONSE_CODE" echo "Received response code: $RESPONSE_CODE"
if [ $RESPONSE_CODE -eq 200 ]; then if [ $RESPONSE_CODE -eq 200 ]; then
echo "Request successful"
exit 0 exit 0
else else
echo "Request failed"
exit 1 exit 1
fi fi