From cb1d8e8a91144516c3f69af68184ea66297eb626 Mon Sep 17 00:00:00 2001 From: Gheorghe Soimu Date: Wed, 25 Sep 2024 17:59:21 +0300 Subject: [PATCH] updated github workflows --- .github/workflows/ci.yaml | 14 ++- .github/workflows/pub-docker-hub.yaml | 29 ------ .github/workflows/pub.yaml | 26 ----- .github/workflows/release.yaml | 89 ++++++++++++++++ pom.xml | 142 +++++++------------------- 5 files changed, 133 insertions(+), 167 deletions(-) delete mode 100644 .github/workflows/pub-docker-hub.yaml delete mode 100644 .github/workflows/pub.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f023adc..84a500b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,8 @@ -name: Java CI - -on: [push] +on: + push: + branches-ignore: + - main + - master-who jobs: build: @@ -8,10 +10,12 @@ jobs: steps: - uses: actions/checkout@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} - name: Set up JDK 17 uses: actions/setup-java@v3 with: java-version: '17' - distribution: 'temurin' + distribution: 'adopt' - name: Build with Maven - run: mvn --batch-mode --update-snapshots package \ No newline at end of file + run: mvn --batch-mode package \ No newline at end of file diff --git a/.github/workflows/pub-docker-hub.yaml b/.github/workflows/pub-docker-hub.yaml deleted file mode 100644 index 3095f57..0000000 --- a/.github/workflows/pub-docker-hub.yaml +++ /dev/null @@ -1,29 +0,0 @@ -name: Publish Docker image to Docker Hub -on: - release: - types: - - published - -jobs: - publish: - runs-on: ubuntu-latest - steps: - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{secrets.DOCKER_USERNAME}} - password: ${{secrets.DOCKER_PASSWORD}} - - uses: actions/checkout@v3 - - name: Set up Maven Central Repository - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'adopt' - server-id: docker.io - server-username: DOCKER_USERNAME - server-password: DOCKER_PASSWORD - - name: Publish package - run: mvn --batch-mode -Prelease package dockerfile:push -env: - DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}} - DOCKER_TOKEN: ${{secrets.DOCKER_PASSWORD}} \ No newline at end of file diff --git a/.github/workflows/pub.yaml b/.github/workflows/pub.yaml deleted file mode 100644 index 15a617a..0000000 --- a/.github/workflows/pub.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: Publish package to the Maven Central Repository -on: - release: - types: [released] - -jobs: - publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Maven Central Repository - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'adopt' - server-id: ossrh - server-username: OSSRH_USERNAME - server-password: OSSRH_TOKEN - gpg-private-key: ${{secrets.GPG_PRIVATE_KEY}} - gpg-passphrase: GPG_PASSPHRASE - - name: Publish package - run: mvn --batch-mode -Prelease deploy -env: - GPG_PASSPHRASE: ${{secrets.GPG_PASSPHRASE}} - OSSRH_USERNAME: ${{secrets.OSSRH_USERNAME}} - OSSRH_TOKEN: ${{secrets.OSSRH_TOKEN}} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..b2f5351 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,89 @@ +name: Release + +on: + push: + branches: + - main + - master-who + +jobs: + build: + runs-on: ubuntu-latest + if: ${{ github.actor != 'protegeproject-bot[bot]' }} + steps: + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{secrets.DOCKER_USERNAME}} + password: ${{secrets.DOCKER_PASSWORD}} + - uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ vars.PROTEGEPROJECT_BOT_APP_ID }} + private-key: ${{ secrets.PROTEGEPROJECT_BOT_APP_PRIVATE_KEY }} + - uses: actions/checkout@v4 + with: + token: ${{ steps.app-token.outputs.token }} + ref: ${{ github.head_ref }} + - name: Set up Maven Central Repository + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'adopt' + server-id: docker.io + server-username: DOCKER_USERNAME + server-password: DOCKER_PASSWORD + - name: Get current version + id: get-version + run: | + current_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + echo "Current version: $current_version" + echo "::set-output name=current_version::$current_version" + - name: Bump version + id: bump + run: | + current_version=${{ steps.get-version.outputs.current_version }} + branch=${GITHUB_REF##*/} + echo "Current branch: $branch" + + # Extract the base version without suffix + base_version=$(echo $current_version | sed -E 's/(-.*)?$//') + + # Increment the base version (assuming semantic versioning) + IFS='.' read -r -a version_parts <<< "$base_version" + version_parts[2]=$((version_parts[2] + 1)) + new_base_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}" + + if [[ "$branch" == "master-who" ]]; then + new_version="${new_base_version}-WHO" + else + new_version="$new_base_version" + fi + + echo "New version: $new_version" + find . -name 'pom.xml' -exec mvn versions:set -DnewVersion=$new_version -DgenerateBackupPoms=false -f {} \; + echo "::set-output name=new_version::$new_version" + - name: Commit new version + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git add . + git commit -m "Bump version to ${{ steps.bump.outputs.new_version }}" + git tag ${{ steps.bump.outputs.new_version }} + git push origin HEAD:${GITHUB_REF##*/} + git push origin ${{ steps.bump.outputs.new_version }} + - name: Build package + run: mvn --batch-mode clean package + - name: Build and push image + run: mvn --batch-mode package install + - name: Release + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.bump.outputs.new_version }} + generate_release_notes: true + +env: + DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}} + DOCKER_TOKEN: ${{secrets.DOCKER_PASSWORD}} diff --git a/pom.xml b/pom.xml index e450abc..471f4b0 100644 --- a/pom.xml +++ b/pom.xml @@ -158,121 +158,49 @@ spring-boot-maven-plugin - com.spotify - dockerfile-maven-plugin - 1.4.13 + org.codehaus.mojo + exec-maven-plugin + 3.3.0 - default + docker-build + package - build + exec + + docker + ${project.basedir} + + build + -f + Dockerfile + --build-arg + JAR_FILE=${project.artifactId}-${project.version}.jar + -t + protegeproject/${project.artifactId}:${project.version} + . + + + + + docker-push + install + + exec + + + docker + ${project.basedir} + + push + protegeproject/${project.artifactId}:${project.version} + + - - protegeproject/${project.artifactId} - ${project.version} - - ${project.build.finalName}.jar - - - - - - - release - - - - org.apache.maven.plugins - maven-source-plugin - 3.2.1 - - - attach-sources - - jar-no-fork - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.2.0 - - none - 16 - - - - attach-javadocs - - jar - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - --pinentry-mode - loopback - - - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ossrh - https://oss.sonatype.org - true - - - - - com.thoughtworks.xstream - xstream - 1.4.15 - - - - - - - - - local - - local - - - -