Skip to content

Commit

Permalink
CI pipelines (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
DusanStevic authored Sep 15, 2021
1 parent 7d5f66f commit 42bfad4
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci-pr-develop-pipeline.yml
Original file line number Diff line number Diff line change
@@ -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-admin-service
52 changes: 52 additions & 0 deletions .github/workflows/ci-push-develop-pipeline.yml
Original file line number Diff line number Diff line change
@@ -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 Admin service docker image
run: bash ./publish-dockerhub.sh ${{ needs.prerelease.outputs.tag_name }} ${{ secrets.DOCKER_USER }} ${{ secrets.DOCKER_PASS }}
51 changes: 51 additions & 0 deletions .github/workflows/ci-push-main-pipeline.yml
Original file line number Diff line number Diff line change
@@ -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 Admin service docker image
run: bash ./publish-dockerhub.sh ${{ needs.release.outputs.tag_name }} ${{ secrets.DOCKER_USER }} ${{ secrets.DOCKER_PASS }}
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<properties>
<java.version>1.8</java.version>
<appName>admin_service</appName>
<sonar.organization>devops-nistagram-organization</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<spring-cloud.version>2020.0.3</spring-cloud.version>
</properties>
<dependencies>
Expand Down Expand Up @@ -88,8 +90,20 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
</plugins>
<finalName>${appName}</finalName>
</build>
<distributionManagement>
<repository>
<id>github</id>
<name>Nistagram Admin service GitHub Package</name>
<url>https://maven.pkg.github.com/DevOps-Nistagram-Organization/Nistagram-admin-service</url>
</repository>
</distributionManagement>

</project>
14 changes: 14 additions & 0 deletions publish-dockerhub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

VERSION=${1}
DOCKERHUB_USERNAME=${2}
DOCKERHUB_PASSWORD=${3}


ADMIN=${DOCKERHUB_USERNAME}/nistagram-admin-service:${VERSION}

DOCKER_BUILDKIT=1 docker build -t ${ADMIN} --no-cache .

docker login --username ${DOCKERHUB_USERNAME} --password ${DOCKERHUB_PASSWORD}

docker push ${ADMIN}

0 comments on commit 42bfad4

Please sign in to comment.