Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '21'
java-version: '17'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
server-username: ${{ github.actor }} # Automatically uses the GitHub actor (username)
server-password: ${{ secrets.TOKEN }}

- name: Build with Maven
run: mvn -B package --file pom.xml
run: mvn -B -q package --file pom.xml --settings $GITHUB_WORKSPACE/.github/workflows/maven-settings.xml
env:
TOKEN: ${{ secrets.TOKEN }}

- name: Publish to GitHub Packages Apache Maven
run: mvn deploy
run: mvn deploy -pl cannons-bukkit -am --settings $GITHUB_WORKSPACE/.github/workflows/maven-settings.xml
env:
TOKEN: ${{ secrets.TOKEN }}
38 changes: 38 additions & 0 deletions .github/workflows/maven-settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<activeProfiles>
<activeProfile>github</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/APDevTeam/Movecraft</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</profile>
</profiles>

<servers>
<server>
<id>github</id>
<username>Intybyte</username>
<password>${env.TOKEN}</password>
</server>
</servers>

</settings>
106 changes: 106 additions & 0 deletions .github/workflows/pull-request-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Pull Request

on:
pull_request:
workflow_dispatch:

permissions:
contents: read
pull-requests: write
issues: write

jobs:
setup-preview-build:
name: Preview build
runs-on: ubuntu-latest
outputs:
short-commit-hash: ${{ steps.env-setup.outputs.SHORT_COMMIT_HASH }}

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

# Setup for the preview build
- id: env-setup
run: |
SHORT_COMMIT_HASH=$(git rev-parse --short=8 ${{ github.sha }})
JAR_VERSION="Preview-Build-#${{ github.event.number }}-$SHORT_COMMIT_HASH"
echo "SHORT_COMMIT_HASH=$SHORT_COMMIT_HASH" >> "$GITHUB_ENV"
echo "SHORT_COMMIT_HASH=$SHORT_COMMIT_HASH" >> "$GITHUB_OUTPUT"
echo "JAR_VERSION=$JAR_VERSION" >> "$GITHUB_ENV"

- name: Set preview version for cannons-bukkit
run: mvn -B -q versions:set -DnewVersion="${JAR_VERSION}" -f cannons-bukkit/pom.xml

- name: Build with Maven
id: build
run: mvn -B -q package --file pom.xml --settings $GITHUB_WORKSPACE/.github/workflows/maven-settings.xml
env:
TOKEN: ${{ secrets.TOKEN }}

- name: Upload the artifact
if: ${{ steps.build.outcome == 'success' }}
uses: actions/upload-artifact@v4
with:
name: cannons-bukkit${{ github.event.number }}-${{ env.SHORT_COMMIT_HASH }}
path: 'cannons-bukkit/target/cannons-bukkit-${{ env.JAR_VERSION }}.jar'

- name: Get artifact download URL
id: get-artifact-url
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
PR_NUMBER: ${{ github.event.number }}
SHORT_HASH: ${{ env.SHORT_COMMIT_HASH }}
run: |
echo "Fetching artifacts for run $RUN_ID"
ARTIFACTS_JSON=$(curl -sSL -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$REPO/actions/runs/$RUN_ID/artifacts")

ARTIFACT_NAME="cannons-bukkit${PR_NUMBER}-${SHORT_HASH}"
ARTIFACT_ID=$(echo "$ARTIFACTS_JSON" | jq -r --arg name "$ARTIFACT_NAME" '.artifacts[] | select(.name==$name) | .id')

if [ -z "$ARTIFACT_ID" ] || [ "$ARTIFACT_ID" == "null" ]; then
ARTIFACT_ID=$(echo "$ARTIFACTS_JSON" | jq -r '.artifacts[0].id')
fi

if [ -z "$ARTIFACT_ID" ] || [ "$ARTIFACT_ID" == "null" ]; then
echo "No artifact found"
exit 1
fi

DOWNLOAD_URL="https://github.com/$REPO/suites/$RUN_ID/artifacts/$ARTIFACT_ID"
echo "Artifact download URL: $DOWNLOAD_URL"

echo "artifact_url=$DOWNLOAD_URL" >> $GITHUB_OUTPUT

- name: Comment success on PR
if: ${{ steps.build.outcome == 'success' }}
uses: peter-evans/create-or-update-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
✅ Build succeeded!
Download the artifact [here](${{ steps.get-artifact-url.outputs.artifact_url }})

- name: Comment failure on PR
if: ${{ steps.build.outcome != 'success' }}
uses: peter-evans/create-or-update-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
❌ Build failed.
Please check the logs [here](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
7 changes: 7 additions & 0 deletions api-internal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
<target>${java.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
17 changes: 10 additions & 7 deletions cannons-bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/apdevteam/movecraft</url>
<url>https://maven.pkg.github.com/APDevTeam/Movecraft</url>
<releases>
<enabled>true</enabled>
</releases>
Expand Down Expand Up @@ -173,7 +173,7 @@
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>

<finalName>${project.name}</finalName>
<finalName>${project.name}-${version}</finalName>
<defaultGoal>clean install</defaultGoal>
<!-- Resources -->
<resources>
Expand Down Expand Up @@ -216,10 +216,6 @@
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down Expand Up @@ -292,6 +288,13 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.4</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,16 @@
<module>api-internal</module>
<module>cannons-bukkit</module>
</modules>

<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>