Skip to content

Красивые changelogs, 1.21.11 API #18

Красивые changelogs, 1.21.11 API

Красивые changelogs, 1.21.11 API #18

name: Сборка и публикация
on:
push:
branches: [ main, master ]
workflow_dispatch:
jobs:
extract-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.VERSION }}
artifact_name: ${{ steps.get_artifact_name.outputs.ARTIFACT_NAME }}
tag_exists: ${{ steps.check_tag.outputs.TAG_EXISTS }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT }}
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: "21"
distribution: "temurin"
- name: Get Maven version
id: get_version
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Detected version: $VERSION"
- name: Get artifact name
id: get_artifact_name
run: |
ARTIFACT_NAME=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> $GITHUB_OUTPUT
echo "Detected artifact name: $ARTIFACT_NAME"
- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "v${{ steps.get_version.outputs.VERSION }}" >/dev/null 2>&1; then
echo "TAG_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "TAG_EXISTS=false" >> $GITHUB_OUTPUT
fi
build:
needs: extract-version
runs-on: ubuntu-latest
if: needs.extract-version.outputs.tag_exists == 'false'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: "21"
distribution: "temurin"
- name: Build
run: mvn clean package
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ needs.extract-version.outputs.artifact_name }}-v${{ needs.extract-version.outputs.version }}
path: target/*.jar
create-tag:
needs: [extract-version, build]
runs-on: ubuntu-latest
if: needs.extract-version.outputs.tag_exists == 'false'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
fetch-depth: 0
- name: Create tag
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git tag -a "v${{ needs.extract-version.outputs.version }}" -m "Release v${{ needs.extract-version.outputs.version }}"
git push origin "v${{ needs.extract-version.outputs.version }}"
release:
needs: [extract-version, create-tag]
runs-on: ubuntu-latest
if: needs.extract-version.outputs.tag_exists == 'false'
outputs:
changelog: ${{ steps.generate_changelog.outputs.CHANGELOG }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT }}
- name: Generate changelog with commit links
id: generate_changelog
run: |
REPO="${{ github.repository }}"
PREV_TAG=$(git describe --tags --abbrev=0 --exclude="v${{ needs.extract-version.outputs.version }}" HEAD~1 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
COMMITS=$(git log --oneline --no-decorate)
else
COMMITS=$(git log "${PREV_TAG}..HEAD" --oneline --no-decorate)
fi
if [ -z "$COMMITS" ]; then
CHANGELOG="Нет изменений"
else
while IFS= read -r line; do
if [ -n "$line" ]; then
COMMIT_HASH=$(echo "$line" | cut -d' ' -f1)
COMMIT_MSG=$(echo "$line" | cut -d' ' -f2-)
echo "- [$COMMIT_HASH](https://github.com/$REPO/commit/$COMMIT_HASH) $COMMIT_MSG"
fi
done <<< "$COMMITS" > /tmp/changelog.md
CHANGELOG=$(cat /tmp/changelog.md)
fi
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.extract-version.outputs.artifact_name }}-v${{ needs.extract-version.outputs.version }}
- name: Remove original-*.jar
run: find . -name "original-*.jar" -delete
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.extract-version.outputs.version }}
name: v${{ needs.extract-version.outputs.version }}
body: ${{ steps.generate_changelog.outputs.CHANGELOG }}
files: "**/*.jar"
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
publish-modrinth:
needs: [extract-version, release]
runs-on: ubuntu-latest
if: needs.extract-version.outputs.tag_exists == 'false'
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.extract-version.outputs.artifact_name }}-v${{ needs.extract-version.outputs.version }}
- name: Remove original-*.jar
run: find . -name "original-*.jar" -delete
- name: Publish to Modrinth
uses: Kir-Antipov/mc-publish@v3.3
with:
modrinth-id: k7ZA8q9y
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
name: v${{ needs.extract-version.outputs.version }}
version: ${{ needs.extract-version.outputs.version }}
version-type: release
changelog: ${{ needs.release.outputs.changelog }}
files: "**/*.jar"
game-versions: |
1.21.11
loaders: |
paper
spigot
purpur
folia
bukkit