Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add actions for maven builds #143

Merged
merged 18 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 1 addition & 1 deletion actions/java-gradle-setup/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# java-gradle-test
# java-gradle-setup

This action sets up Java and Gradle.

Expand Down
2 changes: 1 addition & 1 deletion actions/java-gradle-test/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# java-gradle-setup
# java-gradle-test

This action runs Junit tests, publishes the test results and tests signing for Sonatype.

Expand Down
27 changes: 27 additions & 0 deletions actions/java-maven-build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# java-maven-build

This action builds Java artifacts using Maven.

## Input Parameters

| Name | Required | Default Value | Type | Description |
| ----------------- | :------: | :-----------: | :----: | -------------------------------------------------------------------------------------------------- |
| java-distribution | ❌ | microsoft | string | [Java distribution](https://github.com/actions/setup-java#supported-distributions) to be installed |
| java-version | ❌ | 11 | string | Java version to be installed |
| maven-version | ❌ | wrapper | string | Maven version to be installed |
| working-directory | ❌ | "." | string | Working directory of your Maven artifacts |
| command | ❌ | compile | string | Command to run build with |

## Usage

```yaml
steps:
- name: Build
uses: bakdata/ci-templates/actions/java-maven-build@main
with:
java-distribution: "microsoft" # (Optional)
java-version: "11" # (Optional)
maven-version: "3.8.2"
working-directory: "." # (Optional)
command: "compile" # (Optional)
```
40 changes: 40 additions & 0 deletions actions/java-maven-build/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "Build Java artifacts"
philipp94831 marked this conversation as resolved.
Show resolved Hide resolved
description: "Build Java artifacts using Maven"

inputs:
java-distribution:
description: "Java distribution to be installed. (Default is microsoft)"
required: false
default: "microsoft"
java-version:
description: "Java version to be installed. (Default is 11)"
required: false
default: "11"
maven-version:
description: "Maven version to be installed."
required: true
yannick-roeder marked this conversation as resolved.
Show resolved Hide resolved
working-directory:
description: "Working directory of your Maven artifacts. (Default is .)"
required: false
default: "."
command:
description: "Command to run build with. (Default is compile)"
required: false
default: "compile"
runs:
using: "composite"
steps:
- name: Check out repository
uses: bakdata/ci-templates/actions/[email protected]

- name: Set up Maven with version ${{ inputs.maven-version }}
uses: bakdata/ci-templates/actions/java-maven-setup@feature/maven
philipp94831 marked this conversation as resolved.
Show resolved Hide resolved
with:
java-distribution: ${{ inputs.java-distribution }}
java-version: ${{ inputs.java-version }}
maven-version: ${{ inputs.maven-version }}

- name: Compile
run: mvn clean ${{ inputs.command }}
yannick-roeder marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
working-directory: ${{ inputs.working-directory }}
31 changes: 31 additions & 0 deletions actions/java-maven-release/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# java-maven-release

This action releases Java Maven artifacts by createing a tag on GitHub.

## Input Parameters

| Name | Required | Default Value | Type | Description |
| ----------------- | :------: | :-----------: | :----: | -------------------------------------------------------------------------------------------------- |
yannick-roeder marked this conversation as resolved.
Show resolved Hide resolved
| github-email | ✅ | - | string | GitHub email for requesting changes from API |
| github-username | ✅ | - | string | GitHub username for requesting changes from API |
| github-token | ✅ | - | string | GitHub token for requesting changes from API |
| java-distribution | ❌ | microsoft | string | [Java distribution](https://github.com/actions/setup-java#supported-distributions) to be installed |
| java-version | ❌ | 11 | string | Java version to be installed |
| maven-version | ❌ | wrapper | string | Maven version to be installed |
| working-directory | ❌ | "." | string | Working directory of your Maven artifacts |

## Usage

```yaml
steps:
- name: Release on Github
uses: bakdata/ci-templates/actions/java-maven-release@main
with:
github-email: ${{ secrets.github-email }}
github-username: ${{ secrets.github-username }}
github-token: ${{ secrets.github-token }}
java-distribution: "microsoft" # (Optional)
java-version: "11" # (Optional)
maven-version: "3.8.2"
working-directory: "." # (Optional)
```
78 changes: 78 additions & 0 deletions actions/java-maven-release/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: "Release Java artifacts"
description: "Release Java Maven artifacts on Github"

inputs:
release-type:
description: "Scope of the release"
required: true
github-email:
description: "GitHub email for requesting changes from API."
required: true
github-username:
description: "GitHub username for requesting changes from API."
required: true
github-token:
description: "GitHub token for requesting changes from API."
required: true
java-distribution:
description: "Java distribution to be installed. (Default is microsoft)"
required: false
default: "microsoft"
java-version:
description: "Java version to be installed. (Default is 11)"
required: false
default: "11"
working-directory:
description: "Working directory of your Maven artifacts. (Default is .)"
required: false
default: "."

outputs:
release-version:
description: "The bumped version of your release."
value: ${{ steps.evaluate-version.outputs.release-version }}

runs:
using: "composite"
steps:
- name: Check out repository
uses: bakdata/ci-templates/actions/[email protected]
with:
fetch-depth: 0
token: ${{ inputs.github-token }}

- name: Setup git
run: |
git config user.email ${{ inputs.github-email }}
git config user.name ${{ inputs.github-username }}
shell: bash

- name: Setup semver
run: |
wget -O /usr/local/bin/semver https://raw.githubusercontent.com/fsaintjacques/semver-tool/3.3.0/src/semver
chmod +x /usr/local/bin/semver
shell: bash

- name: Set up Maven with version ${{ inputs.maven-version }}
uses: bakdata/ci-templates/actions/java-maven-setup@feature/maven
philipp94831 marked this conversation as resolved.
Show resolved Hide resolved
with:
java-distribution: ${{ inputs.java-distribution }}
java-version: ${{ inputs.java-version }}
maven-version: ${{ inputs.maven-version }}
yannick-roeder marked this conversation as resolved.
Show resolved Hide resolved

- name: Bump version
id: evaluate-version
run: |
old_version=$(mvn -Dexec.executable='echo' -Dexec.args='${project.version}' --non-recursive exec:exec -q)
if [[ "${{ inputs.release-type }}" == "patch" ]]; then
release_version="${old_version%-*}"
else
release_version=$(semver bump "${{ inputs.release-type }}" "${old_version}")
fi
echo "release-version=$release_version" >> "$GITHUB_OUTPUT"
shell: bash

- name: Create release
run: mvn release:prepare -B -DreleaseVersion=${{ steps.evaluate-version.outputs.release-version }} -Darguments=-DskipTests -Dscm.developer.connection="scm:git:${{ github.server_url }}/${{ github.repository }}.git"
shell: bash
working-directory: ${{ inputs.working-directory }}
23 changes: 23 additions & 0 deletions actions/java-maven-setup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# java-maven-setup

This action sets up Java and Maven.

## Input Parameters

| Name | Required | Default Value | Type | Description |
| ----------------- | :------: | :-----------: | :----: | -------------------------------------------------------------------------------------------------- |
| java-distribution | ❌ | microsoft | string | [Java distribution](https://github.com/actions/setup-java#supported-distributions) to be installed |
| java-version | ❌ | 11 | string | Java version to be installed |
| maven-version | ❌ | wrapper | string | Maven version to be installed |
yannick-roeder marked this conversation as resolved.
Show resolved Hide resolved

## Usage

```yaml
steps:
- name: Set up Maven
uses: bakdata/ci-templates/actions/java-maven-setup@main
with:
java-distribution: "microsoft" # (Optional)
java-version: "11" # (Optional)
maven-version: "3.8.2"
```
27 changes: 27 additions & 0 deletions actions/java-maven-setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Setup Maven"
description: "Setup Java and Maven"

inputs:
java-distribution:
description: "Java distribution to be installed. (Default is microsoft)"
required: false
default: "microsoft"
java-version:
description: "Java version to be installed. (Default is 11)"
required: false
default: "11"
maven-version:
description: "Maven version to be installed."
required: true
runs:
using: "composite"
steps:
- uses: actions/setup-java@v3
with:
distribution: ${{ inputs.java-distribution }}
java-version: ${{ inputs.java-version }}

- name: Set up Maven
uses: yuzhiyongcn/[email protected]
yannick-roeder marked this conversation as resolved.
Show resolved Hide resolved
with:
maven-version: ${{ inputs.maven-version }}
28 changes: 28 additions & 0 deletions actions/java-maven-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# java-maven-test

This action runs Junit tests and publishes the test results.

## Input Parameters

| Name | Required | Default Value | Type | Description |
| ------------------ | :------: | :-----------: | :-----: | -------------------------------------------------------------------------------------------------- |
| java-distribution | ❌ | microsoft | string | [Java distribution](https://github.com/actions/setup-java#supported-distributions) to be installed |
| java-version | ❌ | 11 | string | Java version to be installed |
| maven-version | ❌ | wrapper | string | Maven version to be installed |
| working-directory | ❌ | "." | string | Working directory of your Maven artifacts |
| download-lfs-files | ❌ | false | boolean | Whether the Git checkout action should resolve LFS files or not |
| command | ❌ | test | string | Command to run tests with |

## Usage

```yaml
steps:
- name: Test
uses: bakdata/ci-templates/actions/java-maven-test@main
with:
java-distribution: "microsoft" # (Optional)
java-version: "11" # (Optional)
maven-version: "3.8.2"
working-directory: "." # (Optional)
command: "test" # (Optional)
```
48 changes: 48 additions & 0 deletions actions/java-maven-test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: "Test Java artifacts"
philipp94831 marked this conversation as resolved.
Show resolved Hide resolved
description: "Run Junit test and publish test results"

inputs:
java-distribution:
description: "Java distribution to be installed. (Default is microsoft)"
required: false
default: "microsoft"
java-version:
description: "Java version to be installed. (Default is 11)"
required: false
default: "11"
maven-version:
description: "Maven version to be installed."
required: true
working-directory:
description: "Working directory of your Maven artifacts. (Default is .)"
required: false
default: "."
download-lfs-files:
description: "Whether the Git checkout action should resolve LFS files or not. (Default is false)"
required: false
default: false
command:
description: "Command to run tests with. (Default is test)"
required: false
default: "test"

runs:
using: "composite"
steps:
- name: Check out repository
uses: bakdata/ci-templates/actions/[email protected]
with:
fetch-depth: 0
lfs: ${{ inputs.download-lfs-files }}

- name: Set up Maven with version ${{ inputs.maven-version }}
uses: bakdata/ci-templates/actions/java-maven-setup@feature/maven
philipp94831 marked this conversation as resolved.
Show resolved Hide resolved
with:
java-distribution: ${{ inputs.java-distribution }}
java-version: ${{ inputs.java-version }}
maven-version: ${{ inputs.maven-version }}

- name: Run tests
run: mvn ${{ inputs.command }}
yannick-roeder marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
working-directory: ${{ inputs.working-directory }}