Skip to content

Commit cadb12d

Browse files
committed
Add a step for syncing README.md to Docker Hub in container-image.yml
1 parent a9e5e60 commit cadb12d

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

.github/workflows/container-image.yml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
# builds, and builds the container images using the Containerfile. For all non-pull request events that
44
# trigger this workflow, it logs into GHCR and Docker Hub using credentials from the workflow call inputs,
55
# tags and pushes the images to both registries, and generates and pushes signed build provenance attestations
6-
# to each registry. For pull request events, it just builds the images but does not push them to the registries.
6+
# to each registry. Additionally, when a building and publishing the latest tag, it syncs the README file
7+
# determined by the container_readme_filepath input (or the first For-Container.md file found in the ./doc/
8+
# directory if not provided) with Docker Hub if it has been modified since the previous version of the latest
9+
# tag. For pull request events, it just builds the images but does not push them to the registries.
710

811
name: Container Image
912

@@ -18,6 +21,10 @@ on:
1821
required: true
1922
type: string
2023
description: 'URL to the Icinga documentation for this project.'
24+
container_readme_filepath:
25+
required: false
26+
type: string
27+
description: 'Path to the README file to sync with Docker Hub. Defaults to the first For-Container.md file found in the ./doc/ directory.'
2128
# We do not need to require the secrets.GITHUB_TOKEN here because it is automatically
2229
# inherited from the workflow call [^1].
2330
#
@@ -46,6 +53,10 @@ env:
4653
# If true, the container image will be tagged with the major version (e.g., '1') when pushed to the registries.
4754
LATEST_MAJOR: false
4855

56+
# The path to the README file to sync with Docker Hub. If not provided, it defaults to
57+
# the first For-Container.md file found in the ./doc/ directory.
58+
README_FILEPATH: ${{ inputs.container_readme_filepath }}
59+
4960
jobs:
5061
build-and-publish:
5162
name: Build and Publish
@@ -177,3 +188,43 @@ jobs:
177188
subject-name: index.docker.io/${{ env.IMAGE_NAME }}
178189
subject-digest: ${{ steps.build-and-push.outputs.digest }}
179190
push-to-registry: false
191+
192+
- name: Prepare For-Container.md file
193+
if: ${{ env.LATEST == 'true' }}
194+
run: |
195+
if [ -z "${{ env.README_FILEPATH }}" ]; then
196+
file_path=$(find ./doc/ -type f -name 'For-Container.md' | head -n 1)
197+
if [ -z "$file_path" ]; then
198+
echo "No For-Container.md file found in the ./doc/ directory."
199+
exit 1
200+
fi
201+
echo "No custom container README file path provided. Using default path: $file_path"
202+
echo "README_FILEPATH=$file_path" >> "$GITHUB_ENV"
203+
else
204+
# Check if the provided file exists.
205+
if [ -f "${{ env.README_FILEPATH }}" ]; then
206+
echo "Using provided container README file path: ${{ env.README_FILEPATH }}"
207+
else
208+
echo "Provided container README file path does not exist: ${{ env.README_FILEPATH }}"
209+
exit 1
210+
fi
211+
fi
212+
213+
# Check if the README file has been modified since the github.event.before reference point
214+
# and write the result to the README_MODIFIED ENV variable.
215+
if ! git diff --quiet --exit-code ${{ github.event.before }} "${{ env.README_FILEPATH }}"; then
216+
echo "README file has been modified since the last commit."
217+
echo "README_MODIFIED=true" >> "$GITHUB_ENV"
218+
else
219+
echo "README file has not been modified since the last commit."
220+
echo "README_MODIFIED=false" >> "$GITHUB_ENV"
221+
fi
222+
223+
- name: Sync For-Container.md
224+
uses: ms-jpq/sync-dockerhub-readme@e2991ea1ba48832e73555cdbd5b82f5a2e91ee9b # v1
225+
if: ${{ env.README_MODIFIED == 'true' }}
226+
with:
227+
username: ${{ secrets.dockerhub_username }}
228+
password: ${{ secrets.dockerhub_token }}
229+
repository: ${{ env.IMAGE_NAME }}
230+
readme: ${{ env.README_FILEPATH }}

0 commit comments

Comments
 (0)