-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added auto building of releases on GitHub
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
name: Build project and create GitHub Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 # Fetch all history for all tags and branches | ||
|
||
- name: Set up JDK 16 | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: adopt | ||
java-version: 16 | ||
|
||
- name: Set up Maven | ||
uses: stCarolas/setup-maven@v4.2 | ||
with: | ||
maven-version: 3.8.1 | ||
|
||
- name: Get version from pom.xml | ||
id: version | ||
run: echo "VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV | ||
|
||
- name: Check if tag exists | ||
id: tag_exists | ||
run: | | ||
if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then | ||
echo "TAG_EXISTS=true" >> $GITHUB_ENV | ||
else | ||
echo "TAG_EXISTS=false" >> $GITHUB_ENV | ||
fi | ||
- name: Exit if tag exists | ||
if: env.TAG_EXISTS == 'true' | ||
run: echo "Tag v${{ env.VERSION }} already exists. Skipping build and release." | ||
|
||
- name: Fetch commit messages | ||
if: env.TAG_EXISTS == 'false' | ||
id: fetch_commits | ||
run: | | ||
git fetch --tags | ||
LAST_TAG=$(git describe --tags --abbrev=0 $(git rev-list --tags --max-count=1)) | ||
COMMIT_MESSAGES=$(git log $LAST_TAG..HEAD --pretty=format:"- %s") | ||
echo "COMMIT_MESSAGES<<EOF" >> $GITHUB_ENV | ||
echo "Full Changelog:" >> $GITHUB_ENV | ||
echo "" >> $GITHUB_ENV | ||
echo "$COMMIT_MESSAGES" >> $GITHUB_ENV | ||
echo "EOF" >> $GITHUB_ENV | ||
- name: Build project | ||
if: env.TAG_EXISTS == 'false' | ||
run: mvn package -B | ||
|
||
- name: List files in target directory | ||
if: env.TAG_EXISTS == 'false' | ||
run: ls -al ./target/ | ||
|
||
- name: Create Release | ||
if: env.TAG_EXISTS == 'false' | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
with: | ||
tag_name: v${{ env.VERSION }} | ||
release_name: Release ${{ env.VERSION }} | ||
body: ${{ env.COMMIT_MESSAGES }} | ||
draft: false | ||
prerelease: false | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
|
||
- name: Upload Release Asset | ||
if: env.TAG_EXISTS == 'false' | ||
uses: actions/upload-release-asset@v1 | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./target/CustomDrops-${{ env.VERSION }}.jar | ||
asset_name: CustomDrops-${{ env.VERSION }}.jar | ||
asset_content_type: application/java-archive | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |