Update maven.yml #7
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
name: Java CI with Maven, Auto-Versioning, and Release | |
on: | |
push: | |
branches: [ "master" ] | |
jobs: | |
build-and-release: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # To ensure tags are fetched as well | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: maven | |
- name: Build with Maven and Auto-Versioning | |
run: mvn -B build-helper:parse-version versions:set versions:commit package --file pom.xml | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: minecraft-plugin | |
path: target/*.jar | |
- name: Extract version and artifact name | |
id: extract_info | |
run: | | |
JAR_NAME=$(ls target/*.jar) | |
VERSION=$(echo $JAR_NAME | grep -oP '(?<=-)\d+\.\d+\.\d+(?=-SNAPSHOT)') | |
ARTIFACT_NAME=$(basename $JAR_NAME) | |
echo "::set-output name=version::v$VERSION" | |
echo "::set-output name=artifact_name::$ARTIFACT_NAME" | |
- name: Create and Push Tag | |
run: | | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git tag ${{ needs.build-and-release.outputs.version }} | |
git push origin ${{ needs.build-and-release.outputs.version }} | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
name: ${{ needs.build-and-release.outputs.artifact_name }} | |
tag_name: ${{ needs.build-and-release.outputs.version }} | |
files: target/*.jar | |
generate_release_notes: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |