|
18 | 18 | required: true
|
19 | 19 | type: string
|
20 | 20 | 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.' |
21 | 25 | # We do not need to require the secrets.GITHUB_TOKEN here because it is automatically
|
22 | 26 | # inherited from the workflow call [^1].
|
23 | 27 | #
|
|
46 | 50 | # If true, the container image will be tagged with the major version (e.g., '1') when pushed to the registries.
|
47 | 51 | LATEST_MAJOR: false
|
48 | 52 |
|
| 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 | + |
49 | 57 | jobs:
|
50 | 58 | build-and-publish:
|
51 | 59 | name: Build and Publish
|
@@ -177,3 +185,44 @@ jobs:
|
177 | 185 | subject-name: index.docker.io/${{ env.IMAGE_NAME }}
|
178 | 186 | subject-digest: ${{ steps.build-and-push.outputs.digest }}
|
179 | 187 | 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