Compare commits
117 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93b93397c2 | ||
|
|
3103d1465d | ||
|
|
0b9f9c4786 | ||
|
|
3b9f4f25f0 | ||
|
|
1488116043 | ||
|
|
4fd465609e | ||
|
|
9404f28f56 | ||
|
|
eef18f85b1 | ||
|
|
db792ed6c9 | ||
|
|
4fdf852815 | ||
|
|
bc97286b92 | ||
|
|
b2ff61bdb1 | ||
|
|
c908a72eaf | ||
|
|
2c9ccb12d6 | ||
|
|
27a09e0234 | ||
|
|
da890086d3 | ||
|
|
afa309ec72 | ||
|
|
22ceabb390 | ||
|
|
5edfa5bd9e | ||
|
|
1cf9afbac3 | ||
|
|
8a5577cb53 | ||
|
|
836d7e6aa8 | ||
|
|
6c2330d495 | ||
|
|
7e2c013575 | ||
|
|
451dfdc2a0 | ||
|
|
72b5f8eb8c | ||
|
|
142e236b5b | ||
|
|
89908cabb5 | ||
|
|
d8b35356f3 | ||
|
|
b73baad189 | ||
|
|
2f090b7665 | ||
|
|
05c1ee4f23 | ||
|
|
051fe81a00 | ||
|
|
71d921164d | ||
|
|
675b619ca6 | ||
|
|
ff044ee025 | ||
|
|
2ad1a4749f | ||
|
|
b9a0540444 | ||
|
|
ec57f928ad | ||
|
|
86903dfeb9 | ||
|
|
ebf083452f | ||
|
|
0940284a04 | ||
|
|
27aaeae4e5 | ||
|
|
c827149363 | ||
|
|
0151f40476 | ||
|
|
31c84f79aa | ||
|
|
d43a08dfeb | ||
|
|
616d1b63e8 | ||
|
|
76c5a90afd | ||
|
|
ae9aa33b7a | ||
|
|
54a7a303dd | ||
|
|
73ac163f37 | ||
|
|
582deb1a76 | ||
|
|
af2d781270 | ||
|
|
c9ab1334ce | ||
|
|
acbe71233a | ||
|
|
9c6c243f1d | ||
|
|
789f11f261 | ||
|
|
b45eba2bbb | ||
|
|
95dee52e1c | ||
|
|
041efd9199 | ||
|
|
f7242b77a5 | ||
|
|
da75b33366 | ||
|
|
7dedddda13 | ||
|
|
bc29825a35 | ||
|
|
9aa16a4f71 | ||
|
|
a5a2b94bf3 | ||
|
|
fe4fd29897 | ||
|
|
1087364d83 | ||
|
|
e9afc858d8 | ||
|
|
97e5f46ce8 | ||
|
|
9627b85954 | ||
|
|
78d978464e | ||
|
|
71b8c97334 | ||
|
|
773f327409 | ||
|
|
4b076256d2 | ||
|
|
d4e0800ec5 | ||
|
|
91342cc8a6 | ||
|
|
6443116500 | ||
|
|
445b7e95b6 | ||
|
|
cdce24d19d | ||
|
|
dc17467ac6 | ||
|
|
4b080f0994 | ||
|
|
1d0dd5623c | ||
|
|
8dd2813668 | ||
|
|
dac62d382a | ||
|
|
c4ad60f25c | ||
|
|
3cf73e9a56 | ||
|
|
227aa80eb9 | ||
|
|
17abc79f55 | ||
|
|
dd8b1b1548 | ||
|
|
d5f4187668 | ||
|
|
8fa8201677 | ||
|
|
9db4dd4244 | ||
|
|
68960cdd4c | ||
|
|
63eba8b40c | ||
|
|
03c1121463 | ||
|
|
6cde3510ab | ||
|
|
ad0054eb7a | ||
|
|
08f06f46d8 | ||
|
|
33cc80a90a | ||
|
|
65f339015f | ||
|
|
8d41514320 | ||
|
|
ac036cd74b | ||
|
|
cd1a929ab8 | ||
|
|
f2b0643b95 | ||
|
|
a6985f583c | ||
|
|
b6bd2fd8c2 | ||
|
|
b5167ca4ba | ||
|
|
10e602777f | ||
|
|
382a87f452 | ||
|
|
2799bbf86a | ||
|
|
432cd004b3 | ||
|
|
9313daeb2f | ||
|
|
852d8b4b1f | ||
|
|
b93f6fad1d | ||
|
|
6ffdd6905f |
3
.eslintignore
Normal file
3
.eslintignore
Normal file
@@ -0,0 +1,3 @@
|
||||
dist/
|
||||
lib/
|
||||
node_modules/
|
||||
18
.eslintrc.json
Normal file
18
.eslintrc.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"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"
|
||||
],
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"rules": {
|
||||
"@typescript-eslint/camelcase": "off"
|
||||
}
|
||||
}
|
||||
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
github: peter-evans
|
||||
15
.github/dependabot.yml
vendored
Normal file
15
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
labels:
|
||||
- "dependencies"
|
||||
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
allow:
|
||||
- dependency-name: "@actions/*"
|
||||
104
.github/workflows/ci.yml
vendored
Normal file
104
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- 'README.md'
|
||||
- 'docs/**'
|
||||
pull_request:
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- 'README.md'
|
||||
- 'docs/**'
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16.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@v3
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
- uses: actions/upload-artifact@v3
|
||||
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@v3
|
||||
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
||||
uses: actions/download-artifact@v3
|
||||
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/main'
|
||||
needs: [test]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v4
|
||||
with:
|
||||
commit-message: 'build: update distribution'
|
||||
title: Update distribution
|
||||
body: |
|
||||
- Updates the distribution for changes on `main`
|
||||
|
||||
Auto-generated by [create-pull-request][1]
|
||||
|
||||
[1]: https://github.com/peter-evans/create-pull-request
|
||||
branch: update-distribution
|
||||
23
.github/workflows/dockerhub-description.yml
vendored
23
.github/workflows/dockerhub-description.yml
vendored
@@ -1,8 +1,9 @@
|
||||
name: Update Docker Hub Description
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
paths:
|
||||
- README.md
|
||||
- .github/workflows/dockerhub-description.yml
|
||||
@@ -10,15 +11,17 @@ jobs:
|
||||
dockerHubDescription:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Copy README.md to TEST.md
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Modify readme for DockerHub
|
||||
run: |
|
||||
mkdir -p some/path
|
||||
mv README.md some/path/TEST.md
|
||||
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\/main\/LICENSE)/' README.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
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
repository: peterevans/dockerhub-description
|
||||
short-description: ${{ github.event.repository.description }}
|
||||
|
||||
41
.github/workflows/publish-docker.yml
vendored
Normal file
41
.github/workflows/publish-docker.yml
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
name: Publish Docker Image
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- v*
|
||||
env:
|
||||
IMAGE_NAME: peterevans/dockerhub-description
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- 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" == "main" ] && 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 --all-tags
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
lib/
|
||||
node_modules/
|
||||
3
.prettierignore
Normal file
3
.prettierignore
Normal file
@@ -0,0 +1,3 @@
|
||||
dist/
|
||||
lib/
|
||||
node_modules/
|
||||
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
||||
20
Dockerfile
20
Dockerfile
@@ -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"]
|
||||
|
||||
93
README.md
93
README.md
@@ -9,46 +9,67 @@ 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@v2.1.0
|
||||
env:
|
||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
|
||||
uses: peter-evans/dockerhub-description@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
repository: peterevans/dockerhub-description
|
||||
```
|
||||
|
||||
#### Required environment variables
|
||||
### Action inputs
|
||||
|
||||
- `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 `<namespace>/<name>`. 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 or [Personal Access Token](https://docs.docker.com/docker-hub/access-tokens/) with `read/write/delete` scope. | |
|
||||
| `repository` | Docker Hub repository in the format `<namespace>/<name>`. | `github.repository` |
|
||||
| `short-description` | Docker Hub repository short description. | |
|
||||
| `readme-filepath` | Path to the repository readme. | `./README.md` |
|
||||
|
||||
**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.
|
||||
#### Content limits
|
||||
|
||||
#### Optionally specifying the file path
|
||||
DockerHub has content limits, which if exceeded will result in the content being automatically truncated.
|
||||
The readme content is limited to 25,000 bytes, and `short-description` is limited to 100 characters.
|
||||
|
||||
#### 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@v2.1.0
|
||||
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@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
repository: peterevans/dockerhub-description
|
||||
readme-filepath: ./path/to/README.md
|
||||
```
|
||||
|
||||
#### Examples
|
||||
#### Using the GitHub repository description
|
||||
|
||||
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`.
|
||||
The GitHub repository description can be used for the Docker Hub `short-descripton` by passing the description from the event context.
|
||||
|
||||
```yml
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
repository: peterevans/dockerhub-description
|
||||
short-description: ${{ github.event.repository.description }}
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
The following workflow updates the Docker Hub repository description whenever there are changes to `README.md` and the workflow file itself on the `main` branch. This workflow assumes its location to be `.github/workflows/dockerhub-description.yml`.
|
||||
|
||||
```yml
|
||||
name: Update Docker Hub Description
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
paths:
|
||||
- README.md
|
||||
- .github/workflows/dockerhub-description.yml
|
||||
@@ -56,13 +77,15 @@ jobs:
|
||||
dockerHubDescription:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v2.1.0
|
||||
env:
|
||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
|
||||
uses: peter-evans/dockerhub-description@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
repository: peterevans/dockerhub-description
|
||||
short-description: ${{ github.event.repository.description }}
|
||||
```
|
||||
|
||||
Updates the Docker Hub repository description whenever a new release is created.
|
||||
@@ -74,13 +97,15 @@ jobs:
|
||||
dockerHubDescription:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v2.1.0
|
||||
env:
|
||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
DOCKERHUB_REPOSITORY: peterevans/dockerhub-description
|
||||
uses: peter-evans/dockerhub-description@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
repository: peterevans/dockerhub-description
|
||||
short-description: ${{ github.event.repository.description }}
|
||||
```
|
||||
|
||||
## Using the Docker image independently of GitHub Actions
|
||||
@@ -94,7 +119,7 @@ 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:2.1.0
|
||||
peterevans/dockerhub-description:3
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
23
action.yml
23
action.yml
@@ -1,9 +1,26 @@
|
||||
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 or Personal Access Token with read/write/delete scope
|
||||
required: true
|
||||
repository:
|
||||
description: >
|
||||
Docker Hub repository in the format `<namespace>/<name>`
|
||||
Default: `github.repository`
|
||||
short-description:
|
||||
description: Docker Hub repository short description
|
||||
readme-filepath:
|
||||
description: >
|
||||
Path to the repository readme
|
||||
Default: `./README.md`
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'docker://peterevans/dockerhub-description:2.1.1'
|
||||
using: 'node16'
|
||||
main: 'dist/index.js'
|
||||
branding:
|
||||
icon: 'upload'
|
||||
icon: 'upload'
|
||||
color: 'blue'
|
||||
|
||||
6985
dist/index.js
vendored
Normal file
6985
dist/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1,29 +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
|
||||
|
||||
# Check the file size
|
||||
if [ $(wc -c <${README_FILEPATH}) -gt 25000 ]; then
|
||||
echo "File size exceeds the maximum allowed 25000 bytes"
|
||||
exit 1
|
||||
fi
|
||||
# Remove lines containing sensitive information from the log
|
||||
sed -i '/::debug::/d' ./action.log
|
||||
sed -i '/::add-mask::/d' ./action.log
|
||||
|
||||
# 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_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
11
jest.config.js
Normal 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
|
||||
}
|
||||
10740
package-lock.json
generated
Normal file
10740
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
48
package.json
Normal file
48
package.json
Normal 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.10.0",
|
||||
"node-fetch": "^2.6.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/node": "^16.11.11",
|
||||
"@typescript-eslint/parser": "^5.5.0",
|
||||
"@vercel/ncc": "^0.32.0",
|
||||
"eslint": "^8.3.0",
|
||||
"eslint-plugin-github": "^4.3.5",
|
||||
"eslint-plugin-jest": "^25.3.0",
|
||||
"jest": "^27.4.3",
|
||||
"jest-circus": "^27.4.2",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.5.0",
|
||||
"ts-jest": "^27.0.7",
|
||||
"typescript": "^4.5.2"
|
||||
}
|
||||
}
|
||||
53
src/dockerhub-helper.ts
Normal file
53
src/dockerhub-helper.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
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'}
|
||||
})
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Unexpected response: ${response.status} ${response.statusText}`
|
||||
)
|
||||
}
|
||||
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
76
src/input-helper.ts
Normal 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')
|
||||
}
|
||||
45
src/main.ts
Normal file
45
src/main.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
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} from 'util'
|
||||
|
||||
function getErrorMessage(error: unknown) {
|
||||
if (error instanceof Error) return error.message
|
||||
return String(error)
|
||||
}
|
||||
|
||||
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'
|
||||
})
|
||||
|
||||
// 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(getErrorMessage(error))
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
16
tsconfig.json
Normal file
16
tsconfig.json
Normal 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"]
|
||||
}
|
||||
Reference in New Issue
Block a user