Skip to content

Commit

Permalink
Update input names and README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Jan 8, 2025
1 parent 44c965e commit 30a4927
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,35 @@
Copy & paste the following workflow definition into your project `.github/workflows/describe-docker.yml`

```yaml
name: Validate hyperlinks in markdown files
name: Docker Hub Description

on:
push:
workflow_dispatch:

jobs:
describe-docker:
runs-on: ubuntu-latest # Can run on multiple operating systems
runs-on: ubuntu-latest
steps:
- uses: thevickypedia/describe-docker@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
summary: "Short description to summarize the docker image"
repository: "vaultapi"
filename: "README.md"
```
- Commit your changes to trigger the workflow or run the workflow manually.
### Action inputs
- `docker_username` - Docker hub username.
- `docker_password` - Docker hub password.
- `docker_registry` - Docker hub registry URL (defaults to https://hub.docker.com/v2)
- `repository_name` - Name of the docker image repository.
- `summary` - Docker repository overview (character limit enforced)
- `description_file` - Filename to read the full description for the docker image.
- `summary_limit` - Summary limit for docker hub overview (defaults to 100 for hub.docker.com)
- `username` - Docker hub username.
- `password` - Docker hub password.
- `registry` - Docker hub registry URL (defaults to https://hub.docker.com/v2)
- `repository` - Name of the docker image repository. _Docker hub username is prefixed automatically_.
- `summary` - Docker repository overview (100-character limit)
- `filename` - Filename to read the full description for the docker image.

## License & copyright

Expand Down
54 changes: 27 additions & 27 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
name: describe-docker
description: GitHub action to update docker description
inputs:
docker_username:
username:
description: Docker hub username
required: true
docker_password:
password:
description: Docker hub password
required: true
docker_registry:
registry:
description: Docker hub registry URL
required: false
default: https://hub.docker.com/v2
repository_name:
repository:
description: Name of the docker image repository
required: true
summary:
description: Docker repository overview (character limit enforced)
description: Docker repository overview (100-character limit)
required: true
description_file:
filename:
description: Filename to read the full description for the docker image.
required: true
summary_limit:
description: Summary limit for docker hub overview (defaults to 100 for hub.docker.com)
required: false
default: "100"
outputs: { }
runs:
using: composite
Expand All @@ -35,22 +31,22 @@ runs:

- name: Validate Inputs
run: |
if [[ -z "${{ inputs.docker_username }}" ]]; then
if [[ -z "${{ inputs.username }}" ]]; then
echo "::error title=MissingInput::Docker hub username is not provided."
exit 1
fi
if [[ -z "${{ inputs.docker_password }}" ]]; then
if [[ -z "${{ inputs.password }}" ]]; then
echo "::error title=MissingInput::Docker hub password is not provided."
exit 1
fi
if [[ -z "${{ inputs.docker_registry }}" ]]; then
if [[ -z "${{ inputs.registry }}" ]]; then
echo "::error title=MissingInput::Docker registry URL is not provided."
exit 1
fi
if [[ -z "${{ inputs.repository_name }}" ]]; then
if [[ -z "${{ inputs.repository }}" ]]; then
echo "::error title=MissingInput::Repository name is not provided."
exit 1
fi
Expand All @@ -59,31 +55,34 @@ runs:
echo "::warning title=MissingInput::Summary is not provided."
fi
if [[ -z "${{ inputs.description_file }}" ]]; then
if [[ -z "${{ inputs.filename }}" ]]; then
echo "::error title=MissingInput::Description file is not provided."
exit 1
fi
if [[ ! -f "${{ inputs.description_file }}" ]]; then
echo "::error title=MissingInput::Description file '${{ inputs.description_file }}' does not exist."
if [[ ! -f "${{ inputs.filename }}" ]]; then
echo "::error title=MissingInput::Description file '${{ inputs.filename }}' does not exist."
exit 1
fi
if [[ "${{ inputs.repository_name }}" == "${{ inputs.docker_username }}/"* ]]; then
echo "REPOSITORY_NAME=${{ inputs.repository_name }}" >> $GITHUB_ENV
if [[ "${{ inputs.repository }}" == "${{ inputs.username }}/"* ]]; then
echo "REPOSITORY_NAME=${{ inputs.repository }}" >> $GITHUB_ENV
elif [[ "${{ inputs.repository }}" == */* ]]; then
echo "::error title=InvalidInput::Invalid repository name, it should either be 'username/repository' or just 'repository'."
exit 1
else
echo "REPOSITORY_NAME=${{ inputs.docker_username }}/${{ inputs.repository_name }}" >> $GITHUB_ENV
echo "REPOSITORY_NAME=${{ inputs.username }}/${{ inputs.repository }}" >> $GITHUB_ENV
fi
shell: bash

- name: Fetch API Token
run: |
payload=$(jq -n \
--arg username "${{ inputs.docker_username }}" \
--arg password "${{ inputs.docker_password }}" \
--arg username "${{ inputs.username }}" \
--arg password "${{ inputs.password }}" \
'{username: $username, password: $password}')
token=$(curl -s -X POST "${{ inputs.docker_registry }}/users/login/" \
token=$(curl -s -X POST "${{ inputs.registry }}/users/login/" \
-H "Content-Type: application/json" \
-d "$payload" | jq -r '.token')
Expand All @@ -98,10 +97,11 @@ runs:

- name: Check summary limit
run: |
warn="Summary exceeds DockerHub's limit and has been truncated to ${{ inputs.summary_limit }} characters."
summary_limit=100
warn="Summary exceeds DockerHub's limit and has been truncated to ${summary_limit} characters."
summary="${{ inputs.summary }}"
summary_length=${#summary}
if [[ "$summary_length" -gt "${{ inputs.summary_limit }}" ]]; then
if [[ "$summary_length" -gt "${summary_limit}" ]]; then
echo "::warning title=Summary Too Long::${warn}"
echo "SUMMARY=${summary:0:97}..." >> $GITHUB_ENV
else
Expand All @@ -111,14 +111,14 @@ runs:

- name: Update description
run: |
full_description="$(cat "${{ inputs.description_file }}")"
full_description="$(cat "${{ inputs.filename }}")"
payload=$(jq -n \
--arg description "${{ env.SUMMARY }}" \
--arg full_description "$full_description" \
'{description: $description, full_description: $full_description}')
response=$(curl -s -o /tmp/desc -w "%{http_code}" -X PATCH \
"${{ inputs.docker_registry }}/repositories/${{ env.REPOSITORY_NAME }}/" \
"${{ inputs.registry }}/repositories/${{ env.REPOSITORY_NAME }}/" \
-H "Authorization: Bearer ${{ env.API_TOKEN }}" \
-H "Content-Type: application/json" \
-d "$payload")
Expand Down

0 comments on commit 30a4927

Please sign in to comment.