Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eschleb committed Dec 3, 2024
0 parents commit fce27fe
Show file tree
Hide file tree
Showing 35 changed files with 1,970 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/release-and-deploy-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: release and deploy

on:
push:
branches:
- main

jobs:
release:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Maven setup
uses: s4u/[email protected]
with:
servers: |
[{
"id": "magnolia.enterprise.group",
"username": "${{secrets.MGNL_NEXUS_USER}}",
"password": "${{secrets.MGNL_NEXUS_PASS}}"
}]
- name: Maven verify
run: mvn verify --batch-mode
# Install xmllint
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install libxml2-utils
# Set git user name and email
- name: Set up Git
run: |
chmod +x ci/setup-git.sh
ci/setup-git.sh
# Release, set correct versions and create tag
- name: Release (versioning/tag)
run: |
chmod +x ci/mvn-release.sh
ci/mvn-release.sh
deploy-release:

needs: release
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: 'main'
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-passphrase: MAVEN_GPG_PASSPHRASE
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
- name: Release Maven package
run: mvn deploy -Pdeploy
env:
MAVEN_USERNAME: ${{ secrets.SONATYPE_USER }}
MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
29 changes: 29 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: verify

on:
push:
branches-ignore:
- main

jobs:
verify:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Maven setup
uses: s4u/[email protected]
with:
servers: |
[{
"id": "magnolia.enterprise.group",
"username": "${{secrets.MGNL_NEXUS_USER}}",
"password": "${{secrets.MGNL_NEXUS_PASS}}"
}]
- name: Maven verify
run: mvn verify --batch-mode
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
135 changes: 135 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Magnolia Testing

