Compare commits
222 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc67fad700 | ||
|
|
67a28beebc | ||
|
|
ab07c6ee52 | ||
|
|
1ebaf7335e | ||
|
|
b85449155b | ||
|
|
950d5c5a19 | ||
|
|
4f5c0cdd7c | ||
|
|
d790b19dfe | ||
|
|
8e5fadaee0 | ||
|
|
1590065a78 | ||
|
|
2e1b37d8fb | ||
|
|
3dc747dce1 | ||
|
|
2573e7f4c0 | ||
|
|
5059fd86e9 | ||
|
|
4ebf07e899 | ||
|
|
d722849477 | ||
|
|
d7ee0471b0 | ||
|
|
40314b1002 | ||
|
|
b95ff7bca1 | ||
|
|
9f9136cb72 | ||
|
|
16530875f9 | ||
|
|
955386a494 | ||
|
|
de77530ea5 | ||
|
|
2d1351cb35 | ||
|
|
11da833829 | ||
|
|
823190d895 | ||
|
|
1b71c03ec0 | ||
|
|
579f64ca0a | ||
|
|
3f29bdade4 | ||
|
|
8b56ea036f | ||
|
|
2e2fadf6e3 | ||
|
|
015b1b5f51 | ||
|
|
4b1a4bb484 | ||
|
|
3ba533f0ff | ||
|
|
f866d47eb4 | ||
|
|
03ca5ee9b4 | ||
|
|
a57cec0ff6 | ||
|
|
2a3abf56ec | ||
|
|
9e64bda1bc | ||
|
|
dd732b0272 | ||
|
|
24d9720e95 | ||
|
|
74d5634479 | ||
|
|
f92370924c | ||
|
|
32a61cce5a | ||
|
|
4a4792c2ca | ||
|
|
202973a37c | ||
|
|
728b36f7bb | ||
|
|
3f60feb215 | ||
|
|
812a4d0496 | ||
|
|
79b63455c0 | ||
|
|
e139363f61 | ||
|
|
bbef094b30 | ||
|
|
21ccfa72b4 | ||
|
|
067627a8af | ||
|
|
d514e8a638 | ||
|
|
d440d6b705 | ||
|
|
ebb09a6e43 | ||
|
|
842061843e | ||
|
|
b360ab3b73 | ||
|
|
7ca13a4f6e | ||
|
|
d244f2b158 | ||
|
|
2c16b08205 | ||
|
|
ebbe765cd1 | ||
|
|
20a27e1287 | ||
|
|
ffe399573c | ||
|
|
692ca5d836 | ||
|
|
d560591414 | ||
|
|
4b6b64d89b | ||
|
|
4e40b120de | ||
|
|
fcaa3f84b7 | ||
|
|
651109f8e8 | ||
|
|
b02c8b39c6 | ||
|
|
f0e52ee452 | ||
|
|
f8648cb2f7 | ||
|
|
81ec7f185c | ||
|
|
723ac59666 | ||
|
|
841dc674ea | ||
|
|
bc803ce02a | ||
|
|
e35d4507cd | ||
|
|
c3668578c8 | ||
|
|
dec2815534 | ||
|
|
f2b6dec597 | ||
|
|
22519658ca | ||
|
|
3901fb41b0 | ||
|
|
2956947109 | ||
|
|
4a7ad32d0a | ||
|
|
1c79b7b870 | ||
|
|
f1bd7c2b9a | ||
|
|
bcd6cafa5b | ||
|
|
a2a89a04dc | ||
|
|
a9d3672166 | ||
|
|
3bafe822d0 | ||
|
|
fd3ace2386 | ||
|
|
c5d7e00b1e | ||
|
|
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 | ||
|
|
2739a0900f | ||
|
|
84d38211e2 | ||
|
|
abea83050d | ||
|
|
3361358488 | ||
|
|
2774ff3d56 | ||
|
|
b03d823861 | ||
|
|
6de5e14b55 | ||
|
|
5b8fd77939 | ||
|
|
81f3992e82 | ||
|
|
5e7108e09c | ||
|
|
f87713fbd6 |
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
|
||||
21
.github/dependabot.yml
vendored
Normal file
21
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
day: "sunday"
|
||||
labels:
|
||||
- "dependencies"
|
||||
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
day: "sunday"
|
||||
ignore:
|
||||
- dependency-name: "*"
|
||||
update-types: ["version-update:semver-major"]
|
||||
labels:
|
||||
- "dependencies"
|
||||
|
||||
13
.github/workflows/automerge-dependabot.yml
vendored
Normal file
13
.github/workflows/automerge-dependabot.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
name: Auto-merge Dependabot
|
||||
on: pull_request
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
steps:
|
||||
- uses: peter-evans/enable-pull-request-automerge@v3
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||
pull-request-number: ${{ github.event.pull_request.number }}
|
||||
merge-method: squash
|
||||
106
.github/workflows/ci.yml
vendored
Normal file
106
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
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
|
||||
cache: npm
|
||||
- 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@v5
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||
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
|
||||
27
.github/workflows/dockerhub-description.yml
vendored
Normal file
27
.github/workflows/dockerhub-description.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
name: Update Docker Hub Description
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- README.md
|
||||
- .github/workflows/dockerhub-description.yml
|
||||
jobs:
|
||||
dockerHubDescription:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- 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\/main\/LICENSE)/' README.md
|
||||
|
||||
- name: Docker Hub Description
|
||||
uses: ./
|
||||
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
|
||||
16
.github/workflows/push.yml
vendored
16
.github/workflows/push.yml
vendored
@@ -1,16 +0,0 @@
|
||||
name: Update Docker Hub Description
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
dockerHubDescription:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- 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-major-version.yml
vendored
Normal file
31
.github/workflows/update-major-version.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
name: Update Major Version
|
||||
run-name: Update ${{ github.event.inputs.main_version }} to ${{ github.event.inputs.target }}
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
target:
|
||||
description: The target tag or reference
|
||||
required: true
|
||||
main_version:
|
||||
type: choice
|
||||
description: The major version tag to update
|
||||
options:
|
||||
- v3
|
||||
|
||||
jobs:
|
||||
tag:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||
fetch-depth: 0
|
||||
- name: Git config
|
||||
run: |
|
||||
git config user.name actions-bot
|
||||
git config user.email actions-bot@users.noreply.github.com
|
||||
- name: Tag new target
|
||||
run: git tag -f ${{ github.event.inputs.main_version }} ${{ github.event.inputs.target }}
|
||||
- name: Push new tag
|
||||
run: git push origin ${{ github.event.inputs.main_version }} --force
|
||||
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"]
|
||||
|
||||
138
README.md
138
README.md
@@ -1,6 +1,5 @@
|
||||
# Docker Hub Description
|
||||
[](https://github.com/marketplace/actions/docker-hub-description)
|
||||
[](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,92 @@ 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.0.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>`.
|
||||
| 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` |
|
||||
| `enable-url-completion` | Enables completion of relative URLs to absolute ones. See also [known Issues](#url-completion-known-issues). | `false` |
|
||||
| `image-extensions` | File extensions that will be treated as images. | `bmp,gif,jpg,jpeg,png,svg,webp` |
|
||||
|
||||
Note that `DOCKERHUB_REPOSITORY` may also be passed as a secret if considered sensitive.
|
||||
#### Content limits
|
||||
|
||||
#### Optionally specifying the file path
|
||||
DockerHub has content limits.
|
||||
The readme content is limited to 25,000 bytes, and `short-description` is limited to 100 bytes.
|
||||
This action truncates content to prevent the request being rejected.
|
||||
If the content has been truncated a warning will be issued in the run log.
|
||||
|
||||
#### 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.0.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 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`.
|
||||
|
||||
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
|
||||
- main
|
||||
paths:
|
||||
- README.md
|
||||
- .github/workflows/dockerhub-description.yml
|
||||
jobs:
|
||||
dockerHubDescription:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v2.0.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 }}
|
||||
enable-url-completion: true
|
||||
```
|
||||
|
||||
Updates the Docker Hub repository description whenever a new release is created.
|
||||
|
||||
```yml
|
||||
name: Update Docker Hub Description
|
||||
on: release
|
||||
@@ -70,15 +102,49 @@ jobs:
|
||||
dockerHubDescription:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v2.0.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 }}
|
||||
```
|
||||
|
||||
### URL completion known Issues
|
||||
|
||||
The completion of relative URLs has some known issues:
|
||||
|
||||
1. Relative markdown links in inline-code and code blocks **are also converted**:
|
||||
|
||||
```markdown
|
||||
[link in inline code](#table-of-content)
|
||||
```
|
||||
|
||||
will be converted into
|
||||
|
||||
```markdown
|
||||
[link in inline code](https://github.com/peter-evans/dockerhub-description/blob/main/./README.md#table-of-content)
|
||||
```
|
||||
|
||||
2. Links containing square brackets (`]`) in the text fragment **are not converted**:
|
||||
|
||||
```markdown
|
||||
[[link text with square brackets]](#table-of-content)
|
||||
```
|
||||
|
||||
3. [Reference-style links/images](https://www.markdownguide.org/basic-syntax/#reference-style-links) **are not converted**.
|
||||
|
||||
```markdown
|
||||
[table-of-content][toc]
|
||||
|
||||
...
|
||||
|
||||
[toc]: #table-of-content "Table of content"
|
||||
```
|
||||
|
||||
## Using the Docker image independently of GitHub Actions
|
||||
|
||||
The image can be executed in other environments independently of GitHub Actions.
|
||||
@@ -90,9 +156,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:2.0.0
|
||||
peterevans/dockerhub-description:3
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT License - see the [LICENSE](LICENSE) file for details
|
||||
[MIT](LICENSE)
|
||||
|
||||
335
__test__/readme-helper.unit.test.ts
Normal file
335
__test__/readme-helper.unit.test.ts
Normal file
@@ -0,0 +1,335 @@
|
||||
import {completeRelativeUrls} from '../src/readme-helper'
|
||||
|
||||
describe('complete relative urls tests', () => {
|
||||
const GITHUB_SERVER_URL = process.env['GITHUB_SERVER_URL']
|
||||
const GITHUB_REPOSITORY = process.env['GITHUB_REPOSITORY']
|
||||
const GITHUB_REF_NAME = process.env['GITHUB_REF_NAME']
|
||||
|
||||
const README_FILEPATH = './README.md'
|
||||
const EXPECTED_REPOSITORY_URL = `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}`
|
||||
const EXPECTED_BLOB_URL = `${EXPECTED_REPOSITORY_URL}/blob/${GITHUB_REF_NAME}`
|
||||
const EXPECTED_RAW_URL = `${EXPECTED_REPOSITORY_URL}/raw/${GITHUB_REF_NAME}`
|
||||
|
||||
// known issues
|
||||
test('reference-style links/image sources are not converted', async () => {
|
||||
const content = [
|
||||
'table-of-content][toc]',
|
||||
'',
|
||||
'[toc]: #table-of-content "Table of content"'
|
||||
].join('\n')
|
||||
expect(completeRelativeUrls(content, README_FILEPATH, true, '')).toEqual(
|
||||
content
|
||||
)
|
||||
})
|
||||
|
||||
test('links containing square brackets in the text fragment are not converted', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[[text with square brackets]](README.md)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual('[[text with square brackets]](README.md)')
|
||||
})
|
||||
|
||||
test('links containing square brackets in the text fragment are not converted', async () => {
|
||||
expect(
|
||||
completeRelativeUrls('`[text](README.md)`', README_FILEPATH, true, '')
|
||||
).toEqual(`\`[text](${EXPECTED_BLOB_URL}/README.md)\``)
|
||||
})
|
||||
|
||||
// misc
|
||||
test('do not change content when disabled', async () => {
|
||||
expect(
|
||||
completeRelativeUrls('[text](README.md)', README_FILEPATH, false, '')
|
||||
).toEqual('[text](README.md)')
|
||||
})
|
||||
|
||||
test('do not change link with mailto protocol', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[text](mailto:mail@example.com)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual(`[text](mailto:mail@example.com)`)
|
||||
})
|
||||
|
||||
test('do not change link with ftp protocol', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[text](ftp://example.com)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual(`[text](ftp://example.com)`)
|
||||
})
|
||||
|
||||
test('do not change link with http protocol', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[text](http://example.com)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual(`[text](http://example.com)`)
|
||||
})
|
||||
|
||||
test('do not change link with https protocol', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[text](https://example.com)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual(`[text](https://example.com)`)
|
||||
})
|
||||
|
||||
test('do not change link with protocol-like beginning', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[text](abc://example.com)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual(`[text](abc://example.com)`)
|
||||
})
|
||||
|
||||
test('do not change image from absolute source with absolute link', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[](https://example.com/image.svg)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
'svg'
|
||||
)
|
||||
).toEqual(
|
||||
`[](https://example.com/image.svg)`
|
||||
)
|
||||
})
|
||||
|
||||
// anchors
|
||||
test('anchor referencing the current document', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[text](#relative-anchor)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual(`[text](${EXPECTED_BLOB_URL}/README.md#relative-anchor)`)
|
||||
})
|
||||
|
||||
test('anchor referencing the current document with a title', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[text](#relative-anchor "the anchor (a title)")',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual(
|
||||
`[text](${EXPECTED_BLOB_URL}/README.md#relative-anchor "the anchor (a title)")`
|
||||
)
|
||||
})
|
||||
|
||||
test('anchor referencing the current document with a title and unicode', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[text with 🌬](#relative-anchor "the anchor (a title with 🌬)")',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual(
|
||||
`[text with 🌬](${EXPECTED_BLOB_URL}/README.md#relative-anchor "the anchor (a title with 🌬)")`
|
||||
)
|
||||
})
|
||||
|
||||
test('anchor referencing another document', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[text](OTHER.md#absolute-anchor)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual(`[text](${EXPECTED_BLOB_URL}/OTHER.md#absolute-anchor)`)
|
||||
})
|
||||
|
||||
test('anchor referencing another document with a title', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[text](OTHER.md#absolute-anchor "the anchor (a title)")',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual(
|
||||
`[text](${EXPECTED_BLOB_URL}/OTHER.md#absolute-anchor "the anchor (a title)")`
|
||||
)
|
||||
})
|
||||
|
||||
test('anchor with image referencing the current document', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[](#absolute-anchor "the anchor (a title)")',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
'svg'
|
||||
)
|
||||
).toEqual(
|
||||
`[](${EXPECTED_BLOB_URL}/README.md#absolute-anchor "the anchor (a title)")`
|
||||
)
|
||||
})
|
||||
|
||||
test('anchor with image referencing another document', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[](OTHER.md#absolute-anchor "the anchor (a title)")',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
'svg'
|
||||
)
|
||||
).toEqual(
|
||||
`[](${EXPECTED_BLOB_URL}/OTHER.md#absolute-anchor "the anchor (a title)")`
|
||||
)
|
||||
})
|
||||
|
||||
// documents
|
||||
test('text document', async () => {
|
||||
expect(
|
||||
completeRelativeUrls('[text](document.yaml)', README_FILEPATH, true, '')
|
||||
).toEqual(`[text](${EXPECTED_BLOB_URL}/document.yaml)`)
|
||||
})
|
||||
|
||||
test('pdf document', async () => {
|
||||
expect(
|
||||
completeRelativeUrls('[text](document.pdf)', README_FILEPATH, true, '')
|
||||
).toEqual(`[text](${EXPECTED_BLOB_URL}/document.pdf)`)
|
||||
})
|
||||
|
||||
test('document with a title', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[text](document.pdf "the document (a title)")',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual(
|
||||
`[text](${EXPECTED_BLOB_URL}/document.pdf "the document (a title)")`
|
||||
)
|
||||
})
|
||||
|
||||
test('document with a title and unicode', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[text with 🌬](document.pdf "the document (a title with 🌬)")',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
''
|
||||
)
|
||||
).toEqual(
|
||||
`[text with 🌬](${EXPECTED_BLOB_URL}/document.pdf "the document (a title with 🌬)")`
|
||||
)
|
||||
})
|
||||
|
||||
// images
|
||||
test('image with supported file extension', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
'svg'
|
||||
)
|
||||
).toEqual(``)
|
||||
})
|
||||
|
||||
test('image with unsupported file extension', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
'jpeg'
|
||||
)
|
||||
).toEqual(``)
|
||||
})
|
||||
|
||||
test('image without alternate text', async () => {
|
||||
expect(
|
||||
completeRelativeUrls('', README_FILEPATH, true, 'svg')
|
||||
).toEqual(``)
|
||||
})
|
||||
|
||||
test('image with a title', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'")',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
'svg'
|
||||
)
|
||||
).toEqual(`")`)
|
||||
})
|
||||
|
||||
test('image with relative link', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[](image.svg)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
'svg'
|
||||
)
|
||||
).toEqual(
|
||||
`[](${EXPECTED_BLOB_URL}/image.svg)`
|
||||
)
|
||||
})
|
||||
|
||||
test('image with a title, unicode and relative link', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[")](image.🌬.svg)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
'svg'
|
||||
)
|
||||
).toEqual(
|
||||
`[")](${EXPECTED_BLOB_URL}/image.🌬.svg)`
|
||||
)
|
||||
})
|
||||
|
||||
test('image from absolute source with relative link', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[](image.svg)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
'svg'
|
||||
)
|
||||
).toEqual(
|
||||
`[](${EXPECTED_BLOB_URL}/image.svg)`
|
||||
)
|
||||
})
|
||||
|
||||
test('image with absolute link', async () => {
|
||||
expect(
|
||||
completeRelativeUrls(
|
||||
'[](https://example.com/image.svg)',
|
||||
README_FILEPATH,
|
||||
true,
|
||||
'svg'
|
||||
)
|
||||
).toEqual(
|
||||
`[](https://example.com/image.svg)`
|
||||
)
|
||||
})
|
||||
})
|
||||
10
__test__/utils.unit.test.ts
Normal file
10
__test__/utils.unit.test.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import {truncateToBytes} from '../src/utils'
|
||||
|
||||
describe('truncate to bytes tests', () => {
|
||||
test('unicode aware truncation to a number of bytes', async () => {
|
||||
expect(truncateToBytes('test string to be truncated', 10)).toEqual(
|
||||
'test strin'
|
||||
)
|
||||
expect(truncateToBytes('😀😁😂🤣😃😄😅', 10)).toEqual('😀😁')
|
||||
})
|
||||
})
|
||||
31
action.yml
31
action.yml
@@ -1,9 +1,34 @@
|
||||
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`
|
||||
enable-url-completion:
|
||||
description: >
|
||||
Enables completion of relative URLs to absolute ones
|
||||
Default: `false`
|
||||
image-extensions:
|
||||
description: >
|
||||
File extensions that will be treated as images
|
||||
Default: `bmp,gif,jpg,jpeg,png,svg,webp`
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'docker://peterevans/dockerhub-description:2.1.0'
|
||||
using: 'node16'
|
||||
main: 'dist/index.js'
|
||||
branding:
|
||||
icon: 'upload'
|
||||
icon: 'upload'
|
||||
color: 'blue'
|
||||
|
||||
7355
dist/index.js
vendored
Normal file
7355
dist/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1,23 +1,16 @@
|
||||
#!/bin/sh -l
|
||||
set -euo 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
|
||||
exit_code=$?
|
||||
|
||||
# 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"
|
||||
# Output the log
|
||||
cat action.log
|
||||
|
||||
if [ $RESPONSE_CODE -eq 200 ]; then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
# Exit using the exit code of the node command
|
||||
exit $exit_code
|
||||
|
||||
16
jest.config.js
Normal file
16
jest.config.js
Normal file
@@ -0,0 +1,16 @@
|
||||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testRunner: 'jest-circus/runner',
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true
|
||||
}
|
||||
process.env = Object.assign(process.env, {
|
||||
GITHUB_SERVER_URL: 'https://github.com',
|
||||
GITHUB_REPOSITORY: 'peter-evans/dockerhub-description',
|
||||
GITHUB_REF_NAME: 'main'
|
||||
})
|
||||
6893
package-lock.json
generated
Normal file
6893
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
49
package.json
Normal file
49
package.json
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"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"
|
||||
},
|
||||
"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.11",
|
||||
"unicode-substring": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/node": "^16.18.36",
|
||||
"@typescript-eslint/parser": "^5.59.11",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.43.0",
|
||||
"eslint-plugin-github": "^4.8.0",
|
||||
"eslint-plugin-jest": "^25.7.0",
|
||||
"jest": "^27.5.1",
|
||||
"jest-circus": "^27.5.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.8.8",
|
||||
"ts-jest": "^27.1.5",
|
||||
"typescript": "^4.9.5"
|
||||
}
|
||||
}
|
||||
51
src/dockerhub-helper.ts
Normal file
51
src/dockerhub-helper.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as fetch from 'node-fetch'
|
||||
|
||||
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
|
||||
}
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
94
src/input-helper.ts
Normal file
94
src/input-helper.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as readmeHelper from './readme-helper'
|
||||
|
||||
interface Inputs {
|
||||
username: string
|
||||
password: string
|
||||
repository: string
|
||||
shortDescription: string
|
||||
readmeFilepath: string
|
||||
enableUrlCompletion: boolean
|
||||
imageExtensions: 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'),
|
||||
enableUrlCompletion: Boolean(core.getInput('enable-url-completion')),
|
||||
imageExtensions: core.getInput('image-extensions')
|
||||
}
|
||||
|
||||
// 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']
|
||||
}
|
||||
|
||||
if (!inputs.enableUrlCompletion && process.env['ENABLE_URL_COMPLETION']) {
|
||||
inputs.enableUrlCompletion = Boolean(process.env['ENABLE_URL_COMPLETION'])
|
||||
}
|
||||
|
||||
if (!inputs.imageExtensions && process.env['IMAGE_EXTENSIONS']) {
|
||||
inputs.imageExtensions = process.env['IMAGE_EXTENSIONS']
|
||||
}
|
||||
|
||||
// Set defaults
|
||||
if (!inputs.readmeFilepath) {
|
||||
inputs.readmeFilepath = readmeHelper.README_FILEPATH_DEFAULT
|
||||
}
|
||||
if (!inputs.enableUrlCompletion) {
|
||||
inputs.enableUrlCompletion = readmeHelper.ENABLE_URL_COMPLETION_DEFAULT
|
||||
}
|
||||
if (!inputs.imageExtensions) {
|
||||
inputs.imageExtensions = readmeHelper.IMAGE_EXTENSIONS_DEFAULT
|
||||
}
|
||||
if (!inputs.repository && process.env['GITHUB_REPOSITORY']) {
|
||||
inputs.repository = process.env['GITHUB_REPOSITORY']
|
||||
}
|
||||
|
||||
// Enforce lower case, where needed
|
||||
inputs.repository = inputs.repository.toLowerCase()
|
||||
inputs.imageExtensions = inputs.imageExtensions.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')
|
||||
}
|
||||
59
src/main.ts
Normal file
59
src/main.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as inputHelper from './input-helper'
|
||||
import * as dockerhubHelper from './dockerhub-helper'
|
||||
import * as readmeHelper from './readme-helper'
|
||||
import * as utils from './utils'
|
||||
import {inspect} from 'util'
|
||||
|
||||
const SHORT_DESCRIPTION_MAX_BYTES = 100
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const inputs = inputHelper.getInputs()
|
||||
core.debug(`Inputs: ${inspect(inputs)}`)
|
||||
|
||||
inputHelper.validateInputs(inputs)
|
||||
|
||||
// Fetch the readme content
|
||||
core.info('Reading description source file')
|
||||
const readmeContent = await readmeHelper.getReadmeContent(
|
||||
inputs.readmeFilepath,
|
||||
inputs.enableUrlCompletion,
|
||||
inputs.imageExtensions
|
||||
)
|
||||
core.debug(readmeContent)
|
||||
|
||||
// Truncate the short description if it is too long
|
||||
const truncatedShortDescription = utils.truncateToBytes(
|
||||
inputs.shortDescription,
|
||||
SHORT_DESCRIPTION_MAX_BYTES
|
||||
)
|
||||
if (truncatedShortDescription.length !== inputs.shortDescription.length) {
|
||||
core.warning(
|
||||
`The short description exceeds DockerHub's limit and has been truncated to ${SHORT_DESCRIPTION_MAX_BYTES} bytes.`
|
||||
)
|
||||
}
|
||||
core.debug(`Truncated short description: ${truncatedShortDescription}`)
|
||||
|
||||
// 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,
|
||||
truncatedShortDescription,
|
||||
readmeContent
|
||||
)
|
||||
core.info('Request successful')
|
||||
} catch (error) {
|
||||
core.debug(inspect(error))
|
||||
core.setFailed(utils.getErrorMessage(error))
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
185
src/readme-helper.ts
Normal file
185
src/readme-helper.ts
Normal file
@@ -0,0 +1,185 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as fs from 'fs'
|
||||
import * as utils from './utils'
|
||||
|
||||
export const README_FILEPATH_DEFAULT = './README.md'
|
||||
export const IMAGE_EXTENSIONS_DEFAULT = 'bmp,gif,jpg,jpeg,png,svg,webp'
|
||||
export const ENABLE_URL_COMPLETION_DEFAULT = false
|
||||
|
||||
const TITLE_REGEX = `(?: +"[^"]+")?`
|
||||
const REPOSITORY_URL = `${process.env['GITHUB_SERVER_URL']}/${process.env['GITHUB_REPOSITORY']}`
|
||||
const BLOB_PREFIX = `${REPOSITORY_URL}/blob/${process.env['GITHUB_REF_NAME']}/`
|
||||
const RAW_PREFIX = `${REPOSITORY_URL}/raw/${process.env['GITHUB_REF_NAME']}/`
|
||||
|
||||
const MAX_BYTES = 25000
|
||||
|
||||
type Rule = {
|
||||
/**
|
||||
* all left of the relative url belonging to the markdown image/link
|
||||
*/
|
||||
left: RegExp
|
||||
/**
|
||||
* relative url
|
||||
*/
|
||||
url: RegExp
|
||||
/**
|
||||
* part to prefix the relative url with (excluding github repository url)
|
||||
*/
|
||||
absUrlPrefix: string
|
||||
}
|
||||
|
||||
export async function getReadmeContent(
|
||||
readmeFilepath: string,
|
||||
enableUrlCompletion: boolean,
|
||||
imageExtensions: string
|
||||
): Promise<string> {
|
||||
// Fetch the readme content
|
||||
let readmeContent = await fs.promises.readFile(readmeFilepath, {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
|
||||
readmeContent = completeRelativeUrls(
|
||||
readmeContent,
|
||||
readmeFilepath,
|
||||
enableUrlCompletion,
|
||||
imageExtensions
|
||||
)
|
||||
|
||||
const truncatedReadmeContent = utils.truncateToBytes(readmeContent, MAX_BYTES)
|
||||
if (truncatedReadmeContent.length !== readmeContent.length) {
|
||||
core.warning(
|
||||
`The README content exceeds DockerHub's limit and has been truncated to ${MAX_BYTES} bytes.`
|
||||
)
|
||||
}
|
||||
|
||||
return truncatedReadmeContent
|
||||
}
|
||||
|
||||
export function completeRelativeUrls(
|
||||
readmeContent: string,
|
||||
readmeFilepath: string,
|
||||
enableUrlCompletion: boolean,
|
||||
imageExtensions: string
|
||||
): string {
|
||||
if (enableUrlCompletion) {
|
||||
readmeFilepath = readmeFilepath.replace(/^[.][/]/, '')
|
||||
|
||||
// Make relative urls absolute
|
||||
const rules = [
|
||||
...getRelativeReadmeAnchorsRules(readmeFilepath),
|
||||
...getRelativeImageUrlRules(imageExtensions),
|
||||
...getRelativeUrlRules()
|
||||
]
|
||||
|
||||
readmeContent = applyRules(rules, readmeContent)
|
||||
}
|
||||
|
||||
return readmeContent
|
||||
}
|
||||
|
||||
function applyRules(rules: Rule[], readmeContent: string): string {
|
||||
rules.forEach(rule => {
|
||||
const combinedRegex = `${rule.left.source}[(]${rule.url.source}[)]`
|
||||
core.debug(`rule: ${combinedRegex}`)
|
||||
|
||||
const replacement = `$<left>(${rule.absUrlPrefix}$<url>)`
|
||||
core.debug(`replacement: ${replacement}`)
|
||||
|
||||
readmeContent = readmeContent.replace(
|
||||
new RegExp(combinedRegex, 'giu'),
|
||||
replacement
|
||||
)
|
||||
})
|
||||
|
||||
return readmeContent
|
||||
}
|
||||
|
||||
// has to be applied first to avoid wrong results
|
||||
function getRelativeReadmeAnchorsRules(readmeFilepath: string): Rule[] {
|
||||
const prefix = `${BLOB_PREFIX}${readmeFilepath}`
|
||||
|
||||
// matches e.g.:
|
||||
// #table-of-content
|
||||
// #table-of-content "the anchor (a title)"
|
||||
const url = new RegExp(`(?<url>#[^)]+${TITLE_REGEX})`)
|
||||
|
||||
const rules: Rule[] = [
|
||||
// matches e.g.:
|
||||
// [#table-of-content](#table-of-content)
|
||||
// [#table-of-content](#table-of-content "the anchor (a title)")
|
||||
{
|
||||
left: /(?<left>\[[^\]]+\])/,
|
||||
url: url,
|
||||
absUrlPrefix: prefix
|
||||
},
|
||||
|
||||
// matches e.g.:
|
||||
// [](#table-of-content)
|
||||
// [](#table-of-content "title b")
|
||||
{
|
||||
left: /(?<left>\[!\[[^\]]*\]\([^)]+\)\])/,
|
||||
url: url,
|
||||
absUrlPrefix: prefix
|
||||
}
|
||||
]
|
||||
|
||||
return rules
|
||||
}
|
||||
|
||||
function getRelativeImageUrlRules(imageExtensions: string): Rule[] {
|
||||
const extensionsRegex = imageExtensions.replace(/,/g, '|')
|
||||
// matches e.g.:
|
||||
// media/image.svg
|
||||
// media/image.svg "with title"
|
||||
const url = new RegExp(
|
||||
`(?<url>[^:)]+[.](?:${extensionsRegex})${TITLE_REGEX})`
|
||||
)
|
||||
|
||||
const rules: Rule[] = [
|
||||
// matches e.g.:
|
||||
// 
|
||||
// 
|
||||
{
|
||||
left: /(?<left>!\[[^\]]*\])/,
|
||||
url: url,
|
||||
absUrlPrefix: RAW_PREFIX
|
||||
}
|
||||
]
|
||||
|
||||
return rules
|
||||
}
|
||||
|
||||
function getRelativeUrlRules(): Rule[] {
|
||||
// matches e.g.:
|
||||
// .releaserc.yaml
|
||||
// README.md#table-of-content "title b"
|
||||
// .releaserc.yaml "the .releaserc.yaml file (a title)"
|
||||
const url = new RegExp(`(?<url>[^:)]+${TITLE_REGEX})`)
|
||||
|
||||
const rules: Rule[] = [
|
||||
// matches e.g.:
|
||||
// [.releaserc.yaml](.releaserc.yaml)
|
||||
// [.releaserc.yaml](.releaserc.yaml "the .releaserc.yaml file (a title)")
|
||||
{
|
||||
left: /(?<left>\[[^\]]+\])/,
|
||||
url: url,
|
||||
absUrlPrefix: BLOB_PREFIX
|
||||
},
|
||||
|
||||
// matches e.g.:
|
||||
// [](media/image.svg)
|
||||
// [](README.md#table-of-content "title b")
|
||||
// [](media/image.svg)
|
||||
// [](media/image.svg "title b")
|
||||
// [](README.md#table-of-content "title b")
|
||||
{
|
||||
left: new RegExp(
|
||||
`(?<left>\\[!\\[[^\\]]*\\]\\([^)]+${TITLE_REGEX}\\)\\])`
|
||||
),
|
||||
url: url,
|
||||
absUrlPrefix: BLOB_PREFIX
|
||||
}
|
||||
]
|
||||
|
||||
return rules
|
||||
}
|
||||
14
src/utils.ts
Normal file
14
src/utils.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import unicodeSubstring = require('unicode-substring')
|
||||
|
||||
export function getErrorMessage(error: unknown) {
|
||||
if (error instanceof Error) return error.message
|
||||
return String(error)
|
||||
}
|
||||
|
||||
export function truncateToBytes(s: string, n: number): string {
|
||||
let len = n
|
||||
while (Buffer.byteLength(s) > n) {
|
||||
s = unicodeSubstring(s, 0, len--)
|
||||
}
|
||||
return s
|
||||
}
|
||||
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