Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/actions/github-release/action.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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:
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:
Expand Down Expand Up @@ -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 file; do
[ -z "$file" ] && continue
NOTES="$(< "$file")"
printf '\n%s\n' "${NOTES//@VERSION@/$VERSION}" >> "${RUNNER_TEMP}/release-notes.md"
fi
done <<< "$NOTES_FILE"

gh release create "$TAG" \
--title "$TAG" \
Expand Down
30 changes: 30 additions & 0 deletions .github/actions/maven-release-notes/action.yml
Original file line number Diff line number Diff line change
@@ -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"
113 changes: 113 additions & 0 deletions .github/actions/maven-release-notes/notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/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 = ["<dependency>", f" <groupId>{group}</groupId>", f" <artifactId>{artifact}</artifactId>",
f" <version>{version}</version>"]
if "jar" not in mains:
dependency.append(" <type>war</type>")
dependencies.append("\n".join(dependency + ["</dependency>"]))

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"]
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))
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")


main()
47 changes: 45 additions & 2 deletions .github/workflows/maven-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ on:
release-notes-file:
type: string
default: ''
release-coordinates:
type: string
default: ''
release-assets:
type: string
default: |
Expand Down Expand Up @@ -113,12 +116,26 @@ 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
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"
Expand Down Expand Up @@ -581,6 +598,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
Expand Down Expand Up @@ -730,7 +765,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:
Expand All @@ -748,10 +783,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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
39 changes: 27 additions & 12 deletions docs/maven-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down Expand Up @@ -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.
Expand All @@ -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<version>` 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&lt;version&gt;", 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.
Expand Down Expand Up @@ -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
<dependency>
<groupId>org.mycore</groupId>
<artifactId>mycore-base</artifactId>
<version>@VERSION@</version>
</dependency>
`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 `''`.
Expand Down