Release and Publish #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Creates GitHub releases and publishes to GitHub Packages and Maven Central | |
| name: Release and Publish | |
| permissions: | |
| contents: write | |
| packages: write | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to release' | |
| required: true | |
| type: string | |
| jobs: | |
| build: | |
| name: Build Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 22 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '22' | |
| distribution: 'temurin' | |
| cache: gradle | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Build with Gradle | |
| run: ./gradlew build | |
| - name: Determine version | |
| id: determine-version | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV | |
| else | |
| TAG=${GITHUB_REF#refs/tags/v} | |
| echo "VERSION=$TAG" >> $GITHUB_ENV | |
| fi | |
| echo "VERSION=${{ env.VERSION }}" | |
| - name: Generate Changelog | |
| id: changelog | |
| run: | | |
| git fetch --tags --force | |
| CURRENT_TAG="v${{ env.VERSION }}" | |
| PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -vx "$CURRENT_TAG" | head -n1) | |
| if [ -z "$PREVIOUS_TAG" ]; then | |
| echo "## π Initial Release $CURRENT_TAG" > changelog.md | |
| echo "" >> changelog.md | |
| echo "This is the first official release." >> changelog.md | |
| else | |
| echo "## π Release $CURRENT_TAG" > changelog.md | |
| echo "" >> changelog.md | |
| echo "### Changes since $PREVIOUS_TAG:" >> changelog.md | |
| echo "" >> changelog.md | |
| git log --pretty=format:"* %s (%h)" "$PREVIOUS_TAG"..HEAD \ | |
| | grep -v "Merge" \ | |
| | grep -v "Merge remote-tracking branch" >> changelog.md | |
| fi | |
| cat changelog.md | |
| CHANGELOG=$(cat changelog.md) | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| echo "$CHANGELOG" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create Release | |
| id: create_release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ env.VERSION }} | |
| name: Release v${{ env.VERSION }} | |
| body: ${{ steps.changelog.outputs.changelog }} | |
| draft: false | |
| prerelease: false | |
| files: | | |
| API/build/libs/*.jar | |
| Common/build/libs/*.jar | |
| LICENSE | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish to BiomeBattle Maven | |
| uses: gradle/gradle-build-action@v2 | |
| with: | |
| arguments: publish | |
| env: | |
| BB_REPO_USERNAME: ${{ secrets.BB_REPO_USERNAME }} | |
| BB_REPO_PASSWORD: ${{ secrets.BB_REPO_PASSWORD }} |