-
-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (114 loc) · 4.81 KB
/
publish.yml
File metadata and controls
133 lines (114 loc) · 4.81 KB
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
125
126
127
128
129
130
131
132
133
name: Package & Release Plugin
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
release:
types: [ created ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '8'
- name: Build with Maven
run: mvn clean package
- name: Upload plugin artifact
uses: actions/upload-artifact@v4
with:
name: Plugin
path: target/${{ github.event.repository.name }}-*.jar
- name: Get Plugin Version
id: version
run: echo "VERSION=$(basename $(ls target/${{ github.event.repository.name }}-*.jar | grep -vE '(-sources|-javadoc).jar') .jar | sed 's/${{ github.event.repository.name }}-//')" >> $GITHUB_ENV
- name: Delete existing GitHub release (if exists)
run: |
RELEASE_ID=$(gh release view ${{ env.VERSION }} --json id -q '.id' || echo "")
if [ -n "$RELEASE_ID" ]; then
echo "Deleting existing release..."
gh release delete ${{ env.VERSION }} --yes
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete existing tag (if exists)
run: |
if git rev-parse "${{ env.VERSION }}" >/dev/null 2>&1; then
echo "Deleting existing tag..."
git tag -d ${{ env.VERSION }}
git push origin :refs/tags/${{ env.VERSION }}
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Rename & Upload Latest Release
run: |
JAR_FILE=$(ls target/${{ github.event.repository.name }}-*.jar | grep -vE '(-sources|-javadoc).jar' | head -n 1)
cp "$JAR_FILE" target/${{ github.event.repository.name }}-latest.jar
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.VERSION }}
name: Release ${{ env.VERSION }}
draft: false
prerelease: false
files: |
target/${{ github.event.repository.name }}-latest.jar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Maven repository
uses: actions/checkout@v4
with:
repository: CroaBeast/repo
path: maven-repo
token: ${{ secrets.MAVEN_DEPLOY_TOKEN }}
- name: Configure Git
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Deploy to Maven repository
run: |
# Create directory structure
mkdir -p maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}
# Copy JAR files
cp target/${{ github.event.repository.name }}-${{ env.VERSION }}.jar maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/
cp target/${{ github.event.repository.name }}-${{ env.VERSION }}-javadoc.jar maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/
cp target/${{ github.event.repository.name }}-${{ env.VERSION }}-sources.jar maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/
# Create POM file
cat > maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/${{ github.event.repository.name }}-${{ env.VERSION }}.pom << EOF
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>me.croabeast</groupId>
<artifactId>${{ github.event.repository.name }}</artifactId>
<version>${{ env.VERSION }}</version>
<packaging>jar</packaging>
</project>
EOF
# Update or create maven-metadata.xml
cat > maven-repo/me/croabeast/${{ github.event.repository.name }}/maven-metadata.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>me.croabeast</groupId>
<artifactId>${{ github.event.repository.name }}</artifactId>
<versioning>
<latest>${{ env.VERSION }}</latest>
<release>${{ env.VERSION }}</release>
<versions>
<version>${{ env.VERSION }}</version>
</versions>
<lastUpdated>$(date +%Y%m%d%H%M%S)</lastUpdated>
</versioning>
</metadata>
EOF
# Commit and push changes
cd maven-repo
git add .
git commit -m "Deploy ${{ github.event.repository.name }} ${{ env.VERSION }}"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}