Skip to content

Commit

Permalink
Add actions for maven builds (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp94831 authored Sep 20, 2023
1 parent b5bc543 commit f6654cb
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 2 deletions.
2 changes: 2 additions & 0 deletions actions/java-gradle-release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This action releases Java Gradle artifacts by createing a tag on GitHub.

| Name | Required | Default Value | Type | Description |
| ----------------- | :------: | :-----------: | :-----: | ------------------------------------------------------------------------------------------------------------- |
| release-type || - | string | Scope of the release |
| 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 |
Expand All @@ -22,6 +23,7 @@ steps:
- name: Release on Github
uses: bakdata/ci-templates/actions/java-gradle-release@main
with:
release-type: "patch"
github-email: ${{ secrets.github-email }}
github-username: ${{ secrets.github-username }}
github-token: ${{ secrets.github-token }}
Expand Down
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 |
| ----------------- | :------: | :-----------: | :----: | -------------------------------------------------------------------------------------------------- |
| maven-version || - | string | Maven version to be installed |
| 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 |
| 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:
maven-version: "3.8.2"
java-distribution: "microsoft" # (Optional)
java-version: "11" # (Optional)
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"
description: "Build Java artifacts using Maven"

inputs:
maven-version:
description: "Maven version to be installed."
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: "."
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-setup1.33.0
with:
java-distribution: ${{ inputs.java-distribution }}
java-version: ${{ inputs.java-version }}
maven-version: ${{ inputs.maven-version }}

- name: Compile
run: mvn clean ${{ inputs.command }}
shell: bash
working-directory: ${{ inputs.working-directory }}
33 changes: 33 additions & 0 deletions actions/java-maven-release/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# java-maven-release

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

## Input Parameters

| Name | Required | Default Value | Type | Description |
| ----------------- | :------: | :-----------: | :----: | -------------------------------------------------------------------------------------------------- |
| release-type || - | string | Scope of the release |
| 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 |
| maven-version || - | string | Maven version to be installed |
| 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 |
| 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:
release-type: "patch"
github-email: ${{ secrets.github-email }}
github-username: ${{ secrets.github-username }}
github-token: ${{ secrets.github-token }}
maven-version: "3.8.2"
java-distribution: "microsoft" # (Optional)
java-version: "11" # (Optional)
working-directory: "." # (Optional)
```
81 changes: 81 additions & 0 deletions actions/java-maven-release/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: "Release Java artifacts"
description: "Release Java Maven artifacts on Github"

inputs:
maven-version:
description: "Maven version to be installed."
required: true
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-setup1.33.0
with:
java-distribution: ${{ inputs.java-distribution }}
java-version: ${{ inputs.java-version }}
maven-version: ${{ inputs.maven-version }}

- 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 |
| ----------------- | :------: | :-----------: | :----: | -------------------------------------------------------------------------------------------------- |
| maven-version || - | string | Maven version to be installed |
| 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 |

## Usage

```yaml
steps:
- name: Set up Maven
uses: bakdata/ci-templates/actions/java-maven-setup@main
with:
maven-version: "3.8.2"
java-distribution: "microsoft" # (Optional)
java-version: "11" # (Optional)
```
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:
maven-version:
description: "Maven version to be installed."
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"
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]
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 |
| ------------------ | :------: | :-----------: | :-----: | -------------------------------------------------------------------------------------------------- |
| maven-version || - | string | Maven version to be installed |
| 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 |
| 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:
maven-version: "3.8.2"
java-distribution: "microsoft" # (Optional)
java-version: "11" # (Optional)
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"
description: "Run Junit test and publish test results"

inputs:
maven-version:
description: "Maven version to be installed."
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: "."
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-setup1.33.0
with:
java-distribution: ${{ inputs.java-distribution }}
java-version: ${{ inputs.java-version }}
maven-version: ${{ inputs.maven-version }}

- name: Run tests
run: mvn ${{ inputs.command }}
shell: bash
working-directory: ${{ inputs.working-directory }}

0 comments on commit f6654cb

Please sign in to comment.