Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
108 changes: 2 additions & 106 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,106 +1,2 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt


# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
.idea
.DS_Store
*.iml
.idea
97 changes: 36 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,62 @@
# A Github Action to Export Your Maven Project's Version for Use in Subsequent Steps
# A GitHub Action to Export Your Maven Project's Version for Use in Subsequent Steps

I saw a great tweet from [Bruno Borges](https://twitter.com/brunoborges) about using Github Actions to derive the version of Java to be installed by analyzing the `pom.xml` of the build itself. It seems like a good enough idea,
so I [put it into practive here](https://github.com/joshlong/java-version-export-github-action). Most of the magic lives [in a very tiny JavaScript file, `index.js`](https://raw.githubusercontent.com/joshlong/java-version-export-github-action/main/index.js):
This is a fork from [joshlong/java-version-export-github-action](https://github.com/joshlong/java-version-export-github-action)
that adds some new features to the base idea of the upstream:

Usage:
> I saw a great tweet from [Bruno Borges](https://twitter.com/brunoborges) about using GitHub Actions to derive
> the version of Java to be installed by analyzing the `pom.xml` of the build itself.
> It seems like a good enough idea, so I [put it into practice here](https://github.com/joshlong/java-version-export-github-action).
> Most of the magic lives [in a very tiny JavaScript file, `index.js`](https://raw.githubusercontent.com/joshlong/java-version-export-github-action/main/index.js):
> It'll analyze your Maven `pom.xml` to determine which version of Java you've configured by having Maven tell it
> the value of `maven.compiler.version`.
> The program then exports the version and the major version of Java as a step output _and_ an environment variable
> that you could use in later steps.
>
> I really should make this work for Gradle... (Pull requests welcome!)

```yaml

const core = require("@actions/core");
const github = require("@actions/github");
const exec = require("@actions/exec");
# Usage

function cmd(cmd, args, stdoutListener) {
exec
.exec(cmd, args, {
listeners: {
stdout: stdoutListener,
},
})
.then((ec) => {
console.debug("the exit code is " + ec);
});
}
This is a basic example of how to use this action in your workflow:

try {
cmd(
"mvn",
[
"help:evaluate",
"-q",
"-DforceStdout",
"-Dexpression=maven.compiler.target",
],
// ["help:evaluate", "-q", "-DforceStdout", "-Dexpression=java.version"],
(outputBuffer) => {
const output = outputBuffer.toString();
console.log(output);
const varsMap = new Map();
varsMap.set("java_version", output + "");
varsMap.set("java_major_version", parseInt("" + output) + "");
varsMap.forEach(function (value, key) {
console.log(key + "=" + value);
core.setOutput(key, value);
core.exportVariable(key.toUpperCase(), value);
});
}
);
} catch (error) {
core.setFailed(error.message);
}
```yaml
- uses: BetonQuest/java-version-export-github-action@main
id: jve
```

Basically, you put this at the very beginning of your Github Actions flow, right after the checkout, and it'll
analyse your Maven `pom.xml` to determine which version of Java you've configured by having Maven tell it the value of `maven.compiler.version`. The
program then exports the version and the major version of Java as a step output _and_ an environment variable that you could use in subsequent steps.
or if you have the java version in another property like the release property:

```yaml
- uses: BetonQuest/java-version-export-github-action@main
id: jve
with:
maven-expression: 'maven.compiler.release'
```

So, assuming the following usage:
or if you want to use a different Maven command, like `./mvnw`, or `mvnd` or the daemon in the wrapper:

```yaml
- uses: joshlong/java-version-export-github-action@v17
- uses: BetonQuest/java-version-export-github-action@main
id: jve
with:
maven-command: './mvnw'
# Or for maven daemon with the --raw-streams option to work properly:
# maven-command: './mvnw --raw-streams'
```

You can use the exported environment variable:
Then you can use the exported environment variable:

```
- uses: actions/setup-java@v3
```yaml
- uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_MAJOR_VERSION }}
```

or reference the step's output values, like this:

```yaml

- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
java-version: ${{ steps.jve.outputs.java_major_version }}
```


Now Github Actions will download whatever version of Java you've specified in your Maven `pom.xml`.

I really should make this work for Gradle... (Pull requests welcome!)

Now GitHub Actions will download whatever version of Java you've specified in your Maven `pom.xml`.
14 changes: 12 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
name: "java-version-export-github-action"
description: "Exports the version of Java specified in pom.xml for use in configuring the version of Java to be used in the github action job"

inputs:
maven-expression:
description: "The Maven expression to evaluate for the java version"
required: false
default: "maven.compiler.target"
maven-command:
description: "The Maven command to use for example maven-wrapper"
required: false
default: "mvn"

runs:
using: "node16"
main: "dist/index.js"
using: "node24"
main: "index.js"
17 changes: 0 additions & 17 deletions build.sh

This file was deleted.

Loading