Skip to content

Build and Publish Release #23

Build and Publish Release

Build and Publish Release #23

Workflow file for this run

name: Build and Publish Release
on:
push:
# Tag triggers releases, push triggers pre-releases
# branches: [ master, main ]
tags:
- '*'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: gradle
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
# build
- name: Build with Gradle Wrapper
run: ./gradlew assemble
- name: Get version & release name
id: version
run: |
echo "version=$(./gradlew -q echoVersion)" >> $GITHUB_OUTPUT
echo "releaseName=$(./gradlew -q echoReleaseName)" >> $GITHUB_OUTPUT
- name: Print version & release name
run: |
echo "Version: ${{ steps.version.outputs.version }}"
echo "Release Name: ${{ steps.version.outputs.releaseName }}"
- name: Create an empty CHANGELOG.md if missing
run: |
if [ ! -f CHANGELOG.md ]; then
touch CHANGELOG.md
fi
- name: Remove all lines after the 2nd title in CHANGELOG.md
shell: pwsh
run: |
$changelogPath = "CHANGELOG.md"
$content = Get-Content -Path CHANGELOG.md
$indices = ($content | ForEach-Object { $_ } | Select-String -Pattern "^#" | ForEach-Object { $_.LineNumber - 1 })
if ($indices.Count -ge 2) {
$startIndex = $indices[0]
$endIndex = $indices[1]
$changes = $content[$startIndex..($endIndex - 1)]
$changes = $changes | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
$changes -join "`n" | Set-Content -Path $changelogPath
Write-Output "Changelog updated"
} else {
Write-Output "Not as much lines as expected"
}
- name: Create Release
id: createRelease
uses: ncipollo/release-action@v1.14.0
with:
allowUpdates: true
updateOnlyUnreleased: true
artifacts: build/libs/Underilla-${{ steps.version.outputs.version }}.jar
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.releaseName }}
bodyFile: CHANGELOG.md
# prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }} #Always release for now
skipIfReleaseExists: true
- name: Publish to hangar #& modrinth
env:
# Make sure you have added a repository secret in the repository's settings
HANGAR_API_TOKEN: ${{ secrets.HANGAR_API_TOKEN }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
run: ./gradlew assemble publishPluginPublicationToHangar #modrinth