Skip to content

Commit c3615ec

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

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

.github/workflows/container-image.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ on:
1818
required: true
1919
type: string
2020
description: 'URL to the Icinga documentation for this project.'
21+
container_readme_filepath:
22+
required: false
23+
type: string
24+
description: 'Path to the README file to sync with Docker Hub. Defaults to the first For-Container.md file found in the ./doc/ directory.'
2125
# We do not need to require the secrets.GITHUB_TOKEN here because it is automatically
2226
# inherited from the workflow call [^1].
2327
#
@@ -46,6 +50,10 @@ env:
4650
# If true, the container image will be tagged with the major version (e.g., '1') when pushed to the registries.
4751
LATEST_MAJOR: false
4852

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

0 commit comments

Comments
 (0)