Skip to content

Commit

Permalink
Prep for auto dev builds
Browse files Browse the repository at this point in the history
  • Loading branch information
shantek committed Aug 28, 2024
1 parent de19e9b commit dd9edb3
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 9 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Build project and create GitHub Release

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Fetch all history for all tags and branches

- name: Set up JDK 16
uses: actions/setup-java@v2
with:
distribution: adopt
java-version: 16

- name: Set up Maven
uses: stCarolas/[email protected]
with:
maven-version: 3.8.1

- name: Get version from pom.xml
id: version
run: echo "VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV

- name: Check if tag exists
id: tag_exists
run: |
if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then
echo "TAG_EXISTS=true" >> $GITHUB_ENV
else
echo "TAG_EXISTS=false" >> $GITHUB_ENV
fi
- name: Exit if tag exists
if: env.TAG_EXISTS == 'true'
run: echo "Tag v${{ env.VERSION }} already exists. Skipping build and release."

- name: Fetch commit messages
if: env.TAG_EXISTS == 'false'
id: fetch_commits
run: |
git fetch --tags
LAST_TAG=$(git describe --tags --abbrev=0 $(git rev-list --tags --max-count=1))
COMMIT_MESSAGES=$(git log $LAST_TAG..HEAD --pretty=format:"- %s")
echo "COMMIT_MESSAGES<<EOF" >> $GITHUB_ENV
echo "Full Changelog:" >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
echo "$COMMIT_MESSAGES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Build project
if: env.TAG_EXISTS == 'false'
run: mvn package -B

- name: List files in target directory
if: env.TAG_EXISTS == 'false'
run: ls -al ./target/

- name: Create Release
if: env.TAG_EXISTS == 'false'
id: create_release
uses: actions/create-release@v1
with:
tag_name: v${{ env.VERSION }}
release_name: Release ${{ env.VERSION }}
body: ${{ env.COMMIT_MESSAGES }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

- name: Upload Release Asset
if: env.TAG_EXISTS == 'false'
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./target/HorseGuard-${{ env.VERSION }}.jar
asset_name: HorseGuard-${{ env.VERSION }}.jar
asset_content_type: application/java-archive
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
25 changes: 16 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,34 @@
</properties>

<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
Expand Down Expand Up @@ -65,8 +72,8 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
</project>

0 comments on commit dd9edb3

Please sign in to comment.