59 Commits

Author SHA1 Message Date
Peter Evans
4b076256d2 Merge pull request #33 from jennydaman/lowercase
Some checks failed
Publish Docker Image / publish (push) Has been cancelled
Convert repository to lower case
2021-02-05 10:18:20 +09:00
Jennings Zhang
d4e0800ec5 Convert repository to lower case 2021-02-03 19:58:54 -05:00
Peter Evans
91342cc8a6 Merge pull request #30 from peter-evans/update-distribution
Update distribution
2020-12-28 10:15:06 +09:00
peter-evans
6443116500 build: update distribution 2020-12-28 01:06:26 +00:00
Peter Evans
445b7e95b6 Merge pull request #21 from peter-evans/update-dependencies
Update dependencies
2020-12-28 10:05:23 +09:00
actions-bot
cdce24d19d chore: update dependencies 2020-12-24 02:02:44 +00:00
Peter Evans
dc17467ac6 Merge pull request #25 from peter-evans/dependabot/npm_and_yarn/node-notifier-8.0.1
Bump node-notifier from 8.0.0 to 8.0.1
2020-12-23 09:46:03 +09:00
dependabot[bot]
4b080f0994 Bump node-notifier from 8.0.0 to 8.0.1
Bumps [node-notifier](https://github.com/mikaelbr/node-notifier) from 8.0.0 to 8.0.1.
- [Release notes](https://github.com/mikaelbr/node-notifier/releases)
- [Changelog](https://github.com/mikaelbr/node-notifier/blob/v8.0.1/CHANGELOG.md)
- [Commits](https://github.com/mikaelbr/node-notifier/compare/v8.0.0...v8.0.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-23 00:16:38 +00:00
Peter Evans
1d0dd5623c Merge pull request #23 from peter-evans/fix-error-handling
Some checks failed
Publish Docker Image / publish (push) Has been cancelled
fix: throw errors on request failure
2020-10-27 10:44:08 +09:00
Peter Evans
8dd2813668 fix: throw errors on request failure 2020-10-27 10:41:21 +09:00
Peter Evans
dac62d382a Merge pull request #20 from peter-evans/update-distribution
Update distribution
2020-10-02 15:49:36 +09:00
peter-evans
c4ad60f25c build: update distribution 2020-10-02 06:49:03 +00:00
Peter Evans
3cf73e9a56 Merge pull request #19 from peter-evans/dependabot/npm_and_yarn/actions/core-1.2.6
Bump @actions/core from 1.2.5 to 1.2.6
2020-10-02 15:47:55 +09:00
dependabot[bot]
227aa80eb9 Bump @actions/core from 1.2.5 to 1.2.6
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-02 06:32:40 +00:00
Peter Evans
17abc79f55 ci: fix input names
Some checks failed
Publish Docker Image / publish (push) Has been cancelled
2020-09-25 15:48:51 +09:00
Peter Evans
dd8b1b1548 Merge pull request #18 from peter-evans/typescript
refactor: convert to typescript
2020-09-25 15:43:53 +09:00
Peter Evans
d5f4187668 ci: add short-description input to test 2020-09-25 15:32:07 +09:00
Peter Evans
8fa8201677 feat: add input for short description 2020-09-25 15:22:36 +09:00
Peter Evans
9db4dd4244 docs: add repository input default 2020-09-25 14:42:31 +09:00
Peter Evans
68960cdd4c style: move input defaults together 2020-09-25 14:41:18 +09:00
Peter Evans
63eba8b40c docs: update readme 2020-09-25 11:38:47 +09:00
Peter Evans
03c1121463 ci: tag docker with major version 2020-09-25 11:32:57 +09:00
Peter Evans
6cde3510ab ci: fix input names 2020-09-25 11:17:27 +09:00
Peter Evans
ad0054eb7a refactor: rename inputs 2020-09-25 11:13:16 +09:00
Peter Evans
08f06f46d8 ci: add workflow to publish docker image 2020-09-24 16:20:22 +09:00
Peter Evans
33cc80a90a refactor: update image to execute action with node 2020-09-23 17:23:10 +09:00
Peter Evans
65f339015f ci: update tests 2020-09-23 16:08:37 +09:00
Peter Evans
8d41514320 ci: update commit messages 2020-09-23 16:03:18 +09:00
Peter Evans
ac036cd74b refactor: convert to typescript 2020-09-23 15:58:54 +09:00
Peter Evans
cd1a929ab8 Update workflow 2020-09-09 13:36:13 +09:00
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
23 changed files with 9224 additions and 149 deletions

View File

@@ -1,70 +0,0 @@
version: 2.1
executors:
docker-executor:
environment:
IMAGE_NAME: peterevans/dockerhub-description
docker:
- image: circleci/buildpack-deps:stretch
jobs:
build:
executor: docker-executor
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Build Docker image
command: |
docker build -t $IMAGE_NAME:latest . --label "org.opencontainers.image.version=${CIRCLE_TAG/v/''}"
- run:
name: Cache Docker image
command: docker save -o image.tar $IMAGE_NAME
- persist_to_workspace:
root: .
paths:
- ./image.tar
publish-tag:
executor: docker-executor
steps:
- attach_workspace:
at: /tmp/workspace
- setup_remote_docker
- run:
name: Load cached Docker image
command: docker load -i /tmp/workspace/image.tar
- run:
name: Publish Docker Image to Docker Hub
command: |
echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
IMAGE_TAG=${CIRCLE_TAG/v/''}
docker tag $IMAGE_NAME:latest $IMAGE_NAME:$IMAGE_TAG
docker push $IMAGE_NAME:latest
docker push $IMAGE_NAME:$IMAGE_TAG
# If the minor version can be extracted then tag and push
MINOR_VERSION=$(echo $CIRCLE_TAG | sed -n "s/^v\([0-9]*.[0-9]*\).[0-9]*$/\1/p")
if [[ ${#MINOR_VERSION} -gt 0 ]]; then
docker tag $IMAGE_NAME:latest $IMAGE_NAME:$MINOR_VERSION
docker push $IMAGE_NAME:$MINOR_VERSION
fi
workflows:
version: 2
build:
jobs:
- build
build-and-publish-tags:
jobs:
- build:
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
- publish-tag:
context: org-global
requires:
- build
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/

3
.eslintignore Normal file
View File

@@ -0,0 +1,3 @@
dist/
lib/
node_modules/

19
.eslintrc.json Normal file
View File

@@ -0,0 +1,19 @@
{
"env": { "node": true, "jest": true },
"parser": "@typescript-eslint/parser",
"parserOptions": { "ecmaVersion": 9, "sourceType": "module" },
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/camelcase": "off"
}
}

99
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,99 @@
name: CI
on:
push:
branches: [master]
paths-ignore:
- 'README.md'
- 'docs/**'
pull_request:
branches: [master]
paths-ignore:
- 'README.md'
- 'docs/**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm ci
- run: npm run build
- run: npm run format-check
- run: npm run lint
- run: npm run test
- uses: actions/upload-artifact@v2
with:
name: dist
path: dist
- uses: actions/upload-artifact@v2
with:
name: action.yml
path: action.yml
test:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
needs: [build]
runs-on: ubuntu-latest
strategy:
matrix:
target: [built, committed]
steps:
- uses: actions/checkout@v2
- if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v2
with:
name: dist
path: dist
- if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v2
with:
name: action.yml
path: .
# Tests
- name: Prepare non-default filepath
run: |
mkdir -p some/path
cp README.md some/path/TEST.md
- name: Docker Hub Description (with)
uses: ./
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: peterevans/dd-ci-fixture-${{ matrix.target }}
short-description: ${{ matrix.target }} test fixture for dockerhub-description action
readme-filepath: ./some/path/TEST.md
- name: Docker Hub Description (env)
uses: ./
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/dd-ci-fixture-${{ matrix.target }}
package:
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: dist
path: dist
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
commit-message: 'build: update distribution'
title: Update distribution
body: |
- Updates the distribution for changes on `master`
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: update-distribution

View File

@@ -0,0 +1,26 @@
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: Modify readme for DockerHub
run: |
sed -i 's/# Docker Hub Description/# [Docker Hub Description](https:\/\/github.com\/peter-evans\/dockerhub-description)/' README.md
sed -i 's/(LICENSE)/(https:\/\/github.com\/peter-evans\/dockerhub-description\/blob\/master\/LICENSE)/' README.md
- name: Docker Hub Description
uses: ./
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: peterevans/dockerhub-description

41
.github/workflows/publish-docker.yml vendored Normal file
View File

@@ -0,0 +1,41 @@
name: Publish Docker Image
on:
push:
branches:
- master
tags:
- v*
env:
IMAGE_NAME: peterevans/dockerhub-description
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Docker Hub login
run: echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
- name: Push image to Docker Hub
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
# Build and tag image
docker build . --file Dockerfile --tag $IMAGE_NAME --label "org.opencontainers.image.version=$VERSION"
docker tag $IMAGE_NAME $IMAGE_NAME:$VERSION
# Tag with the minor version if valid
MINOR_VERSION=$(echo $VERSION | sed -n "s/^\([0-9]*.[0-9]*\).[0-9]*$/\1/p")
[[ ${#MINOR_VERSION} -gt 0 ]] && docker tag $IMAGE_NAME $IMAGE_NAME:$MINOR_VERSION
# Tag with the major version if valid
MAJOR_VERSION=$(echo $VERSION | sed -n "s/^\([0-9]*\).[0-9]*.[0-9]*$/\1/p")
[[ ${#MAJOR_VERSION} -gt 0 ]] && docker tag $IMAGE_NAME $IMAGE_NAME:$MAJOR_VERSION
docker push $IMAGE_NAME

View File

@@ -1,16 +0,0 @@
name: Update Docker Hub Description
on:
push:
branches:
- master
jobs:
dockerHubDescription:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Docker Hub Description
uses: ./
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description

31
.github/workflows/update-dep.yml vendored Normal file
View File

@@ -0,0 +1,31 @@
name: Update Dependencies
on:
schedule:
- cron: '0 1 * * 4'
jobs:
update-dep:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Update dependencies
run: |
npx -p npm-check-updates ncu -u
npm install
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
commit-message: 'chore: update dependencies'
committer: GitHub <noreply@github.com>
author: actions-bot <actions-bot@users.noreply.github.com>
title: Update dependencies
body: |
- Dependency updates
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: update-dependencies

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
lib/
node_modules/

3
.prettierignore Normal file
View File

@@ -0,0 +1,3 @@
dist/
lib/
node_modules/

11
.prettierrc.json Normal file
View File

@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}

View File

@@ -1,16 +1,18 @@
FROM peterevans/curl-jq:1.0.1
FROM node:12-alpine
LABEL maintainer="Peter Evans <mail@peterevans.dev>"
LABEL repository="https://github.com/peter-evans/dockerhub-description"
LABEL homepage="https://github.com/peter-evans/dockerhub-description"
LABEL com.github.actions.name="Docker Hub Description"
LABEL com.github.actions.description="An action to update a Docker Hub repository description from README.md"
LABEL com.github.actions.icon="upload"
LABEL com.github.actions.color="blue"
LABEL \
maintainer="Peter Evans <mail@peterevans.dev>" \
org.opencontainers.image.title="dockerhub-description" \
org.opencontainers.image.description="An action to update a Docker Hub repository description from README.md" \
org.opencontainers.image.authors="Peter Evans <mail@peterevans.dev>" \
org.opencontainers.image.url="https://github.com/peter-evans/dockerhub-description" \
org.opencontainers.image.vendor="https://peterevans.dev" \
org.opencontainers.image.licenses="MIT"
COPY LICENSE README.md /
COPY dist/index.js /index.js
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -1,6 +1,5 @@
# 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)
[![CircleCI](https://circleci.com/gh/peter-evans/dockerhub-description/tree/master.svg?style=svg)](https://circleci.com/gh/peter-evans/dockerhub-description/tree/master)
A GitHub action to update a Docker Hub repository description from `README.md`.
@@ -10,59 +9,69 @@ This is useful if you `docker push` your images to Docker Hub. It provides an ea
```yml
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v1.0.1
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
uses: peter-evans/dockerhub-description@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: peterevans/dockerhub-description
```
#### Required environment variables
### Action inputs
- `DOCKERHUB_USERNAME` - Docker Hub username
- `DOCKERHUB_PASSWORD` - Docker Hub password
- `DOCKERHUB_REPOSITORY` - The Docker Hub repository to update in the format `<namespace>/<name>`
**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 2FA on Docker Hub will prevent the action from working.
Note that `DOCKERHUB_REPOSITORY` may also be passed as a secret if considered sensitive.
| Name | Description | Default |
| --- | --- | --- |
| `username` | (**required**) Docker Hub username. If updating a Docker Hub repository belonging to an organization, this user must have `Admin` permissions for the repository. | |
| `password` | (**required**) Docker Hub password. | |
| `repository` | Docker Hub repository in the format `<namespace>/<name>`. | `github.repository` |
| `short-description` | Docker Hub repository short description. Input exceeding 100 characters will be truncated. | |
| `readme-filepath` | Path to the repository readme. | `./README.md` |
#### Optionally specifying the file path
#### Specifying the file path
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 specified with the `readme-filepath` input.
```yml
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v1.0.1
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
README_FILEPATH: ./some-path/README.md
uses: peter-evans/dockerhub-description@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: peterevans/dockerhub-description
readme-filepath: ./path/to/README.md
```
#### Examples
### Examples
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`.
Updates the Docker Hub repository description whenever there is a `git push` to the `master` branch.
```yml
name: Update Docker Hub Description
on:
push:
branches:
- master
- master
paths:
- README.md
- .github/workflows/dockerhub-description.yml
jobs:
dockerHubDescription:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v2
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v1.0.1
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
uses: peter-evans/dockerhub-description@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: peterevans/dockerhub-description
```
Updates the Docker Hub repository description whenever a new release is created.
```yml
name: Update Docker Hub Description
on: release
@@ -70,13 +79,14 @@ jobs:
dockerHubDescription:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v2
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v1.0.1
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
uses: peter-evans/dockerhub-description@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: peterevans/dockerhub-description
```
## Using the Docker image independently of GitHub Actions
@@ -90,9 +100,9 @@ docker run -v $PWD:/workspace \
-e DOCKERHUB_PASSWORD='xxxxx' \
-e DOCKERHUB_REPOSITORY='user1/my-docker-image' \
-e README_FILEPATH='/workspace/README.md' \
peterevans/dockerhub-description:1.0.1
peterevans/dockerhub-description:2
```
## License
MIT License - see the [LICENSE](LICENSE) file for details
[MIT](LICENSE)

28
action.yml Normal file
View File

@@ -0,0 +1,28 @@
name: 'Docker Hub Description'
author: 'Peter Evans'
description: 'An action to update a Docker Hub repository description from README.md'
inputs:
username:
description: Docker Hub username
required: true
password:
description: Docker Hub password
required: true
repository:
description: >
Docker Hub repository in the format `<namespace>/<name>`
Default: `github.repository`
short-description:
description: >
Docker Hub repository short description
Input exceeding 100 characters will be truncated
readme-filepath:
description: >
Path to the repository readme
Default: `./README.md`
runs:
using: 'node12'
main: 'dist/index.js'
branding:
icon: 'upload'
color: 'blue'

2417
dist/index.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,23 +1,13 @@
#!/bin/sh -l
set -euo pipefail
set -eo pipefail
IFS=$'\n\t'
# Set the default path to README.md
README_FILEPATH=${README_FILEPATH:="./README.md"}
# Execute the action code and output to file
node index.js > action.log 2>&1
# 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)
# Remove lines containing sensitive information from the log
sed -i '/::debug::/d' ./action.log
sed -i '/::add-mask::/d' ./action.log
# Send a PATCH request to update the description of the repository
echo "Sending PATCH request"
REPO_URL="https://hub.docker.com/v2/repositories/${DOCKERHUB_REPOSITORY}/"
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"
if [ $RESPONSE_CODE -eq 200 ]; then
exit 0
else
exit 1
fi
# Output the log
cat action.log

11
jest.config.js Normal file
View File

@@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}

6232
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

48
package.json Normal file
View File

@@ -0,0 +1,48 @@
{
"name": "dockerhub-description",
"version": "3.0.0",
"private": true,
"description": "An action to update a Docker Hub repository description from README.md",
"main": "lib/main.js",
"scripts": {
"build": "tsc && ncc build",
"format": "prettier --write '**/*.ts'",
"format-check": "prettier --check '**/*.ts'",
"lint": "eslint src/**/*.ts",
"test": "jest --passWithNoTests"
},
"repository": {
"type": "git",
"url": "git+https://github.com/peter-evans/dockerhub-description.git"
},
"keywords": [
"actions",
"dockerhub",
"description"
],
"author": "Peter Evans",
"license": "MIT",
"bugs": {
"url": "https://github.com/peter-evans/dockerhub-description/issues"
},
"homepage": "https://github.com/peter-evans/dockerhub-description#readme",
"dependencies": {
"@actions/core": "1.2.6",
"node-fetch": "2.6.1"
},
"devDependencies": {
"@types/jest": "26.0.19",
"@types/node": "14.14.16",
"@typescript-eslint/parser": "4.11.0",
"@vercel/ncc": "0.26.1",
"eslint": "7.16.0",
"eslint-plugin-github": "4.1.1",
"eslint-plugin-jest": "24.1.3",
"jest": "26.6.3",
"jest-circus": "26.6.3",
"js-yaml": "3.14.1",
"prettier": "2.2.1",
"ts-jest": "26.4.4",
"typescript": "4.1.3"
}
}

48
src/dockerhub-helper.ts Normal file
View File

@@ -0,0 +1,48 @@
import * as core from '@actions/core'
import * as fetch from 'node-fetch'
const DESCRIPTION_MAX_CHARS = 100
export async function getToken(
username: string,
password: string
): Promise<string> {
const body = {
username: username,
password: password
}
const response = await fetch('https://hub.docker.com/v2/users/login', {
method: 'post',
body: JSON.stringify(body),
headers: {'Content-Type': 'application/json'}
})
const json = await response.json()
core.setSecret(json['token'])
return json['token']
}
export async function updateRepositoryDescription(
token: string,
repository: string,
description: string,
fullDescription: string
): Promise<void> {
const body = {
full_description: fullDescription
}
if (description) {
body['description'] = description.slice(0, DESCRIPTION_MAX_CHARS)
}
await fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
method: 'patch',
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json',
Authorization: `JWT ${token}`
}
}).then(res => {
if (!res.ok) {
throw new Error(res.statusText)
}
})
}

76
src/input-helper.ts Normal file
View File

@@ -0,0 +1,76 @@
import * as core from '@actions/core'
const README_FILEPATH_DEFAULT = './README.md'
interface Inputs {
username: string
password: string
repository: string
shortDescription: string
readmeFilepath: string
}
export function getInputs(): Inputs {
const inputs = {
username: core.getInput('username'),
password: core.getInput('password'),
repository: core.getInput('repository'),
shortDescription: core.getInput('short-description'),
readmeFilepath: core.getInput('readme-filepath')
}
// Environment variable input alternatives and their aliases
if (!inputs.username && process.env['DOCKERHUB_USERNAME']) {
inputs.username = process.env['DOCKERHUB_USERNAME']
}
if (!inputs.username && process.env['DOCKER_USERNAME']) {
inputs.username = process.env['DOCKER_USERNAME']
}
if (!inputs.password && process.env['DOCKERHUB_PASSWORD']) {
inputs.password = process.env['DOCKERHUB_PASSWORD']
}
if (!inputs.password && process.env['DOCKER_PASSWORD']) {
inputs.password = process.env['DOCKER_PASSWORD']
}
if (!inputs.repository && process.env['DOCKERHUB_REPOSITORY']) {
inputs.repository = process.env['DOCKERHUB_REPOSITORY']
}
if (!inputs.repository && process.env['DOCKER_REPOSITORY']) {
inputs.repository = process.env['DOCKER_REPOSITORY']
}
if (!inputs.shortDescription && process.env['SHORT_DESCRIPTION']) {
inputs.shortDescription = process.env['SHORT_DESCRIPTION']
}
if (!inputs.readmeFilepath && process.env['README_FILEPATH']) {
inputs.readmeFilepath = process.env['README_FILEPATH']
}
// Set defaults
if (!inputs.readmeFilepath) {
inputs.readmeFilepath = README_FILEPATH_DEFAULT
}
if (!inputs.repository && process.env['GITHUB_REPOSITORY']) {
inputs.repository = process.env['GITHUB_REPOSITORY']
}
// Docker repositories must be all lower case
inputs.repository = inputs.repository.toLowerCase()
return inputs
}
function checkRequiredInput(input: string, name: string): void {
if (!input) {
throw new Error(`Required input '${name}' is missing.`)
}
}
export function validateInputs(inputs: Inputs): void {
checkRequiredInput(inputs.username, 'username')
checkRequiredInput(inputs.password, 'password')
}

48
src/main.ts Normal file
View File

@@ -0,0 +1,48 @@
import * as core from '@actions/core'
import * as inputHelper from './input-helper'
import * as dockerhubHelper from './dockerhub-helper'
import * as fs from 'fs'
import {inspect, TextEncoder} from 'util'
const MAX_BYTES = 25000
async function run(): Promise<void> {
try {
const inputs = inputHelper.getInputs()
core.debug(`Inputs: ${inspect(inputs)}`)
inputHelper.validateInputs(inputs)
// Fetch the readme content
const readmeContent = await fs.promises.readFile(inputs.readmeFilepath, {
encoding: 'utf8'
})
const byteLength = new TextEncoder().encode(readmeContent).length
if (byteLength > MAX_BYTES) {
throw new Error(
`File size exceeds the maximum allowed ${MAX_BYTES} bytes`
)
}
// Acquire a token for the Docker Hub API
core.info('Acquiring token')
const token = await dockerhubHelper.getToken(
inputs.username,
inputs.password
)
// Send a PATCH request to update the description of the repository
core.info('Sending PATCH request')
await dockerhubHelper.updateRepositoryDescription(
token,
inputs.repository,
inputs.shortDescription,
readmeContent
)
core.info('Request successful')
} catch (error) {
core.debug(inspect(error))
core.setFailed(error.message)
}
}
run()

16
tsconfig.json Normal file
View File

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es6"
],
"outDir": "./lib",
"rootDir": "./src",
"declaration": true,
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true
},
"exclude": ["__test__", "lib", "node_modules"]
}