Skip to content

Commit

Permalink
Update maven.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Grzybol authored Mar 17, 2024
1 parent 0542ce8 commit d88b22d
Showing 1 changed file with 78 additions and 65 deletions.
143 changes: 78 additions & 65 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,82 +8,95 @@ permissions:
contents: write

jobs:
setup:
checkout-code:
runs-on: ubuntu-latest
outputs:
artifact_name: ${{ steps.extract_info.outputs.artifact_name }}
version: ${{ steps.extract_info.outputs.version }}
# 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
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- 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"
- 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: .

build:
needs: setup
setup-java:
runs-on: ubuntu-latest
needs: checkout-code
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- 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: 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:
needs: build
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:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ needs.setup.outputs.artifact_name }}
path: target/*.jar
- 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:
needs: [upload-artifact, setup]
runs-on: ubuntu-latest
needs: [extract-info, create-and-push-tag]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- 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.setup.outputs.version }}
git push https://x-access-token:${{ secrets.BE_ACCESS_TOKEN }}@github.com/${{ github.repository }} ${{ needs.setup.outputs.version }}
- name: Create Release
uses: softprops/action-gh-release@v1
with:
name: ${{ needs.setup.outputs.artifact_name }}
tag_name: ${{ needs.setup.outputs.version }}
files: target/*.jar
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- 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 }}

0 comments on commit d88b22d

Please sign in to comment.