The spring renderer module makes the Spring-Framework available for Magnolia. <bR>
Recommended to be used with [dynamic builders modules](https://github.com/merkle-open/magnolia-dynamic-builders).

## Requirements
* Java 17
* Magnolia >= 6.3

## Setup

- Add Maven dependency:
```xml
<dependency>
<groupId>com.merkle.oss.magnolia</groupId>
<artifactId>magnolia-testing</artifactId>
<version>0.0.1</version>
</dependency>
```
- Add a magnolia module descriptor in your `src/test/resources/META-INF/magnolia` directory (Bindings can differ from non-test setup).


### [Integration Test](src/test/java/com/merkle/oss/magnolia/testing/SampleIntegrationTest.java)
Creates guice context and starts all magnolia modules. Can import jcr exports (xml files) into repository using [@Repository](src/main/java/com/merkle/oss/magnolia/testing/repository/Repository.java) annotation.
```java
import static io.smallrye.common.constraint.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import info.magnolia.context.MgnlContext;
import info.magnolia.objectfactory.Components;
import info.magnolia.repository.RepositoryConstants;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import com.merkle.oss.magnolia.testing.MagnoliaIntegrationTestExtension;
import com.merkle.oss.magnolia.testing.repository.Repository;

@ExtendWith(MagnoliaIntegrationTestExtension.class)
class SampleIntegrationTest {

@Repository(workspaces = {@Repository.Workspace(name = RepositoryConstants.WEBSITE, xml = "jcr.xml")})
@Test
void someMethod() throws RepositoryException {
final Session session = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE);
final Node node = session.getRootNode().getNode("0");
final SomeInterface someInterface = Components.getComponent(SomeInterface.class);
assertEquals("some value 42!", someInterface.someMethod(node));
session.logout();
}
}
```

### [Guice Context Test](src/test/java/com/merkle/oss/magnolia/testing/SampleGuiceContextTest.java)
Only creates guice context, but doesn't start magnolia modules. Can import jcr exports (xml files) into repository, create workspaces and import nodeTypes using [@Repository](src/main/java/com/merkle/oss/magnolia/testing/repository/Repository.java) annotation.

```java
import static org.junit.jupiter.api.Assertions.assertEquals;

import info.magnolia.context.MgnlContext;
import info.magnolia.objectfactory.Components;
import info.magnolia.repository.RepositoryConstants;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import com.merkle.oss.magnolia.testing.MagnoliaGuiceContextTestExtension;
import com.merkle.oss.magnolia.testing.repository.Repository;

@Repository(
nodeTypes = { @Repository.NodeTypesDefinition(cnd = "/mgnl-nodetypes/testing-nodetypes.cnd") },
workspaces = { @Repository.Workspace(name = "testing", xml = "jcr-custom-nodetype.xml", create = true) }
)
@ExtendWith(MagnoliaGuiceContextTestExtension.class)
class SampleGuiceContextTest {

@Test
void someMethod() throws RepositoryException {
final Session session = MgnlContext.getJCRSession("testing");
final Node node = session.getRootNode().getNode("0");
final SomeInterface someInterface = Components.getComponent(SomeInterface.class);
assertEquals("some value 42!", someInterface.someMethod(node));
}
}

```
### Custom Magnolia properties
Custom property files can be specified using the [`@TestConfiguration`](src/main/java/com/merkle/oss/magnolia/testing/configuration/TestConfiguration.java) annotation.

```java
import com.merkle.oss.magnolia.testing.MagnoliaGuiceContextTestExtension;
import com.merkle.oss.magnolia.testing.configuration.TestConfiguration;

@TestConfiguration(magnoliaProperties = "/magnolia-testing.properties")
@ExtendWith(MagnoliaGuiceContextTestExtension.class)
class SampleGuiceContextTest {}
```

#### Placeholders
- `${resource.home}` is replaced by your projects `src/test/resources` directory.
- e.g. `magnolia.repositories.config=${resource.home}/repositories.xml`
- `classpath:` is replaced by any classpath resource
- e.g. `classpath:/repository/InMemoryJcrRepositoryConfiguration.xml`
- `magnolia.app.rootdir` is replaced by a random generated temporary folder (for each test)
- e.g. `magnolia.home=${magnolia.app.rootdir}`

### Test specific component bindings
Test specific component bindings can be configured using the [`@TestConfiguration`](src/main/java/com/merkle/oss/magnolia/testing/configuration/TestConfiguration.java) annotation.

```java
import org.junit.jupiter.api.extension.ExtendWith;

import com.merkle.oss.magnolia.testing.MagnoliaIntegrationTestExtension;
import com.merkle.oss.magnolia.testing.configuration.TestConfiguration;

@ExtendWith(MagnoliaIntegrationTestExtension.class)
class SampleGuiceContextTest {

@Test
@TestConfiguration(components = {
@TestConfiguration.Component(type = SomeInterface.class, implementation = SomeInterface.SomeOtherImplementation.class)
})
void someOtherMethod() {
...
}
}
```
35 changes: 35 additions & 0 deletions ci/mvn-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

CURRENT_VERSION=`xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml`

if [[ $CURRENT_VERSION == *-SNAPSHOT ]]; then
NEW_VERSION=${CURRENT_VERSION%'-SNAPSHOT'}
NEXT_VERSION=`bash ci/semver.sh -p $NEW_VERSION`
NEXT_SNAPSHOT="$NEXT_VERSION-SNAPSHOT"
echo "perform release of $NEW_VERSION from $CURRENT_VERSION and set next develop version $NEXT_SNAPSHOT"

mvn versions:set -DnewVersion=$NEW_VERSION versions:commit --no-transfer-progress

echo "commit new release version"
git commit -a -m "Release $NEW_VERSION: set main to new release version"

echo "Update version in README.md"
sed -i -e "s|<version>[0-9A-Za-z._-]\{1,\}</version>|<version>$NEW_VERSION</version>|g" README.md && rm -f README.md-e
git commit -a -m "Release $NEW_VERSION: Update README.md"

echo "create tag for new release"
git tag -a $NEW_VERSION -m "Release $NEW_VERSION: tag release"

echo "merge main back to develop"
git fetch --all
git checkout develop
git merge main

mvn versions:set -DnewVersion=$NEXT_SNAPSHOT versions:commit --no-transfer-progress

echo "commit new snapshot version"
git commit -a -m "Release $NEW_VERSION: set develop to next development version $NEXT_SNAPSHOT"

git push --all
git push --tags
fi
52 changes: 52 additions & 0 deletions ci/semver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

# Increment a version string using Semantic Versioning (SemVer) terminology.

# Parse command line options.

while getopts ":Mmp" Option
do
case $Option in
M ) major=true;;
m ) minor=true;;
p ) patch=true;;
esac
done

shift $(($OPTIND - 1))

version=$1

# Build array from version string.

a=( ${version//./ } )

# If version string is missing or has the wrong number of members, show usage message.

if [ ${#a[@]} -ne 3 ]
then
echo "usage: $(basename $0) [-Mmp] major.minor.patch"
exit 1
fi

# Increment version numbers as requested.

if [ ! -z $major ]
then
((a[0]++))
a[1]=0
a[2]=0
fi

if [ ! -z $minor ]
then
((a[1]++))
a[2]=0
fi

if [ ! -z $patch ]
then
((a[2]++))
fi

echo "${a[0]}.${a[1]}.${a[2]}"
4 changes: 4 additions & 0 deletions ci/setup-git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

git config --global user.email "[email protected]"
git config --global user.name "Namics OSS CI"
Loading

0 comments on commit fce27fe

Please sign in to comment.