diff --git a/.github/workflows/release-core.yml b/.github/workflows/release-core.yml new file mode 100644 index 00000000..b0bf97f4 --- /dev/null +++ b/.github/workflows/release-core.yml @@ -0,0 +1,135 @@ +name: Release Partner Core + +on: + workflow_dispatch: + inputs: + tag: + description: "Release tag, for example rel-v0.5.0" + required: true + type: string + push: + tags: + - "rel-v*" + +permissions: + contents: write + +jobs: + release-core: + runs-on: ubuntu-latest + + steps: + - name: Resolve release metadata + id: release + shell: bash + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + TAG="${{ inputs.tag }}" + else + TAG="${GITHUB_REF_NAME}" + fi + + VERSION="${TAG#rel-v}" + ASSET_NAME="partner-core-${VERSION}.jar" + ASSET_URL="https://github.com/slhaf/Partner/releases/download/${TAG}/${ASSET_NAME}" + + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" + echo "asset_name=${ASSET_NAME}" >> "$GITHUB_OUTPUT" + echo "asset_url=${ASSET_URL}" >> "$GITHUB_OUTPUT" + + echo "Release tag: ${TAG}" + echo "Release version: ${VERSION}" + echo "Release asset: ${ASSET_NAME}" + + - name: Checkout release source + uses: actions/checkout@v4 + with: + ref: ${{ steps.release.outputs.tag }} + + - name: Set up Java 21 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "21" + + - name: Build Partner Core + run: | + mvn -B -DskipTests=true -pl Partner-Core -am package + + - name: Prepare release artifact + shell: bash + run: | + mkdir -p dist + + SOURCE_JAR="Partner-Core/target/partner-core-${{ steps.release.outputs.version }}.jar" + + if [ ! -f "$SOURCE_JAR" ]; then + echo "Expected artifact not found: $SOURCE_JAR" + echo "Available Partner-Core target files:" + find Partner-Core/target -maxdepth 1 -type f -name "*.jar" -print + exit 1 + fi + + cp "$SOURCE_JAR" "dist/${{ steps.release.outputs.asset_name }}" + ls -lh dist + + - name: Create GitHub Release + shell: bash + run: | + if gh release view "${{ steps.release.outputs.tag }}" >/dev/null 2>&1; then + echo "Release ${{ steps.release.outputs.tag }} already exists." + exit 1 + fi + + gh release create "${{ steps.release.outputs.tag }}" \ + "dist/${{ steps.release.outputs.asset_name }}" \ + --title "${{ steps.release.outputs.tag }}" \ + --notes "Partner Core ${{ steps.release.outputs.version }}" + env: + GH_TOKEN: ${{ github.token }} + + - name: Checkout master for registry update + uses: actions/checkout@v4 + with: + ref: master + path: registry-worktree + + - name: Update latestRelease + working-directory: registry-worktree + run: | + python3 - <<'PY' + import json + from pathlib import Path + + version = "${{ steps.release.outputs.version }}" + url = "${{ steps.release.outputs.asset_url }}" + + index_path = Path("registry/index.json") + index = json.loads(index_path.read_text(encoding="utf-8")) + + index["partner"]["latestRelease"] = { + "url": url, + "version": version + } + + index_path.write_text( + json.dumps(index, ensure_ascii=False, indent=2) + "\n", + encoding="utf-8" + ) + PY + + - name: Commit registry update + working-directory: registry-worktree + run: | + if git diff --quiet registry/index.json; then + echo "No latestRelease changes." + exit 0 + fi + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + git add registry/index.json + git commit -m "chore(registry): update latest core release to ${{ steps.release.outputs.tag }}" + git push origin HEAD:master \ No newline at end of file