diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 488b84c..e269a28 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,6 +9,8 @@ on: jobs: matrix-build: runs-on: ubuntu-latest + permissions: + contents: read strategy: fail-fast: true matrix: @@ -39,13 +41,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - name: Publish Test Report - uses: scacap/action-surefire-report@v1 - if: always() - with: - report_paths: '**/target/surefire-reports/TEST-*.xml' - github_token: ${{ secrets.GITHUB_TOKEN }} - build: needs: matrix-build diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 2ab060c..3ec1e65 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -10,7 +10,9 @@ jobs: analyze: name: Analyze runs-on: ubuntu-latest - + permissions: + contents: read + security-events: write strategy: fail-fast: false diff --git a/.github/workflows/github_release.sh b/.github/workflows/github_release.sh new file mode 100755 index 0000000..d26aab9 --- /dev/null +++ b/.github/workflows/github_release.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set -o pipefail + +base_dir="$( cd "$(dirname "$0")/../.." >/dev/null 2>&1 ; pwd -P )" +readonly base_dir +readonly pom_file="$base_dir/pom.xml" + +# Read project version from pom file +project_version=$(grep "" "$pom_file" | sed --regexp-extended 's/\s*(.*)<\/version>\s*/\1/g' | head --lines=1) +readonly project_version +echo "Read project version '$project_version' from $pom_file" + +# Create GitHub release +readonly changes_file="$base_dir/doc/changes/changes_${project_version}.md" +notes=$(cat "$changes_file") +readonly notes + +readonly title="Release $project_version" +readonly tag="$project_version" +echo "Creating release:" +echo "Git tag : $tag" +echo "Title : $title" +echo "Changes file : $changes_file" + +release_url=$(gh release create --latest --title "$title" --notes "$notes" --target main "$tag") +readonly release_url +echo "Release URL: $release_url" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ca2aa24 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,63 @@ +name: Release + +on: + workflow_dispatch: + inputs: + skip-deploy-maven-central: + description: "Skip deployment to Maven Central" + required: true + type: boolean + default: false + +jobs: + release: + runs-on: ubuntu-latest + defaults: + run: + shell: "bash" + concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + permissions: + contents: write # Required for creating GitHub release + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Fail if not running on main branch + if: ${{ github.ref != 'refs/heads/main' }} + uses: actions/github-script@v7 + with: + script: | + core.setFailed('Not running on main branch, github.ref is ${{ github.ref }}. Please start this workflow only on main') + + - name: Set up Maven Central Repository + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: 11 + cache: "maven" + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE + + - name: Build + run: mvn --batch-mode -T 1C clean install + + - name: List secret GPG keys + run: gpg --list-secret-keys + + - name: Publish to Maven Central Repository + if: ${{ !inputs.skip-deploy-maven-central }} + run: mvn --batch-mode deploy -Possrh -DstagingDescription="Deployed via GitHub workflow release.yml" + env: + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} + + - name: Create GitHub Release + run: ./.github/workflows/github_release.sh + env: + GH_TOKEN: ${{ github.token }} diff --git a/.gitignore b/.gitignore index 5402bb0..f5b34d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.settings/org.eclipse.jdt.apt.core.prefs /.settings/org.eclipse.m2e.core.prefs +/.settings/org.eclipse.core.resources.prefs /target/ /bin/ /.project diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index f9fe345..0000000 --- a/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,4 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/main/java=UTF-8 -encoding//src/test/java=UTF-8 -encoding/=UTF-8 diff --git a/doc/changes/changelog.md b/doc/changes/changelog.md index e111020..0aa0bf1 100644 --- a/doc/changes/changelog.md +++ b/doc/changes/changelog.md @@ -1,4 +1,6 @@ # Changes +* [2.0.2](changes_2.0.2.md) +* [2.0.1](changes_2.0.1.md) * [2.0.0](changes_2.0.0.md) -* [1.0.0](changes_1.0.0.md) \ No newline at end of file +* [1.0.0](changes_1.0.0.md) diff --git a/doc/changes/changes_2.0.1.md b/doc/changes/changes_2.0.1.md new file mode 100644 index 0000000..65e869b --- /dev/null +++ b/doc/changes/changes_2.0.1.md @@ -0,0 +1,17 @@ +# hamcrest-multiline-text-matcher 2.0.1, released 2021-04-17 + +Codename: Update dependencies on top of 2.0.0 + +## Summary + +In version 2.0.1 we updated dependencies. + +## Changes + +* #6: Migrated deployment from JCentral to Maven Central +* #8: Updated dependencies + +## Bugfixes + +* #3: Fixed links in developer guide +* #7: Run Sonar only when token is available diff --git a/doc/changes/changes_2.0.2.md b/doc/changes/changes_2.0.2.md new file mode 100644 index 0000000..abe4c7d --- /dev/null +++ b/doc/changes/changes_2.0.2.md @@ -0,0 +1,11 @@ +# hamcrest-multiline-text-matcher 2.0.2, released 2024-09-02 + +Codename: Update dependencies on top of 2.0.1 + +## Summary + +In version 2.0.1 we updated dependencies and plugins and updated to Hamcrest 3.0. We also added tests using Java 17 and 21. + +## Changes + +* #9: Updated dependencies diff --git a/doc/developer_guide/developer_guide.md b/doc/developer_guide/developer_guide.md index f4e4fa0..0fa967d 100644 --- a/doc/developer_guide/developer_guide.md +++ b/doc/developer_guide/developer_guide.md @@ -25,41 +25,12 @@ mvn versions:display-dependency-updates mvn versions:display-plugin-updates ``` -## Publishing to Maven Central - -1. Add the following to your `~/.m2/settings.xml`: - - ```xml - - - - ossrh - your-jira-id - your-jira-pwd - - - - - ossrh - - true - - - gpg - the_pass_phrase - - - - - ``` - -1. Checkout the `main` branch. -1. Update version in `pom.xml`, commit and push. -1. Run command - - ```bash - mvn -DskipSigningArtifacts=false clean deploy - ``` +## Creating a Release on Maven Central and GitHub +1. Start the release workflow + * Run command `gh workflow run release.yml --repo itsallcode/hamcrest-mutliline-text-matcher --ref main` + * or go to [GitHub Actions](https://github.com/itsallcode/hamcrest-mutliline-text-matcher/actions/workflows/release.yml) and start the `release.yml` workflow on branch `main`. +2. Update title and description of the newly created [GitHub release](https://github.com/itsallcode/hamcrest-mutliline-text-matcher/releases). +3. After some time the release will be available at [Maven Central](https://repo1.maven.org/maven2/org/itsallcode/hamcrest-mutliline-text-matcher/). 1. Create a [release](https://github.com/itsallcode/hamcrest-mutliline-text-matcher/releases) of the `main` branch on GitHub. 1. After some time the release will be available at [Maven Central](https://repo1.maven.org/maven2/org/itsallcode/hamcrest-mutliline-text-matcher/). diff --git a/launch/MultilineTextMatcher - all tests coverage.launch b/launch/MultilineTextMatcher - all tests coverage.launch deleted file mode 100644 index 471b7a0..0000000 --- a/launch/MultilineTextMatcher - all tests coverage.launch +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/launch/MultilineTextMatcher - license update.launch b/launch/MultilineTextMatcher - license update.launch deleted file mode 100644 index 27b90a3..0000000 --- a/launch/MultilineTextMatcher - license update.launch +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index 4dedae0..a1c70aa 100644 --- a/pom.xml +++ b/pom.xml @@ -12,26 +12,49 @@ true https://sonarcloud.io itsallcode + ${git.commit.time} + ${reproducible.build.timestamp} - org.junit.jupiter - junit-jupiter - 5.10.1 - test + org.hamcrest + hamcrest + 3.0 - org.hamcrest - hamcrest-all - 1.3 + org.junit.jupiter + junit-jupiter-api + 5.11.0 + test + + io.github.git-commit-id + git-commit-id-maven-plugin + 9.0.1 + + + get-the-git-infos + + revision + + initialize + + + + true + false + + git.commit.time + + + org.apache.maven.plugins maven-toolchains-plugin - 3.1.0 + 3.2.0 @@ -50,10 +73,15 @@ org.apache.maven.plugins maven-compiler-plugin - 3.12.1 + 3.13.0 ${java.version} ${java.version} + true + + -Xlint:all + -Werror + @@ -94,17 +122,17 @@ org.apache.maven.plugins maven-jar-plugin - 3.3.0 + 3.4.2 org.apache.maven.plugins maven-surefire-plugin - 3.2.5 + 3.5.0 org.apache.maven.plugins maven-source-plugin - 3.3.0 + 3.3.1 attach-sources @@ -117,7 +145,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.6.3 + 3.10.0 attach-javadocs @@ -142,7 +170,7 @@ org.jacoco jacoco-maven-plugin - 0.8.11 + 0.8.12 @@ -161,7 +189,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.4.1 + 3.5.0 enforce-maven @@ -181,7 +209,7 @@ org.codehaus.mojo versions-maven-plugin - 2.16.2 + 2.17.1 package @@ -208,7 +236,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.1.0 + 3.2.5 sign-artifacts @@ -225,12 +253,12 @@ org.apache.maven.plugins maven-deploy-plugin - 3.1.1 + 3.1.3 org.sonatype.plugins nexus-staging-maven-plugin - 1.6.13 + 1.7.0 true ossrh @@ -238,6 +266,23 @@ true + + org.apache.maven.plugins + maven-artifact-plugin + 3.5.1 + + + verify-reproducible-build + verify + + check-buildplan + + + + + true + + https://github.com/itsallcode/hamcrest-mutliline-text-matcher @@ -280,4 +325,4 @@ https://oss.sonatype.org/service/local/staging/deploy/maven2/ - \ No newline at end of file + diff --git a/src/main/java/org/itsallcode/matcher/MultilineTextMatcher.java b/src/main/java/org/itsallcode/matcher/MultilineTextMatcher.java index f5e3f40..4bbb425 100644 --- a/src/main/java/org/itsallcode/matcher/MultilineTextMatcher.java +++ b/src/main/java/org/itsallcode/matcher/MultilineTextMatcher.java @@ -93,7 +93,7 @@ protected void describeMismatchSafely(final String text, final Description misma } } - private String describeLineCount(final int lineCount) + private static String describeLineCount(final int lineCount) { return "(" + lineCount + " lines)" + LINE_SEPARATOR; } @@ -119,12 +119,13 @@ public void describeTo(final Description description) * @param lines the expected lines * @return the matcher */ + @SuppressWarnings("java:S923") // Varargs are required here public static MultilineTextMatcher matchesAllLines(final String... lines) { return new MultilineTextMatcher(String.join(LINE_SEPARATOR, lines)); } - private List splitPreservingNewLines(final String text) + private static List splitPreservingNewLines(final String text) { final String lineSplittingRegEx = "(?<=" + LINE_ENDING + ")"; final List lines = new ArrayList<>(); @@ -135,4 +136,4 @@ private List splitPreservingNewLines(final String text) } return lines; } -} \ No newline at end of file +}