|
3 | 3 | # builds, and builds the container images using the Containerfile. For all non-pull request events that
|
4 | 4 | # trigger this workflow, it logs into GHCR and Docker Hub using credentials from the workflow call inputs,
|
5 | 5 | # 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. |
7 | 10 |
|
8 | 11 | name: Container Image
|
9 | 12 |
|
|
18 | 21 | required: true
|
19 | 22 | type: string
|
20 | 23 | 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.' |
21 | 28 | # We do not need to require the secrets.GITHUB_TOKEN here because it is automatically
|
22 | 29 | # inherited from the workflow call [^1].
|
23 | 30 | #
|
|
46 | 53 | # If true, the container image will be tagged with the major version (e.g., '1') when pushed to the registries.
|
47 | 54 | LATEST_MAJOR: false
|
48 | 55 |
|
| 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 | + |
49 | 60 | jobs:
|
50 | 61 | build-and-publish:
|
51 | 62 | name: Build and Publish
|
@@ -177,3 +188,43 @@ jobs:
|
177 | 188 | subject-name: index.docker.io/${{ env.IMAGE_NAME }}
|
178 | 189 | subject-digest: ${{ steps.build-and-push.outputs.digest }}
|
179 | 190 | 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