GitHub Action
Update Image - README
There is a short tutorial with enough steps for you to get started with this not-so-useful GitHub Action. Check that out here.
If you want to get an in-depth idea on the usage of this action, please follow the below points.
- You need to update the markdown file(.md) with 2 comments. You can refer here for updating it.
- Make sure to have a
.github/images
folder on your profile repository or any other repository. Jump here to know more. - Optional You'll need a GitHub API Token with
repo
scope from here if you're running the action for a non profile repository.- You can use this example to work it out.
- You can follow any one example below according to your needs to get started !
- It is better to run the Action on your Profile Repository, since you won't be needing a GitHub Access Token !
- Check this to see available options while creating a workflow for this action.
Add a comment to your README.md
like this:
<!--START_SECTION:update_image-->
<!--END_SECTION:update_image-->
You can place these 2 lines anywhere you want your images to be displayed.
You need to have your own collection of images that you want to be displayed on your README.
You can do so in 2 ways:
- Add
.github/images
folder on the same repository as README or on a different repository, this folder should contain the images.
You can add .github/images
on a different repository as well, then you would need to mention that repository explicitly by passing a parameter IMG_REPOSITORY
on your workflow yaml.
with:
IMG_REPOSITORY: <username>/<imagerepo>
- Add a folder (name it whatever you like) on the same repository as README or on a different repository, this folder should contain the images.
You need to specify IMG_PATH
on your workflow yaml, with this if you are creating this folder on a different repository, then you would need to specify IMG_REPOSITORY
as well.
If on same repo but image folder is not .github/images
:
with:
IMG_PATH: <images-folder>
If on a different repo and image folder is not .github/images
:
with:
IMG_PATH: <images-folder>
IMG_REPOSITORY: <username>/<imagerepo>
If you're executing the workflow on your Profile Repository (<username>/<username>
)
You wouldn't need a GitHub Access Token since GitHub Actions already makes one for you.
Please follow the steps below:
- Go to your
<username>/<username>/actions
, hitNew workflow
, thenset up a workflow yourself
, delete all the default content github made for you. - Copy the following code and paste it to your new workflow you created at step 1:
name: Update Image Readme
on:
workflow_dispatch:
schedule:
# Runs at 1 UTC everyday
- cron: "0 1 * * *"
jobs:
update-readme:
name: Update Image README
runs-on: ubuntu-latest
steps:
- uses: siddharth2016/update-readme-image@main
with:
IMG_ALT: Image ALT
- Make sure you have
.github/images
folder in<username>/<username>
repo. If you have created a different folder, then addIMG_PATH
afterIMG_ALT
underwith
. Check this. - There are other options as well, height/width you want for image and it's alignment within README. Check examples for more.
- Add a comment to your
README.md
like this:
<!--START_SECTION:update_image-->
<!--END_SECTION:update_image-->
- Go to Workflows menu (mentioned in step 1), click
Update Image Readme
, clickRun workflow
. - Go to your profile page, you will be able to see a random image from your collection of images.
If you're executing the workflow on another repo other than (<username>/<username>
)
You'll need to get a GitHub Access Token with a repo
scope.
You need to save the GitHub API Token in the repository secrets. You can find that in the Settings of your Repository.
- Go to your
<username>/<differentrepo>/actions
, hitNew workflow
, thenset up a workflow yourself
, delete all the default content github made for you. - Copy the following code and paste it to your new workflow you created at step 1:
name: Update Image Readme
on:
workflow_dispatch:
schedule:
# Runs at 1 UTC everyday
- cron: "0 1 * * *"
jobs:
update-readme:
name: Update Image README
runs-on: ubuntu-latest
steps:
- uses: siddharth2016/update-readme-image@main
with:
IMG_ALT: Image ALT
GH_TOKEN: ${{ secrets.GH_TOKEN }}
README_REPOSITORY: <username>/<differentrepo> # No need to mention this if workflow present in current non profile repo.
Add IMG_REPOSITORY
or IMG_PATH
as required, check this for more info.
- There are other options as well, height/width you want for image and it's alignment within README. Check examples for more.
- Add a comment to your
README.md
like this:
<!--START_SECTION:update_image-->
<!--END_SECTION:update_image-->
- Go to Workflows menu (mentioned in step 1), click
Update Image Readme
, clickRun workflow
. - Go to your non-profile readme page, you will be able to see a random image from your collection of images.
- If you want to use this action for a README that is not present in current workflow repository.
- uses: siddharth2016/update-readme-image@main
with:
GH_TOKEN: ${{ secrets.GH_TOKEN }} # Needed if README repository is not profile repo
README_REPOSITORY: <username>/<differentrepo>
Using README_REPOSITORY
will change README present in that repository head.
For example, if your workflow is present in <username>/repo1
and you want to update README present in <username>/repo2
, then assign README_REPOSITORY
to <username>/repo2
in workflow at <username>/repo1
.
- If your images are present in a different repository than current workflow repository.
- uses: siddharth2016/update-readme-image@main
with:
GH_TOKEN: ${{ secrets.GH_TOKEN }} # Needed if README repository is not profile repo
README_REPOSITORY: <username>/<differentrepo> # Needed if README repository is not current repo
IMG_PATH: <your-image-directory> # Needed if images are not present in .github/images of image repository
IMG_REPOSITORY: <username>/<imagerepo>
It's better to have all images in .github/images
to avoid any confusion and keep the images in same repository as of README and workflow repository.
- If you want to set image alt, height, width and alignment, then use these flags:
- uses: siddharth2016/update-readme-image@main
with:
GH_TOKEN: ${{ secrets.GH_TOKEN }} # Needed if README repository is not profile repo
README_REPOSITORY: <username>/<differentrepo> # Needed if README repository is not current repo
IMG_PATH: <your-image-directory> # Needed if images are not present in .github/images of image repository
IMG_REPOSITORY: <username>/<imagerepo> # Needed if images are not present in current repo
HEIGHT: 180px # default
WIDTH: 180px # default
ALIGN: right # default
IMG_ALT: Profile Image # default
- You can specify a commit message to override the default "Update Readme Image".
- uses: siddharth2016/update-readme-image@main
with:
GH_TOKEN: ${{ secrets.GH_TOKEN }} # Needed if README repository is not profile repo
README_REPOSITORY: <username>/<differentrepo> # Needed if README repository is not current repo
IMG_PATH: <your-image-directory> # Needed if images are not present in .github/images of image repository
IMG_REPOSITORY: <username>/<imagerepo> # Needed if images are not present in current repo
HEIGHT: 180px # default
WIDTH: 180px # default
ALIGN: right # default
IMG_ALT: Profile Image # default
COMMIT_MESSAGE: <your-commit-message> # default - Update Readme Image
To run tests simply execute the following in the directory containing main.py
:
python -m unittest discover