Skip to content

Enhance webhook workflow with closed event and commit filtering #50

Enhance webhook workflow with closed event and commit filtering

Enhance webhook workflow with closed event and commit filtering #50

Workflow file for this run

name: Build Dev
on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
# Check out the repository
- uses: actions/checkout@v4
# Set up JDK 21
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
# Get the short Git commit hash
- name: Get Git Commit Hash
id: commit_hash
run: echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Get Git Branch Name
id: branch_name
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- name: Verify Commit Hash & Branch
run: |
echo "Commit hash is: $commit"
echo "Branch is: $branch"
# Set env variables for branch and commit
- name: Set Variables
run: |
echo "branch=$(echo "${GITHUB_REF_NAME}" | tr '/' '_')" >> $GITHUB_ENV
- name: Check for existing Spigot JAR
id: check_spigot
run: |
if [ -f "./spigot/1.20.jar" ]; then
echo "Spigot JAR exists, skipping BuildTools"
echo "cached=true" >> $GITHUB_OUTPUT
else
echo "cached=false" >> $GITHUB_OUTPUT
fi
- name: Install existing Spigot JAR into local Maven repo
run: |
mkdir -p ~/.m2/repository/org/spigotmc/spigot/1.20-R0.1-SNAPSHOT
cp ./spigot/1.20.jar \
~/.m2/repository/org/spigotmc/spigot/1.20-R0.1-SNAPSHOT/spigot-1.20-R0.1-SNAPSHOT.jar
- name: Download BuildTools
if: steps.check_spigot.outputs.cached == 'false'
run: |
curl -o BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
- name: Generate Spigot
if: steps.check_spigot.outputs.cached == 'false'
run: |
java -jar BuildTools.jar --rev 1.20
mkdir -p ./spigot
cp ~/.m2/repository/org/spigotmc/spigot/1.20-R0.1-SNAPSHOT/spigot-1.20-R0.1-SNAPSHOT.jar ./spigot/1.20.jar
# Step 3: Verify that Spigot is installed
- name: Verify Spigot Installation
run: |
ls ~/.m2/repository/org/spigotmc/spigot/1.20-R0.1-SNAPSHOT
# Extract version from main pom.xml
- name: Get version from main pom.xml
id: get_version
run: |
VERSION=$(grep -oPm1 "(?<=<version>)[^<]+" pom.xml)
echo "VERSION=${VERSION}" >> $GITHUB_ENV
# Replace <version>0.0.0</version> in github/pom.xml
- name: Update version in pom.github.xml
run: |
sed -i "s/<version>0.0.0<\/version>/<version>${{ env.VERSION }}<\/version>/g" pom.github.xml
# Clean with Maven using the custom pom.xml in github folder
- name: Clean with Maven
run: mvn clean -f pom.github.xml
# Build with Maven using the custom pom.xml in github folder
- name: Build with Maven
run: mvn install -f pom.github.xml
# Rename the built JAR with the commit hash
- name: Rename Built JAR
run: |
mv target/HavenBags.jar target/HavenBags-${{ env.branch }}-$commit.jar
# Verify the renamed file
- name: Verify Renamed JAR
run: ls target/
# Upload the JAR as an artifact
- name: Upload JAR as Artifact
uses: actions/upload-artifact@v4
with:
name: HavenBags-${{ env.branch }}-${{ env.commit }}.jar
path: target/HavenBags-${{ env.branch }}-${{ env.commit }}.jar # Use env.commit and env.branch for proper variable interpolation