Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e929ba639
|
No files matched your search
@@ -31,6 +31,9 @@ jobs:
|
||||
- run:
|
||||
name: Verify resolved multi-module publication POMs
|
||||
command: python3 tests/test_maven_publication_poms.py
|
||||
- run:
|
||||
name: Verify calculated versions match installed Maven coordinates
|
||||
command: python3 tests/test_effective_publication_version.py
|
||||
pipeline-contract-test:
|
||||
resource_class: small
|
||||
docker:
|
||||
|
||||
@@ -220,3 +220,4 @@ publish-release: check-clean check-branch lint clean dev test-all
|
||||
# an isolated temporary repository. Never publishes or uses signing credentials.
|
||||
test-publication-poms:
|
||||
python3 tests/test_maven_publication_poms.py
|
||||
python3 tests/test_effective_publication_version.py
|
||||
@@ -87,6 +87,11 @@ real publication, not a dry run, verifies the trust relationship.
|
||||
| `hotfix/1.5.1` | `1.5.1` |
|
||||
| `feature/*` | `1.5.0-feature-abc1234-SNAPSHOT` |
|
||||
|
||||
The Maven version step verifies the effective `project.version`, not only the
|
||||
`revision` property. For older POMs with a literal project version, it uses
|
||||
Maven's version plugin to align project and reactor coordinates with the
|
||||
calculated version. A mismatch after updating fails before publication.
|
||||
|
||||
### Java Version
|
||||
|
||||
Maven jobs run on Ubuntu machine executors with Temurin JDK. Default is Java 21. To use Java 17:
|
||||
|
||||
@@ -161,7 +161,7 @@ set_version() {
|
||||
##############################################
|
||||
## Use Maven versions plugin to set version ##
|
||||
##############################################
|
||||
mvn versions:set-property -Dproperty=revision -DnewVersion="$new_version" -DgenerateBackupPoms=false
|
||||
mvn -f "$POM_FILE" versions:set-property -Dproperty=revision -DnewVersion="$new_version" -DgenerateBackupPoms=false
|
||||
|
||||
#######################
|
||||
## Verify the change ##
|
||||
@@ -175,6 +175,26 @@ set_version() {
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_project_version() {
|
||||
local expected=$1 actual
|
||||
# A revision property can exist without being used by project.version.
|
||||
# Ask Maven for the effective coordinate, including inherited configuration.
|
||||
actual=$(mvn -f "$POM_FILE" -q -Dstyle.color=never \
|
||||
org.apache.maven.plugins:maven-help-plugin:3.5.1:evaluate \
|
||||
-Dexpression=project.version -DforceStdout)
|
||||
if [[ "$actual" != "$expected" ]]; then
|
||||
mvn -f "$POM_FILE" -B versions:set -DnewVersion="$expected" -DgenerateBackupPoms=false
|
||||
actual=$(mvn -f "$POM_FILE" -q -Dstyle.color=never \
|
||||
org.apache.maven.plugins:maven-help-plugin:3.5.1:evaluate \
|
||||
-Dexpression=project.version -DforceStdout)
|
||||
fi
|
||||
if [[ "$actual" != "$expected" ]]; then
|
||||
echo "ERROR: Effective project version is $actual; expected $expected" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Verified effective project version: $actual"
|
||||
}
|
||||
|
||||
#############################################
|
||||
## Branch Detection and Routing Functions ##
|
||||
#############################################
|
||||
@@ -434,6 +454,9 @@ main() {
|
||||
fi
|
||||
|
||||
echo ""
|
||||
if [[ "$DRY_RUN" != "true" ]]; then
|
||||
ensure_project_version "$NEW_VERSION"
|
||||
fi
|
||||
echo "=== Version calculation complete ==="
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Exercise the real version script and Maven install; never publish remotely."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
NS = {'m': 'http://maven.apache.org/POM/4.0.0'}
|
||||
BASH = os.environ.get('TEST_BASH') or shutil.which('bash')
|
||||
MAVEN = shutil.which('mvn') or shutil.which('mvn.cmd')
|
||||
|
||||
|
||||
def run(args, directory, env=None):
|
||||
subprocess.run(args, cwd=directory, env=env, check=True, timeout=300)
|
||||
|
||||
|
||||
def project(body):
|
||||
return '<project xmlns="http://maven.apache.org/POM/4.0.0">\n<modelVersion>4.0.0</modelVersion>\n' + body + '\n</project>\n'
|
||||
|
||||
|
||||
def main():
|
||||
assert BASH and MAVEN, 'Real Bash, Java and Maven are required'
|
||||
with tempfile.TemporaryDirectory(prefix='qqq-version-') as temporary:
|
||||
base = Path(temporary)
|
||||
for name, version, revision, branch, expected, reactor in (
|
||||
('literal', '0.4.0-SNAPSHOT', '0.4.0-RC.1', 'release/0.4', '0.4.0-RC.2', False),
|
||||
('friendly', '${revision}', '0.4.0-RC.1', 'release/0.4', '0.4.0-RC.2', False),
|
||||
('reactor', '0.4.0-SNAPSHOT', '0.4.0-RC.1', 'release/0.4', '0.4.0-RC.2', True),
|
||||
('unchanged', '0.3.0-SNAPSHOT', '0.4.0-SNAPSHOT', 'develop', '0.4.0-SNAPSHOT', False),
|
||||
):
|
||||
root = base / name
|
||||
root.mkdir()
|
||||
modules = '<modules><module>child</module></modules>' if reactor else ''
|
||||
(root / 'pom.xml').write_text(project(f'''<groupId>example.version</groupId>
|
||||
<artifactId>{name}</artifactId><version>{version}</version><packaging>pom</packaging>
|
||||
<properties>
|
||||
<revision>{revision}</revision>
|
||||
</properties>
|
||||
{modules}'''), encoding='utf-8')
|
||||
if reactor:
|
||||
(root / 'child').mkdir()
|
||||
(root / 'child/pom.xml').write_text(project(f'''<parent><groupId>example.version</groupId>
|
||||
<artifactId>{name}</artifactId><version>{version}</version></parent>
|
||||
<artifactId>child</artifactId><packaging>pom</packaging>'''), encoding='utf-8')
|
||||
run(['git', 'init', '-q'], root)
|
||||
env = dict(os.environ, CIRCLE_BRANCH=branch, CIRCLE_TAG='')
|
||||
run([BASH, str(ROOT / 'src/scripts/calculate_version.sh')], root, env)
|
||||
if name == 'friendly':
|
||||
assert ET.parse(root / 'pom.xml').findtext('m:version', namespaces=NS) == '${revision}'
|
||||
# Install to a temporary repository so the actual artifact coordinate
|
||||
# proves the fix, rather than merely checking the revision property.
|
||||
repository = base / 'repository'
|
||||
run([MAVEN, '-B', '-ntp', '-Dmaven.repo.local=' + str(repository),
|
||||
'-Dflatten.mode=resolveCiFriendliesOnly', '-DupdatePomFile=true',
|
||||
'org.codehaus.mojo:flatten-maven-plugin:1.7.3:flatten', 'install'], root)
|
||||
for artifact in ([name, 'child'] if reactor else [name]):
|
||||
installed = repository / 'example/version' / artifact / expected / f'{artifact}-{expected}.pom'
|
||||
assert installed.exists(), installed
|
||||
pom = ET.parse(installed)
|
||||
actual = pom.findtext('m:version', namespaces=NS) or pom.findtext('m:parent/m:version', namespaces=NS)
|
||||
assert actual == expected, (artifact, actual, expected)
|
||||
print(f'PASS: {name} installed at {expected}', flush=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user