Update maven.yml #39
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" ] | |
permissions: | |
contents: write | |
jobs: | |
checkout-code: | |
runs-on: ubuntu-latest | |
outputs: | |
# Utwórz output, który będzie zawierał ścieżkę do kodu źródłowego | |
source-dir: ${{ github.workspace }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # To ensure tags are fetched as well | |
token: ${{ secrets.GITHUB_TOKEN }} # Użyj GITHUB_TOKEN do checkout | |
- name: Upload source code for other jobs | |
uses: actions/upload-artifact@v3 | |
with: | |
name: source-code | |
path: . | |
setup-java: | |
runs-on: ubuntu-latest | |
needs: checkout-code | |
steps: | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: maven | |
build-with-maven: | |
runs-on: ubuntu-latest | |
needs: setup-java | |
steps: | |
- name: Download source code | |
uses: actions/download-artifact@v3 | |
with: | |
name: source-code | |
- name: Build with Maven and Auto-Versioning | |
run: mvn -B build-helper:parse-version versions:set versions:commit package --file pom.xml | |
upload-artifact: | |
runs-on: ubuntu-latest | |
needs: build-with-maven | |
steps: | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: minecraft-plugin | |
path: target/*.jar | |
extract-info: | |
runs-on: ubuntu-latest | |
needs: upload-artifact | |
outputs: | |
version: ${{ steps.extract_info.outputs.version }} | |
artifact_name: ${{ steps.extract_info.outputs.artifact_name }} | |
steps: | |
- name: Extract version and artifact name | |
id: extract_info | |
run: | | |
JAR_NAME=$(ls target/*.jar) | |
ARTIFACT_NAME=$(basename $JAR_NAME) | |
VERSION=$(echo $ARTIFACT_NAME | grep -oP '(?<=-)\d+\.\d+\.\d+(?=-SNAPSHOT)') | |
echo "::set-output name=version::v$VERSION" | |
echo "::set-output name=artifact_name::$ARTIFACT_NAME" | |
create-and-push-tag: | |
runs-on: ubuntu-latest | |
needs: extract-info | |
steps: | |
- name: Create and Push Tag | |
run: | | |
git config user.name "GitHub Actions" | |
git config user.email "github-actions@users.noreply.github.com" | |
git tag ${{ needs.extract-info.outputs.version }} | |
git push https://x-access-token:${{ secrets.BE_ACCESS_TOKEN }}@github.com/${{ github.repository }} ${{ needs.extract-info.outputs.version }} | |
create-release: | |
runs-on: ubuntu-latest | |
needs: [extract-info, create-and-push-tag] | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: minecraft-plugin | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
name: ${{ needs.extract-info.outputs.artifact_name }} | |
tag_name: ${{ needs.extract-info.outputs.version }} | |
files: target/*.jar | |
generate_release_notes: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |