Skip to content

Commit bcebfc7

Browse files
authored
Update and rename maven-publish.yml to publish.yml
1 parent 8625f7f commit bcebfc7

File tree

2 files changed

+131
-71
lines changed

2 files changed

+131
-71
lines changed

.github/workflows/maven-publish.yml

Lines changed: 0 additions & 71 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Package & Release Plugin
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
release:
9+
types: [created]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Set up JDK 8
20+
uses: actions/setup-java@v3
21+
with:
22+
distribution: 'temurin'
23+
java-version: '8'
24+
25+
- name: Build with Maven
26+
run: mvn clean package
27+
28+
- name: Upload plugin artifact
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: Plugin
32+
path: target/${{ github.event.repository.name }}-*.jar
33+
34+
- name: Get Plugin Version
35+
id: version
36+
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
37+
38+
- name: Delete existing GitHub release (if exists)
39+
run: |
40+
RELEASE_ID=$(gh release view ${{ env.VERSION }} --json id -q '.id' || echo "")
41+
if [ -n "$RELEASE_ID" ]; then
42+
echo "Deleting existing release..."
43+
gh release delete ${{ env.VERSION }} --yes
44+
fi
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Delete existing tag (if exists)
49+
run: |
50+
if git rev-parse "${{ env.VERSION }}" >/dev/null 2>&1; then
51+
echo "Deleting existing tag..."
52+
git tag -d ${{ env.VERSION }}
53+
git push origin :refs/tags/${{ env.VERSION }}
54+
fi
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
58+
- name: Rename & Upload Latest Release
59+
run: |
60+
JAR_FILE=$(ls target/${{ github.event.repository.name }}-*.jar | grep -vE '(-sources|-javadoc).jar' | head -n 1)
61+
cp "$JAR_FILE" target/${{ github.event.repository.name }}-latest.jar
62+
63+
- name: Create GitHub Release
64+
uses: softprops/action-gh-release@v1
65+
with:
66+
tag_name: ${{ env.VERSION }}
67+
name: Release ${{ env.VERSION }}
68+
draft: false
69+
prerelease: false
70+
files: |
71+
target/${{ github.event.repository.name }}-latest.jar
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
75+
- name: Checkout Maven repository
76+
uses: actions/checkout@v4
77+
with:
78+
repository: CroaBeast/repo
79+
path: maven-repo
80+
token: ${{ secrets.MAVEN_DEPLOY_TOKEN }}
81+
82+
- name: Configure Git
83+
run: |
84+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
85+
git config --global user.name "github-actions[bot]"
86+
87+
- name: Deploy to Maven repository
88+
run: |
89+
# Create directory structure
90+
mkdir -p maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}
91+
92+
# Copy JAR file
93+
cp target/${{ github.event.repository.name }}-${{ env.VERSION }}.jar maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/
94+
95+
# Create POM file
96+
cat > maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/${{ github.event.repository.name }}-${{ env.VERSION }}.pom << EOF
97+
<?xml version="1.0" encoding="UTF-8"?>
98+
<project>
99+
<modelVersion>4.0.0</modelVersion>
100+
<groupId>me.croabeast</groupId>
101+
<artifactId>${{ github.event.repository.name }}</artifactId>
102+
<version>${{ env.VERSION }}</version>
103+
<packaging>jar</packaging>
104+
</project>
105+
EOF
106+
107+
# Update or create maven-metadata.xml
108+
cat > maven-repo/me/croabeast/${{ github.event.repository.name }}/maven-metadata.xml << EOF
109+
<?xml version="1.0" encoding="UTF-8"?>
110+
<metadata>
111+
<groupId>me.croabeast</groupId>
112+
<artifactId>${{ github.event.repository.name }}</artifactId>
113+
<versioning>
114+
<latest>${{ env.VERSION }}</latest>
115+
<release>${{ env.VERSION }}</release>
116+
<versions>
117+
<version>${{ env.VERSION }}</version>
118+
</versions>
119+
<lastUpdated>$(date +%Y%m%d%H%M%S)</lastUpdated>
120+
</versioning>
121+
</metadata>
122+
EOF
123+
124+
# Commit and push changes
125+
cd maven-repo
126+
git add .
127+
git commit -m "Deploy ${{ github.event.repository.name }} ${{ env.VERSION }}"
128+
git push
129+
130+
env:
131+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)