From fdf4e60018ef0212225a7475c20bff28127cf666 Mon Sep 17 00:00:00 2001 From: Lennard Golsch Date: Tue, 24 Nov 2026 09:52:44 +0100 Subject: [PATCH 1/3] feat: add the Maven coordinates and download links of a release to its notes --- .github/actions/github-release/action.yml | 9 +- .../actions/maven-release-notes/action.yml | 30 +++++ .github/actions/maven-release-notes/notes.py | 111 ++++++++++++++++++ .github/workflows/maven-release.yml | 41 ++++++- README.md | 3 +- docs/maven-release.md | 39 ++++-- 6 files changed, 214 insertions(+), 19 deletions(-) create mode 100644 .github/actions/maven-release-notes/action.yml create mode 100644 .github/actions/maven-release-notes/notes.py diff --git a/.github/actions/github-release/action.yml b/.github/actions/github-release/action.yml index f744c1b..4b790b9 100644 --- a/.github/actions/github-release/action.yml +++ b/.github/actions/github-release/action.yml @@ -10,7 +10,7 @@ inputs: required: false default: '' notes-file: - description: File appended to the generated notes, empty to skip + description: Files appended to the generated notes in this order, one per line, empty to skip required: false default: '' assets: @@ -60,10 +60,11 @@ runs: gh api --method POST "repos/${GITHUB_REPOSITORY}/releases/generate-notes" \ "${NOTES_ARGS[@]}" --jq '.body' > "${RUNNER_TEMP}/release-notes.md" - if [ -n "$NOTES_FILE" ]; then - NOTES="$(< "$NOTES_FILE")" + while IFS= read -r notes_file; do + [ -z "$notes_file" ] && continue + NOTES="$(< "$notes_file")" printf '\n%s\n' "${NOTES//@VERSION@/$VERSION}" >> "${RUNNER_TEMP}/release-notes.md" - fi + done <<< "$NOTES_FILE" gh release create "$TAG" \ --title "$TAG" \ diff --git a/.github/actions/maven-release-notes/action.yml b/.github/actions/maven-release-notes/action.yml new file mode 100644 index 0000000..a110843 --- /dev/null +++ b/.github/actions/maven-release-notes/action.yml @@ -0,0 +1,30 @@ +name: Maven Release Notes +description: >- + Write the Maven section of the release notes from a bundle for Central: a dependency for every named component with + a jar or war, and a table with the links to its files on Maven Central. Reads only the entries of the bundle. + +inputs: + bundle: + description: Path of the bundle for Central + required: true + version: + description: Version of the release + required: true + coordinates: + description: Components of the bundle, one per line, as groupId:artifactId or artifactId + required: true + output: + description: File the section is written to + required: true + +runs: + using: composite + steps: + - shell: bash + env: + BUNDLE: ${{ inputs.bundle }} + VERSION: ${{ inputs.version }} + COORDINATES: ${{ inputs.coordinates }} + OUTPUT: ${{ inputs.output }} + run: | + python3 -I "$GITHUB_ACTION_PATH/notes.py" diff --git a/.github/actions/maven-release-notes/notes.py b/.github/actions/maven-release-notes/notes.py new file mode 100644 index 0000000..ac32a6a --- /dev/null +++ b/.github/actions/maven-release-notes/notes.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +"""Writes the Maven section of the release notes to OUTPUT: a dependency for every component of COORDINATES with a jar +or war, and a table with the links to its files on Maven Central. COORDINATES names one component of BUNDLE per line, +as groupId:artifactId or as artifactId alone. The entries of the bundle are only read, nothing is extracted.""" +import os +import sys +import zipfile +from pathlib import Path + +sys.dont_write_bytecode = True +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "central-bundle-check")) +from pom_components import NAME, fail # noqa: E402 + +CHECKSUMS = (".md5", ".sha1", ".sha256", ".sha512", ".asc") +REPOSITORY = "https://repo1.maven.org/maven2" +CENTRAL = "https://central.sonatype.com/artifact" + + +def read_bundle(bundle, version): + result = {} + try: + with zipfile.ZipFile(bundle) as archive: + names = archive.namelist() + except Exception as error: + fail(f"the bundle cannot be read as zip file: {error!r}") + for name in names: + if name.endswith("/") or name.endswith(CHECKSUMS): + continue + parts = name.split("/") + if len(parts) < 4 or any(part in (".", "..") or not NAME.fullmatch(part) for part in parts): + fail(f"the bundle contains {name}, which is no file of a Maven component") + group, (artifact, directory, file) = parts[:-3], parts[-3:] + prefix = f"{artifact}-{version}" + if directory != version or not file.startswith((f"{prefix}.", f"{prefix}-")): + fail(f"the bundle contains {name}, which is no file of a component in version {version}") + result.setdefault(f"{'.'.join(group)}:{artifact}", []).append(file[len(prefix):]) + return result + + +def select(components, coordinates): + selected = [] + for line in coordinates.splitlines(): + wanted = line.strip() + if not wanted: + continue + if not all(NAME.fullmatch(part) for part in wanted.split(":")) or wanted.count(":") > 1: + fail(f"release-coordinates has '{wanted}', expected groupId:artifactId or artifactId") + if ":" in wanted: + matches = [wanted] if wanted in components else [] + else: + matches = [key for key in components if key.split(":")[1] == wanted] + if not matches: + fail(f"release-coordinates names {wanted}, but the bundle for Central has no such component") + if len(matches) > 1: + fail(f"release-coordinates names {wanted}, which is {' and '.join(sorted(matches))}, give the groupId") + if matches[0] not in selected: + selected.append(matches[0]) + return selected + + +def split(suffix): + if suffix.startswith("."): + return "", suffix[1:] + classifier, _, extension = suffix[1:].partition(".") + return classifier, extension + + +def main(): + version = os.environ["VERSION"] + components = read_bundle(os.environ["BUNDLE"], version) + selected = select(components, os.environ.get("COORDINATES", "")) + if not selected: + fail("release-coordinates names no component") + + dependencies, rows = [], [] + for key in selected: + group, artifact = key.split(":") + base = f"{REPOSITORY}/{group.replace('.', '/')}/{artifact}/{version}" + files = sorted(split(suffix) for suffix in components[key]) + + def link(classifier, extension): + label = extension if not classifier else classifier if extension == "jar" else f"{classifier}.{extension}" + name = f"{artifact}-{version}{'-' + classifier if classifier else ''}.{extension}" + return f"[{label}]({base}/{name})" + + mains = [extension for classifier, extension in files if not classifier and extension != "pom"] + if "jar" in mains or "war" in mains: + dependency = ["", f" {group}", f" {artifact}", + f" {version}"] + if "jar" not in mains: + dependency.append(" war") + dependencies.append("\n".join(dependency + [""])) + + binaries = [link(c, e) for c, e in files if e != "pom" and c not in ("sources", "javadoc")] + sources = [link(c, e) for c, e in files if c == "sources"] + javadoc = [link(c, e) for c, e in files if c == "javadoc"] + pom = [link(c, e) for c, e in files if not c and e == "pom"] + cells = [f"[{artifact}]({CENTRAL}/{group}/{artifact}/{version})"] + cells += [", ".join(column) for column in (binaries, sources, javadoc, pom)] + rows.append("| " + " | ".join(cells) + " |") + + sections = [] + if dependencies: + sections.append("## Maven\n\n```xml\n" + "\n\n".join(dependencies) + "\n```") + sections.append("## Download\n\n| Artifact | Binary | Sources | Javadoc | POM |\n| --- | --- | --- | --- | --- |\n" + + "\n".join(rows)) + Path(os.environ["OUTPUT"]).write_text("\n\n".join(sections) + "\n", encoding="utf-8") + print(f"the release notes name {len(selected)} components, {len(dependencies)} of them as dependency") + + +main() diff --git a/.github/workflows/maven-release.yml b/.github/workflows/maven-release.yml index 06989b3..539a567 100644 --- a/.github/workflows/maven-release.yml +++ b/.github/workflows/maven-release.yml @@ -43,6 +43,9 @@ on: release-notes-file: type: string default: '' + release-coordinates: + type: string + default: '' release-assets: type: string default: | @@ -113,12 +116,20 @@ jobs: DEPENDENCY_ARTIFACT: ${{ inputs.dependency-artifact }} RELEASE_VERSION: ${{ inputs.release-version }} DEV_VERSION: ${{ inputs.development-version }} + RELEASE_COORDINATES: ${{ inputs.release-coordinates }} run: | set -euo pipefail if [ -z "$ENVIRONMENT" ]; then echo "::error::environment is empty, the release secrets belong in an environment" exit 1 fi + while read -r coordinate extra; do + [ -z "$coordinate" ] && continue + if [ -n "$extra" ] || [[ ! "$coordinate" =~ ^[A-Za-z0-9._-]+(:[A-Za-z0-9._-]+)?$ ]]; then + echo "::error::release-coordinates must name one groupId:artifactId or artifactId per line" + exit 1 + fi + done <<< "$RELEASE_COORDINATES" for value in "$RELEASE_VERSION" "$DEV_VERSION" "$DEPENDENCY_VERSION" "$DEPENDENCY_DEV_VERSION" "$DEPENDENCY_ARTIFACT"; do if [[ "$value" =~ [[:space:]] ]]; then echo "::error::'${value}' contains whitespace" @@ -581,6 +592,24 @@ jobs: SHA256="$(sha256sum "${RUNNER_TEMP}/central/central-bundle.zip" | cut -d ' ' -f 1)" echo "sha256=${SHA256}" >> "$GITHUB_OUTPUT" + - name: Write the Maven section of the release notes + if: inputs.release-coordinates != '' + uses: $/.github/actions/maven-release-notes + with: + bundle: ${{ runner.temp }}/central/central-bundle.zip + version: ${{ needs.prepare.outputs.version }} + coordinates: ${{ inputs.release-coordinates }} + output: ${{ runner.temp }}/maven-release-notes/maven.md + + - if: inputs.release-coordinates != '' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: maven-release-notes + path: ${{ runner.temp }}/maven-release-notes/maven.md + if-no-files-found: error + retention-days: 1 + overwrite: true + # valid for one hour and for this repository only, so it is created right before the push - name: Create the push token id: push-token @@ -730,7 +759,7 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} github-release: - needs: [prepare, build, publish] + needs: [prepare, build, push, publish] runs-on: ubuntu-latest cache-mode: none permissions: @@ -748,10 +777,18 @@ jobs: name: release-assets path: release-assets + - if: inputs.release-coordinates != '' + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: maven-release-notes + path: ${{ runner.temp }}/maven-release-notes + - uses: $/.github/actions/github-release with: tag: v${{ needs.prepare.outputs.version }} - notes-file: ${{ inputs.release-notes-file }} + notes-file: | + ${{ inputs.release-coordinates != '' && format('{0}/maven-release-notes/maven.md', runner.temp) || '' }} + ${{ inputs.release-notes-file }} assets: ${{ needs.build.outputs.has-assets == 'true' && 'release-assets/*' || '' }} # only if nothing reached Central or Central refused it, after an upload in an unknown state the version may still be diff --git a/README.md b/README.md index 3eb6729..3b64595 100644 --- a/README.md +++ b/README.md @@ -49,12 +49,13 @@ The workflows are built from these composite actions. | [`maven-pom-pin`](.github/actions/maven-pom-pin/action.yml) | Set a version property and the scm url in a `pom.xml`, return the previous values | | [`docker-build`](.github/actions/docker-build/action.yml) | Build images without credentials and save them to an archive | | [`docker-push`](.github/actions/docker-push/action.yml) | Load the images of `docker-build`, tag them and push them to Docker Hub | -| [`github-release`](.github/actions/github-release/action.yml) | Create a GitHub release with generated notes, a notes file and assets | +| [`github-release`](.github/actions/github-release/action.yml) | Create a GitHub release with generated notes, notes files and assets | | [`workflow-dispatch`](.github/actions/workflow-dispatch/action.yml) | Dispatch workflows in other repositories, optionally wait for their results | | [`matrix-notify`](.github/actions/matrix-notify/action.yml) | Send a message to a Matrix room | | [`check-trigger`](.github/actions/check-trigger/action.yml) | Fail unless the run is on a branch and not started by the account of `DISPATCH_TOKEN` | | [`pom-diff-check`](.github/actions/pom-diff-check/action.yml) | Fail unless a commit changes nothing but given values in `pom.xml` files | | [`central-bundle-check`](.github/actions/central-bundle-check/action.yml) | Check that a bundle for Central holds only unsigned files of the project and its modules in one version | +| [`maven-release-notes`](.github/actions/maven-release-notes/action.yml) | Write the Maven coordinates and download links of components of a bundle for Central as release notes | | [`central-publish`](.github/actions/central-publish/action.yml) | Check and sign a bundle for Central, upload it and wait for its validation | | [`snapshot-upload`](.github/actions/snapshot-upload/action.yml) | Check the snapshots of a build against the poms of the project, upload them | diff --git a/docs/maven-release.md b/docs/maven-release.md index 6b82afd..801341d 100644 --- a/docs/maven-release.md +++ b/docs/maven-release.md @@ -92,6 +92,7 @@ Other project specific steps run in the caller after the release, using the `ver | `maven-opts` | no | | `MAVEN_OPTS` of prepare and build, e.g. `-Xss128M` | | `group-id-prefix` | no | `org.mycore` | groupId every published file must have, or start with followed by a dot | | `release-notes-file` | no | | File in the repository appended to the release notes, `@VERSION@` is replaced | +| `release-coordinates` | no | | Components for the Maven section of the release notes, one per line, see [Release notes](#release-notes-and-assets) | | `release-assets` | no | jars and wars of the root and of each module | Glob patterns of files attached to the GitHub release, one per line, empty to attach none | | `docker-images` | no | | Images to push, see [Docker images](#docker-images) | | `setup-browser` | no | `false` | See [`maven-build.yml`](maven-build.md) | @@ -186,6 +187,8 @@ flowchart LR the run here. - Every component in the bundle for Central has its pom and every file its md5 and sha1, Central refuses the bundle otherwise. + - Every component of `release-coordinates` is in the bundle for Central. push writes the + [Maven section](#release-notes-and-assets) of the release notes from it and keeps it as artifact for one day. Then branch and tag are pushed in one atomic push, with a token of the GitHub App created right before. If someone pushed to the branch in the meantime, nothing is pushed and the run fails. @@ -196,7 +199,8 @@ flowchart LR the publisher API of Central for automatic publishing and waits up to 30 minutes until Central has validated it. 6. **images** and **github-release** run after a successful publish, independently of each other. images pushes the images of build, tagged with the version. github-release creates the GitHub release `v` with the notes - GitHub generates since the previous `v*` tag, the [notes file](#release-notes-and-assets) and the assets. + GitHub generates since the previous `v*` tag, the [Maven section and the notes file](#release-notes-and-assets) + and the assets. 7. **rollback** runs if publish failed or was cancelled before the upload, or if Central refused the upload. It reverts the release commits in one commit "Roll back the release of v<version>", pushes it and deletes the tag in one atomic push. The poms are the ones of before the release, commits pushed since the release stay. @@ -270,20 +274,31 @@ The tags `v*` of the repository should only change through this workflow: ## Release notes and assets -`release-notes-file` is a file in the repository, appended to the generated notes, with `@VERSION@` replaced -by the version. It is the place for the Maven coordinates and download links: +`release-coordinates` names components of the bundle for Central, one per line, as `groupId:artifactId` or as +`artifactId` alone if no other component has it. The release notes then get a section `Maven` with a dependency for +each of them with a jar or a war, and a section `Download` with a table of the links to their files on Maven Central: +binaries, sources, javadoc and pom, as far as the bundle has them, and the page of the component on Central. A name +that is no component of the bundle fails push, before anything is pushed. For `mir`: -````markdown -## Maven +```yaml + with: + release-coordinates: | + mir-module + mir-layout + mir-common-resources + mir-wizard + mir-webapp + mir-cli +``` + +`release-notes-file` is a file in the repository, appended after it, with `@VERSION@` replaced by the version, e.g. +for the Docker images: + +```markdown +## Docker -```xml - - org.mycore - mycore-base - @VERSION@ - +`mycoreorg/mir:@VERSION@` and `mycoreorg/mir-solr:@VERSION@` ``` -```` `release-assets` attaches the jars and wars of the root project and of each module of the build of the tag by default. Projects with many modules, like `mycore`, set it to `''`. From 74c0e9b041d027d27df4c6353a9d6597910d5e9d Mon Sep 17 00:00:00 2001 From: Lennard Golsch Date: Tue, 24 Nov 2026 09:53:59 +0100 Subject: [PATCH 2/3] fix: rename the loop variable of the notes files --- .github/actions/github-release/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/github-release/action.yml b/.github/actions/github-release/action.yml index 4b790b9..c8e673a 100644 --- a/.github/actions/github-release/action.yml +++ b/.github/actions/github-release/action.yml @@ -60,9 +60,9 @@ runs: gh api --method POST "repos/${GITHUB_REPOSITORY}/releases/generate-notes" \ "${NOTES_ARGS[@]}" --jq '.body' > "${RUNNER_TEMP}/release-notes.md" - while IFS= read -r notes_file; do - [ -z "$notes_file" ] && continue - NOTES="$(< "$notes_file")" + while IFS= read -r file; do + [ -z "$file" ] && continue + NOTES="$(< "$file")" printf '\n%s\n' "${NOTES//@VERSION@/$VERSION}" >> "${RUNNER_TEMP}/release-notes.md" done <<< "$NOTES_FILE" From 2c50ba624c6f31f38ed0b524f13f479c93965649 Mon Sep 17 00:00:00 2001 From: Lennard Golsch Date: Tue, 24 Nov 2026 10:08:22 +0100 Subject: [PATCH 3/3] fix: create the directory of the release notes and list only unclassified files as binaries --- .github/actions/github-release/action.yml | 4 ++-- .github/actions/maven-release-notes/notes.py | 6 ++++-- .github/workflows/maven-release.yml | 6 ++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/actions/github-release/action.yml b/.github/actions/github-release/action.yml index c8e673a..c0da248 100644 --- a/.github/actions/github-release/action.yml +++ b/.github/actions/github-release/action.yml @@ -1,12 +1,12 @@ name: GitHub Release -description: Create a GitHub release with generated notes, an optional notes file and assets. +description: Create a GitHub release with generated notes, optional notes files and assets. inputs: tag: description: Tag of the release (e.g. 'v2025.06.2') required: true version: - description: Value replacing '@VERSION@' in the notes file, defaults to the tag without leading 'v' + description: Value replacing '@VERSION@' in the notes files, defaults to the tag without leading 'v' required: false default: '' notes-file: diff --git a/.github/actions/maven-release-notes/notes.py b/.github/actions/maven-release-notes/notes.py index ac32a6a..81e6c06 100644 --- a/.github/actions/maven-release-notes/notes.py +++ b/.github/actions/maven-release-notes/notes.py @@ -91,7 +91,7 @@ def link(classifier, extension): dependency.append(" war") dependencies.append("\n".join(dependency + [""])) - binaries = [link(c, e) for c, e in files if e != "pom" and c not in ("sources", "javadoc")] + binaries = [link(c, e) for c, e in files if not c and e != "pom"] sources = [link(c, e) for c, e in files if c == "sources"] javadoc = [link(c, e) for c, e in files if c == "javadoc"] pom = [link(c, e) for c, e in files if not c and e == "pom"] @@ -104,7 +104,9 @@ def link(classifier, extension): sections.append("## Maven\n\n```xml\n" + "\n\n".join(dependencies) + "\n```") sections.append("## Download\n\n| Artifact | Binary | Sources | Javadoc | POM |\n| --- | --- | --- | --- | --- |\n" + "\n".join(rows)) - Path(os.environ["OUTPUT"]).write_text("\n\n".join(sections) + "\n", encoding="utf-8") + output = Path(os.environ["OUTPUT"]) + output.parent.mkdir(parents=True, exist_ok=True) + output.write_text("\n\n".join(sections) + "\n", encoding="utf-8") print(f"the release notes name {len(selected)} components, {len(dependencies)} of them as dependency") diff --git a/.github/workflows/maven-release.yml b/.github/workflows/maven-release.yml index 539a567..ef2e2a3 100644 --- a/.github/workflows/maven-release.yml +++ b/.github/workflows/maven-release.yml @@ -123,13 +123,19 @@ jobs: echo "::error::environment is empty, the release secrets belong in an environment" exit 1 fi + COORDINATES=0 while read -r coordinate extra; do [ -z "$coordinate" ] && continue if [ -n "$extra" ] || [[ ! "$coordinate" =~ ^[A-Za-z0-9._-]+(:[A-Za-z0-9._-]+)?$ ]]; then echo "::error::release-coordinates must name one groupId:artifactId or artifactId per line" exit 1 fi + COORDINATES=$((COORDINATES + 1)) done <<< "$RELEASE_COORDINATES" + if [ -n "$RELEASE_COORDINATES" ] && [ "$COORDINATES" -eq 0 ]; then + echo "::error::release-coordinates is set but names no component" + exit 1 + fi for value in "$RELEASE_VERSION" "$DEV_VERSION" "$DEPENDENCY_VERSION" "$DEPENDENCY_DEV_VERSION" "$DEPENDENCY_ARTIFACT"; do if [[ "$value" =~ [[:space:]] ]]; then echo "::error::'${value}' contains whitespace"