@@ -0,0 +1,119 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Java
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 21
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22.14.0
|
||||
|
||||
- name: Install Node dependencies
|
||||
run: npm install
|
||||
|
||||
- name: Lint commits
|
||||
run: |
|
||||
if [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then
|
||||
FROM=$(git rev-list --max-parents=0 HEAD)
|
||||
else
|
||||
FROM="${{ github.event.before }}"
|
||||
fi
|
||||
npx commitlint --from "$FROM" --to "${{ github.sha }}"
|
||||
|
||||
- name: Release version
|
||||
env:
|
||||
GIT_AUTHOR_NAME: "automation"
|
||||
GIT_AUTHOR_EMAIL: "automation@local"
|
||||
GIT_COMMITTER_NAME: "automation"
|
||||
GIT_COMMITTER_EMAIL: "automation@local"
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: npx semantic-release
|
||||
|
||||
- name: Build
|
||||
run: mvn -B package
|
||||
|
||||
- name: Name build artifact
|
||||
run: |
|
||||
if [ -f release-version.txt ]; then
|
||||
VERSION=$(tr -d '\n' < release-version.txt)
|
||||
else
|
||||
VERSION=dev-${GITHUB_SHA:0:7}
|
||||
fi
|
||||
JAR_PATH=$(ls target/*.jar | head -n 1)
|
||||
cp "$JAR_PATH" "target/spigot-chat-sync-${VERSION}.jar"
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: spigot-chat-sync-jar
|
||||
path: target/spigot-chat-sync-*.jar
|
||||
|
||||
- name: Create release
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GITEA_API: ${{ vars.GITEA_API_URL }}
|
||||
GITEA_SERVER_URL: ${{ vars.GITEA_SERVER_URL }}
|
||||
GITHUB_SERVER_URL: ${{ github.server_url }}
|
||||
run: |
|
||||
TAG=$(git describe --tags --exact-match 2>/dev/null || true)
|
||||
if [ -z "$TAG" ]; then
|
||||
echo "No release tag on HEAD; skipping release."
|
||||
exit 0
|
||||
fi
|
||||
if [ -z "$GITEA_API" ]; then
|
||||
if [ -n "$GITEA_SERVER_URL" ]; then
|
||||
GITEA_API="${GITEA_SERVER_URL}/api/v1"
|
||||
elif [ -n "$GITHUB_SERVER_URL" ]; then
|
||||
GITEA_API="${GITHUB_SERVER_URL}/api/v1"
|
||||
else
|
||||
echo "GITEA_API_URL is not set and server URL is unavailable."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
VERSION=${TAG#v}
|
||||
JAR_PATH=$(ls target/spigot-chat-sync-*.jar | head -n 1)
|
||||
RELEASE_RESPONSE=$(curl -sS -X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"${GITEA_API}/repos/${GITHUB_REPOSITORY}/releases" \
|
||||
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"draft\":false,\"prerelease\":false}")
|
||||
RELEASE_ID=$(python3 - <<'PY'
|
||||
import json
|
||||
import sys
|
||||
|
||||
try:
|
||||
payload = json.load(sys.stdin)
|
||||
except json.JSONDecodeError:
|
||||
payload = {}
|
||||
|
||||
value = payload.get("id", "")
|
||||
sys.stdout.write(str(value) if value is not None else "")
|
||||
PY
|
||||
)
|
||||
if [ -z "$RELEASE_ID" ]; then
|
||||
echo "Failed to create release."
|
||||
echo "$RELEASE_RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
curl -sS -X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary "@${JAR_PATH}" \
|
||||
"${GITEA_API}/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=spigot-chat-sync-${VERSION}.jar"
|
||||
Reference in New Issue
Block a user