-
Notifications
You must be signed in to change notification settings - Fork 8
64 lines (53 loc) · 1.84 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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/