You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This GitHub Action is a composite action designed to standardize the build process for Java/Maven projects. It handles several key aspects of the build process:
Java environment setup
Maven configuration
Version management
Build process execution
Artifact handling and deployment
The action adapts its behavior based on the branch being built (master/main, hotfix, or development branches), applying different versioning strategies and build processes accordingly.
Inputs and Outputs
Key Inputs
Input Name
Description
Default Value
Required
java_version
The Java version to use
17
Optional
java_distribution
The Java distribution to use
zulu
Optional
maven_version
The Maven version to use
3.8.3
Optional
maven_flag
Maven command-line flags
-T 4C -B --no-transfer-progress
Optional
token
The GitHub token
N/A
Required
publish_artifacts
Whether to publish artifacts
false
Optional
ref
The ref to build
current GitHub ref
Optional
tag_name_prefix
Tag name prefix for checkout
empty string
Optional
aws_role_arn
The Amazon Resource Name (ARN) of the role to assume for S3 cache
empty string
Optional
Output
version: The version of the built artifact, accessible via${{ steps.set-version.outputs.version }}
Workflow Steps in Detail
1. Environment Setup
The action begins by setting up the Java environment using the officialactions/setup-java@v4 action to install the specified Java version and distribution.
2. Maven Configuration
The action configures Maven with caching to speed up builds. It supports two caching mechanisms:
Local Cache: Usesactions/cache@v4 to cache the Maven repository locally within GitHub Actions.
S3 Cache: Whenaws_role_arn is provided, usesruns-on/cache@v4 with AWS S3 for more persistent and shared caching across workflows.
The action also usesstCarolas/setup-maven@v5 to set up the specified Maven version.
3. Git Configuration
The action configures Git with a specific user identity ("clearci") to ensure consistent commit authoring and proper access to repositories.
4. Branch Detection
The action determines the type of branch being built:
A master/main branch
A hotfix branch
Any other branch (development)
The result is stored as outputs (hotfix andmaster) for use in subsequent steps.
5. Version Management
The action implements sophisticated version management based on the branch type:
Master/Main Branch: Increments the minor version and sets patch to 0 (e.g., 1.2.0 → 1.3.0)
Hotfix Branch:
Checks if the current version has a qualifier
If not, increments the patch version and adds a SNAPSHOT suffix
Commits this change to the repository
Uses the version without the SNAPSHOT suffix for the build
Other Branches: Uses a development version based on the first 8 characters of the commit SHA (e.g., dev-a1b2c3d4)
6. Build Process
The build process varies based on the branch type:
For Master/Hotfix Branches (Production Release):
This performs a full Maven release process with:
Skipping tests
Creating a Git tag with the format "v{version}"
Adding "[ci skip]" prefix to commit messages
Using the version determined in the previous step
For Other Branches (Development Build):
This performs a standard Maven package operation, skipping tests.
7. Artifact Deployment (Optional)
For production builds (master/hotfix), artifacts can optionally be deployed to a Maven repository whenpublish_artifacts is set to 'true'. This step:
Checks out the tag created during the release process
Deploys the artifacts using Maven's deploy goal with settings from.mvn/settings.xml
8. Artifact Upload
Finally, all builds upload artifacts to GitHub Actions, making the built JAR files available for download from the GitHub Actions interface, with a retention period of 1 day.
Branch-Based Strategy Summary
The action implements a sophisticated branch-based strategy:
Master/Main Branch:
Treated as production releases
Increments minor version (1.2.0 → 1.3.0)
Performs full Maven release with tagging
Optionally deploys artifacts
Hotfix Branch:
Special handling for urgent fixes
Increments patch version if needed (1.2.0 → 1.2.1)
Performs full Maven release with tagging
Optionally deploys artifacts
Other Branches:
Treated as development builds
Uses commit-based versioning (dev-a1b2c3d4)
Performs standard Maven package operation
Does not deploy artifacts (but still uploads them to GitHub Actions)
Key Technical Features
Automated Version Management: Automatically determines appropriate version numbers based on branch type and existing version.
Conditional Build Processes: Adapts the build process based on the branch type.
Artifact Management: Uploads artifacts for all builds and optionally deploys them for production builds.
Caching: Implements Maven repository caching to improve build performance, with support for both local GitHub Actions cache and S3-based caching.
Configurable Environment: Allows customization of Java version, distribution, Maven version, and other parameters.
This composite action provides a standardized, reliable, and maintainable build process for Java/Maven projects, with sophisticated version management and branch-based strategies.
S3 Cache Configuration
The action supports using Amazon S3 for caching Maven dependencies, which provides several advantages over the standard GitHub Actions cache:
Persistent Storage: Cache persists beyond the 7-day limit of GitHub Actions cache
Cross-Workflow Sharing: Cache can be shared across different workflows and repositories
Improved Performance: Potentially faster cache operations, especially for large dependency sets
Requirements for S3 Cache
To use the S3 cache functionality:
AWS Role ARN: Provide an AWS Role ARN via theaws_role_arn input parameter
Permissions: The GitHub workflow must havepermissions: write-all set to allow the action to configure AWS credentials
S3 Bucket: The action uses a predefined S3 bucket (ct-github-action-cache) in theap-south-1 region
Example Workflow with S3 Cache
name:Build with S3 Cacheon:push:branches:[ main ]jobs:build:runs-on:ubuntu-latestpermissions:write-allsteps: -uses:actions/checkout@v4 -name:Build with Javauses:cleartax/build-java@mainwith:token:${{ secrets.GITHUB_TOKEN }}aws_role_arn:${{ secrets.AWS_ASSUME_ROLE_ARN }}
Whenaws_role_arn is not provided, the action automatically falls back to using the standard GitHub Actions cache.