From 3fc1e31fa8c293a478f0885ef7d5bec69e603e16 Mon Sep 17 00:00:00 2001 From: Dylan Garvis Date: Thu, 22 Jan 2026 22:31:29 -0500 Subject: [PATCH] build: add gitea release workflow --- .gitea/workflows/build.yml | 89 ++++++++++++++++++++++++++++++++++++++ .gitignore | 1 + .releaserc.cjs | 23 ++++++++++ README.md | 7 +++ build.gradle.kts | 2 +- commitlint.config.cjs | 3 ++ gradle.properties | 1 + package.json | 11 +++++ 8 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/build.yml create mode 100644 .releaserc.cjs create mode 100644 commitlint.config.cjs create mode 100644 gradle.properties create mode 100644 package.json diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..e48092d --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,89 @@ +name: Build + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITEA_TOKEN }} + + - 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 }} + 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 + echo "GITEA_API_URL is not set in repo variables." + exit 1 + 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" diff --git a/.gitignore b/.gitignore index bafa35a..f1e73a1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ .settings/ build/ out/ +node_modules/ *.iml .DS_Store diff --git a/.releaserc.cjs b/.releaserc.cjs new file mode 100644 index 0000000..1de1005 --- /dev/null +++ b/.releaserc.cjs @@ -0,0 +1,23 @@ +module.exports = { + branches: ["main"], + tagFormat: "v${version}", + plugins: [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + [ + "@semantic-release/exec", + { + prepareCmd: + "node -e \"const fs=require('fs');fs.writeFileSync('gradle.properties', 'version=' + process.env.RELEASE_VERSION + '\\n');\"", + }, + ], + [ + "@semantic-release/git", + { + assets: ["gradle.properties"], + message: + "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}", + }, + ], + ], +}; diff --git a/README.md b/README.md index ae3933e..1163bf3 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,13 @@ scrape_configs: credentials: "" ``` +## CI Release Notes + +The Gitea workflow expects these secrets/variables: + +- `GITEA_TOKEN`: token with repo write access for tags/releases. +- `GITEA_API_URL`: API base URL, for example `https://git.garvis.dev/api/v1`. + ## Metrics Some metrics depend on server implementations (TPS/MSPT, player ping, tile entities). If a method is unavailable on your server build, those metrics are omitted. diff --git a/build.gradle.kts b/build.gradle.kts index 7fc31a3..fcda193 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } group = "com.prometheus" -version = "0.1.0" +version = project.findProperty("version")?.toString() ?: "0.1.0" repositories { mavenCentral() diff --git a/commitlint.config.cjs b/commitlint.config.cjs new file mode 100644 index 0000000..69b4242 --- /dev/null +++ b/commitlint.config.cjs @@ -0,0 +1,3 @@ +module.exports = { + extends: ["@commitlint/config-conventional"], +}; diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..de55ab6 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +version=0.1.0 diff --git a/package.json b/package.json new file mode 100644 index 0000000..b8c8050 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "prometheus-spigot", + "private": true, + "devDependencies": { + "@commitlint/cli": "^19.5.0", + "@commitlint/config-conventional": "^19.5.0", + "@semantic-release/exec": "^6.0.3", + "@semantic-release/git": "^10.0.1", + "semantic-release": "^23.1.1" + } +}