Skip to content

Allow to replace patterns in readme file #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: whale
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ Sync <readme.md> to Dockerhub

```

Optionally, you can replace strings in your readme file. For example, to avoid broken images, you can exchange relative image URLs like `![MyImage](./doc/image.svg)` with absolute URLs like `![MyImage](https://github.com/myuser/myrepo/raw/main/doc/image.svg))`:

```yaml
- name: Sync
uses: ms-jpq/sync-dockerhub-readme@v1
with:
username: <dockerhub username>
password: <dockerhub password>
repository: <dockerhub name/repo>
readme: "./README.md"
replace_pattern: "](./"
replace_with: "](${{ github.server_url }}/${{ github.repository }}/raw/${{ github.ref_name }}/"
```

## Docker Image

[![Docker Pulls](https://img.shields.io/docker/pulls/msjpq/sync-dockerhub-readme.svg)](https://hub.docker.com/r/msjpq/sync-dockerhub-readme/)
Expand Down
18 changes: 18 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ inputs:
list of repositories to update
(without username)

replace_pattern:
required: False
description: |-
if set, all occurences of "replace_pattern"
will be replaced with "replace_with"
default: ''

replace_with:
required: False
description: |-
if set, all occurences of "replace_pattern"
will be replaced with "replace_with"
default: ''

runs:
using: docker
image: "Dockerfile"
Expand All @@ -37,6 +51,10 @@ runs:
- "${{ inputs.readme }}"
- "--repo"
- "${{ inputs.repository }}"
- "--replace-pattern"
- "${{ inputs.replace_pattern }}"
- "--replace-with"
- "${{ inputs.replace_with }}"

branding:
icon: anchor
Expand Down
9 changes: 9 additions & 0 deletions docker_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def parse_args() -> Namespace:

parser.add_argument("--readme", required=True)
parser.add_argument("--repo", required=True)
parser.add_argument("--replace-pattern", type=str, required=False)
parser.add_argument("--replace-with", type=str, required=False)

args = parser.parse_args()
return args
Expand Down Expand Up @@ -66,9 +68,16 @@ def set_repo(token: str, repo: str, readme: str) -> str:
return loads(msg)["full_description"]


def replace_patterns(readme: str, replace_pattern: str, replace_with: str) -> str:
return readme.replace(replace_pattern, replace_with)


def main() -> None:
args = parse_args()
print(args)
readme = slurp(args.readme)
if args.replace_pattern and args.replace_with:
readme = replace_patterns(readme, args.replace_pattern, args.replace_with)
token = login(args.username, args.password)
desc = set_repo(token=token, repo=args.repo, readme=readme,)
big_print(desc)
Expand Down