|
| 1 | +name: Publish to Maven Repository |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +jobs: |
| 8 | + publish: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v3 |
| 12 | + |
| 13 | + - name: Set up JDK 17 |
| 14 | + uses: actions/setup-java@v3 |
| 15 | + with: |
| 16 | + java-version: '17' |
| 17 | + distribution: 'temurin' |
| 18 | + |
| 19 | + - name: Build with Maven |
| 20 | + run: mvn package |
| 21 | + |
| 22 | + - name: Get version from release |
| 23 | + id: get_version |
| 24 | + run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV |
| 25 | + |
| 26 | + - name: Checkout Maven repository |
| 27 | + uses: actions/checkout@v3 |
| 28 | + with: |
| 29 | + repository: CroaBeast/repo |
| 30 | + path: maven-repo |
| 31 | + token: ${{ secrets.MAVEN_DEPLOY_TOKEN }} |
| 32 | + |
| 33 | + - name: Configure Git |
| 34 | + run: | |
| 35 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 36 | + git config --global user.name "github-actions[bot]" |
| 37 | + |
| 38 | + - name: Deploy to Maven repository |
| 39 | + run: | |
| 40 | + # Create directory structure |
| 41 | + mkdir -p maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }} |
| 42 | + |
| 43 | + # Copy JAR file |
| 44 | + cp target/${{ github.event.repository.name }}-${{ env.VERSION }}.jar maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/ |
| 45 | + |
| 46 | + # Create POM file |
| 47 | + cat > maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/${{ github.event.repository.name }}-${{ env.VERSION }}.pom << EOF |
| 48 | + <?xml version="1.0" encoding="UTF-8"?> |
| 49 | + <project> |
| 50 | + <modelVersion>4.0.0</modelVersion> |
| 51 | + <groupId>me.croabeast</groupId> |
| 52 | + <artifactId>${{ github.event.repository.name }}</artifactId> |
| 53 | + <version>${{ env.VERSION }}</version> |
| 54 | + <packaging>jar</packaging> |
| 55 | + </project> |
| 56 | + EOF |
| 57 | + |
| 58 | + # Update or create maven-metadata.xml |
| 59 | + cat > maven-repo/me/croabeast/${{ github.event.repository.name }}/maven-metadata.xml << EOF |
| 60 | + <?xml version="1.0" encoding="UTF-8"?> |
| 61 | + <metadata> |
| 62 | + <groupId>me.croabeast</groupId> |
| 63 | + <artifactId>${{ github.event.repository.name }}</artifactId> |
| 64 | + <versioning> |
| 65 | + <latest>${{ env.VERSION }}</latest> |
| 66 | + <release>${{ env.VERSION }}</release> |
| 67 | + <versions> |
| 68 | + <version>${{ env.VERSION }}</version> |
| 69 | + </versions> |
| 70 | + <lastUpdated>$(date +%Y%m%d%H%M%S)</lastUpdated> |
| 71 | + </versioning> |
| 72 | + </metadata> |
| 73 | + EOF |
| 74 | + |
| 75 | + # Commit and push changes |
| 76 | + cd maven-repo |
| 77 | + git add . |
| 78 | + git commit -m "Deploy ${{ github.event.repository.name }} ${{ env.VERSION }}" |
| 79 | + git push |
| 80 | +
|
| 81 | +env: |
| 82 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments