-
Notifications
You must be signed in to change notification settings - Fork 8
82 lines (70 loc) · 2.67 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Build, Test, and Deploy
on:
push:
branches:
- master
jobs:
build-test-deploy:
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"
distribution: "temurin"
- 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: |
START_VERSION="2.0.1903"
CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
if [[ "$CURRENT_VERSION" == "0.0.1-SNAPSHOT" ]]; then
NEW_VERSION=$START_VERSION
else
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F '.' '{print $1"."$2"."$3+1}')
fi
echo "New version: $NEW_VERSION"
echo "artifact-version=$NEW_VERSION" >> $GITHUB_ENV
- name: Build and test with Maven
run: mvn clean install assembly:single --batch-mode -Dartifact.version=${{ env.artifact-version }}
- name: Print contents of target directory
run: |
if [ ! -d "target" ]; then
echo "Target directory not found!" && exit 1
fi
echo "Contents of target directory:"
ls -l target
- name: Rename artifact to include version
run: |
ZIP_FILE=$(find target -name "*.zip" | head -n 1)
if [ -z "$ZIP_FILE" ]; then
echo "Artifact not found!" && exit 1
fi
NEW_ZIP_NAME="target/inmoov2-${{ env.artifact-version }}.zip"
mv "$ZIP_FILE" "$NEW_ZIP_NAME"
- 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: |
S3_URI="s3://your-bucket-name/maven-repo/path/to/artifact/"
aws s3 cp "target/inmoov2-${{ env.artifact-version }}.zip" "$S3_URI"
- name: Verify artifact upload
run: |
aws s3 ls s3://your-bucket-name/maven-repo/path/to/artifact/
- name: Create Git tag for version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git tag -a "v${{ env.artifact-version }}" -m "Release version ${{ env.artifact-version }}"
git push origin "v${{ env.artifact-version }}"