Skip to content

main to master

main to master #1

Workflow file for this run

name: Build, Test, and Deploy
on:
push:
branches:
- master
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: "11"
- name: Cache Maven dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven
- name: Increment version and build with Maven
id: increment-version
run: |
CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "Current version: $CURRENT_VERSION"
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F '.' '{print $1"."$2"."$3+1}')
echo "New version: $NEW_VERSION"
echo "artifact-version=$NEW_VERSION" >> $GITHUB_ENV
- name: Build and test with Maven
run: mvn clean install --batch-mode -Dartifact.version=${{ env.artifact-version }}
deploy:
runs-on: ubuntu-latest
needs: build-and-test
if: success()
steps:
- name: Checkout code.
uses: actions/checkout@v3
- name: Upload to S3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "us-east-1"
run: |
FILE_PATH=$(find target -name "*.jar" | head -n 1)
if [ -z "$FILE_PATH" ]; then
echo "Artifact not found!" && exit 1
fi
S3_URI="s3://your-bucket-name/maven-repo/path/to/artifact/"
aws s3 cp "$FILE_PATH" "$S3_URI"
- name: Verify artifact upload
run: |
aws s3 ls s3://your-bucket-name/maven-repo/path/to/artifact/