diff --git a/.github/workflows/ci-pr-develop-pipeline.yml b/.github/workflows/ci-pr-develop-pipeline.yml new file mode 100644 index 0000000..5a5125c --- /dev/null +++ b/.github/workflows/ci-pr-develop-pipeline.yml @@ -0,0 +1,54 @@ +# source: https://faun.pub/continuous-integration-of-java-project-with-github-actions-7a8a0e8246ef +name: CI operations PR event DEVELOP branch pipeline +on: + pull_request: + branches: + - develop + types: [opened, synchronize, reopened] +jobs: + # Test - Units & Integrations + test: + name: Test - Units & Integrations + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Maven Package + run: mvn -B clean package -DskipTests + #- name: Maven Verify + # run: mvn -B clean verify -Ptest + + # Analyze code with Sonar Cloud + sonar_auth_service: # Generated using Sonar Cloud Maven build template + name: Test - SonarCloud scan (analysis) of auth service + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Cache SonarCloud packages + uses: actions/cache@v1 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Maven packages + uses: actions/cache@v1 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + # -Pdev activate dev profile -f path/to/pom.xml + #run: mvn -Pdev -f -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=DevOps-Nistagram-Organization_Agent + run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=DevOps-Nistagram-Organization_nistagram-agent-service diff --git a/.github/workflows/ci-push-develop-pipeline.yml b/.github/workflows/ci-push-develop-pipeline.yml new file mode 100644 index 0000000..799e3ab --- /dev/null +++ b/.github/workflows/ci-push-develop-pipeline.yml @@ -0,0 +1,52 @@ +# source: https://faun.pub/continuous-integration-of-java-project-with-github-actions-7a8a0e8246ef +name: CI operations PUSH event DEVELOP branch pipeline +on: + push: + branches: + - 'develop' +jobs: + # https://github.com/mathieudutour/github-tag-action + prerelease: + name: Create prerelease + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Bump version and push tag + id: tag_version + uses: mathieudutour/github-tag-action@v5.6 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Create a GitHub prerelease + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.tag_version.outputs.new_tag }} + release_name: Prerelease ${{ steps.tag_version.outputs.new_tag }} + body: ${{ steps.tag_version.outputs.changelog }} + prerelease: true + outputs: + tag_name: ${{ steps.tag_version.outputs.new_tag }} + + artifact: + name: Publish - GitHub Packages + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Publish artifact on GitHub Packages + run: mvn -B clean deploy -DskipTests + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + docker: + name: Publish - Docker Hub + runs-on: ubuntu-latest + needs: [prerelease] + steps: + - uses: actions/checkout@v1 + - name: Build Nistagram Agent service docker image + run: bash ./publish-dockerhub.sh ${{ needs.prerelease.outputs.tag_name }} ${{ secrets.DOCKER_USER }} ${{ secrets.DOCKER_PASS }} \ No newline at end of file diff --git a/.github/workflows/ci-push-main-pipeline.yml b/.github/workflows/ci-push-main-pipeline.yml new file mode 100644 index 0000000..cbbb07e --- /dev/null +++ b/.github/workflows/ci-push-main-pipeline.yml @@ -0,0 +1,51 @@ +# source: https://faun.pub/continuous-integration-of-java-project-with-github-actions-7a8a0e8246ef +name: CI operations PUSH event MAIN branch pipeline +on: + push: + branches: + - 'main' +jobs: + # https://github.com/mathieudutour/github-tag-action + release: + name: Create release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Bump version and push tag + id: tag_version + uses: mathieudutour/github-tag-action@v5.6 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Create a GitHub release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.tag_version.outputs.new_tag }} + release_name: Release ${{ steps.tag_version.outputs.new_tag }} + body: ${{ steps.tag_version.outputs.changelog }} + outputs: + tag_name: ${{ steps.tag_version.outputs.new_tag }} + + artifact: + name: Publish - GitHub Packages + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Publish artifact on GitHub Packages + run: mvn -B clean deploy -DskipTests + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + docker: + name: Publish - Docker Hub + runs-on: ubuntu-latest + needs: [release] + steps: + - uses: actions/checkout@v1 + - name: Build Nistagram Agent service docker image + run: bash ./publish-dockerhub.sh ${{ needs.release.outputs.tag_name }} ${{ secrets.DOCKER_USER }} ${{ secrets.DOCKER_PASS }} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7608531..deaf37e 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,8 @@ 1.8 agent_service + devops-nistagram-organization + https://sonarcloud.io 2020.0.3 @@ -87,8 +89,20 @@ org.springframework.boot spring-boot-maven-plugin + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + ${appName} + + + github + Nistagram Agent service GitHub Package + https://maven.pkg.github.com/DevOps-Nistagram-Organization/nistagram-agent-service + + diff --git a/publish-dockerhub.sh b/publish-dockerhub.sh new file mode 100644 index 0000000..fb8ee6d --- /dev/null +++ b/publish-dockerhub.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +VERSION=${1} +DOCKERHUB_USERNAME=${2} +DOCKERHUB_PASSWORD=${3} + + +AGENT=${DOCKERHUB_USERNAME}/nistagram-agent-service:${VERSION} + +DOCKER_BUILDKIT=1 docker build -t ${AGENT} --no-cache . + +docker login --username ${DOCKERHUB_USERNAME} --password ${DOCKERHUB_PASSWORD} + +docker push ${AGENT} \ No newline at end of file