97 lines
3.0 KiB
YAML
97 lines
3.0 KiB
YAML
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: 20
|
|
|
|
- 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: ./gradlew build
|
|
|
|
- name: Upload artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: prometheus-spigot-jar
|
|
path: build/libs/*.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 build/libs/*.jar | head -n 1)
|
|
RELEASE_ID=$(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}" \
|
|
| python -c "import sys, json; print(json.load(sys.stdin).get('id', ''))")
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "Failed to create release."
|
|
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=prometheus-spigot-${VERSION}.jar"
|