Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sormuras/hello-world-java-action
A template to demonstrate how to build a Java action.
https://github.com/sormuras/hello-world-java-action
actions github github-actions java
Last synced: about 1 month ago
JSON representation
A template to demonstrate how to build a Java action.
- Host: GitHub
- URL: https://github.com/sormuras/hello-world-java-action
- Owner: sormuras
- License: mit
- Created: 2020-10-08T10:10:30.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-29T09:41:31.000Z (3 months ago)
- Last Synced: 2024-09-29T23:21:04.345Z (about 2 months ago)
- Topics: actions, github, github-actions, java
- Language: Java
- Homepage: https://openjdk.java.net/jeps/330
- Size: 39.1 KB
- Stars: 12
- Watchers: 2
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hello World Java Action
A template to demonstrate how to build a Java action via [JEP 330: Launch Single-File Source-Code Programs](https://openjdk.java.net/jeps/330).This action prints "Hello World" to the log or "Hello" + the name of a person to greet.
To learn how this action was built, see "[Creating a composite run steps action](https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/creating-a-composite-run-steps-action)" in the GitHub Help documentation.
## Inputs
### `who-to-greet`
**Required** The name of the person to greet. Default `"World"`.
## Outputs
### `random-number`
> Returns the next pseudorandom, Gaussian ("normally") distributed
> `double` value with mean `0.0` and standard deviation `1.0` from
> this random number generator's sequence.See [java.util.Random#nextGaussian()](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Random.html#nextGaussian()) for details.
## Example usage
```yaml
jobs:
build:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- id: hello
uses: sormuras/hello-world-java-action@v1
with:
who-to-greet: 'Mona the Octocat'
- run: echo random-number ${{ steps.hello.outputs.random-number }}
shell: bash
```## `Action.java`
```java
import java.util.Random;class Action {
public static void main(String... args) {
System.out.printf("Hello %s.%n", args.length == 0 ? "Java" : args[0]);
var gaussian = new Random().nextGaussian();
GitHub.setOutput("random-number", gaussian);
System.out.println("Goodbye and have fun with: " + gaussian);
}/** GitHub Actions helper. */
static class GitHub {
/** Sets an action's output parameter. */
static void setOutput(String name, Object value) {
//...
}
}
}
```## Feedback and Discussion
- [Synchronize default Java version on latest runners](https://github.com/actions/runner-images/discussions/10509)