-
Notifications
You must be signed in to change notification settings - Fork 8
124 lines (107 loc) · 4.68 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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: |
BASE_VERSION="2.0"
BUILD_INCREMENT=1900
BUILD_NUMBER=${{ github.run_number }}
NEW_VERSION="${BASE_VERSION}.$((BUILD_INCREMENT + BUILD_NUMBER))"
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: Generate and upload POM file
run: |
cat > target/pom-${{ env.artifact-version }}.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.inmoov</groupId>
<artifactId>inmoov2</artifactId>
<version>${{ env.artifact-version }}</version>
<packaging>zip</packaging>
<description>POM was created from install:install-file</description>
</project>
EOF
- name: Generate and upload maven-metadata.xml file
run: |
TIMESTAMP=$(date +"%Y%m%d%H%M%S")
cat > target/maven-metadata.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>fr.inmoov</groupId>
<artifactId>inmoov2</artifactId>
<versioning>
<release>${{ env.artifact-version }}</release>
<versions>
<version>${{ env.artifact-version }}</version>
</versions>
<lastUpdated>$TIMESTAMP</lastUpdated>
</versioning>
</metadata>
EOF
- 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"
# s3://myrobotlab-repo/artifactory/myrobotlab/fr/inmoov/inmoov2/2.0.1897/inmoov2-2.0.1897.zip
run: |
S3_METADATA_URI="s3://myrobotlab-repo/artifactory/myrobotlab/fr/inmoov/inmoov2/maven-metadata.xml"
aws s3 cp "target/maven-metadata.xml" "$S3_METADATA_URI"
S3_POM_URI="s3://myrobotlab-repo/artifactory/myrobotlab/fr/inmoov/inmoov2/${{ env.artifact-version }}/inmoov2-${{ env.artifact-version }}.pom"
aws s3 cp "target/pom-${{ env.artifact-version }}.xml" "$S3_POM_URI"
S3_URI="s3://myrobotlab-repo/artifactory/myrobotlab/fr/inmoov/inmoov2/${{ env.artifact-version }}/inmoov2-${{ env.artifact-version }}.zip"
aws s3 cp "target/inmoov2-${{ env.artifact-version }}.zip" "$S3_URI"
# - name: Verify artifact upload
# run: |
# aws s3 ls "s3://myrobotlab-repo/artifactory/myrobotlab/fr/inmoov/inmoov2/${{ env.artifact-version }}"
- name: Create Git tag for version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if git tag -l | grep -q "v${{ env.artifact-version }}"; then
echo "Tag v${{ env.artifact-version }} already exists. Skipping tag creation."
else
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 }}"
fi