Skip to content

Merge pull request #10 from FIAP-Tech-Chalenge/ajustes-endpoint #62

Merge pull request #10 from FIAP-Tech-Chalenge/ajustes-endpoint

Merge pull request #10 from FIAP-Tech-Chalenge/ajustes-endpoint #62

Workflow file for this run

name: Docker Image CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn -B package --file pom.xml
test:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Test with Maven
run: mvn test
sonarcloud-analysis:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: SonarCloud analysis
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=${{ secrets.SONAR_PROJECTKEY }} -Dsonar.organization=${{ secrets.SONAR_ORGANIZATION }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.token=${{ secrets.SONAR_TOKEN }}
- name: Install xmllint
run: sudo apt-get install -y libxml2-utils
- name: Check JaCoCo Coverage
run: |
JACOCO_XML_PATH=target/site/jacoco/jacoco.xml
COVERAGE=$(xmllint --xpath 'string(//report/counter[@type="INSTRUCTION"]/@covered)' $JACOCO_XML_PATH)
MISSED=$(xmllint --xpath 'string(//report/counter[@type="INSTRUCTION"]/@missed)' $JACOCO_XML_PATH)
TOTAL=$(echo "$COVERAGE + $MISSED" | bc)
PERCENTAGE=$(echo "scale=2; $COVERAGE / $TOTAL * 100" | bc)
echo "Code coverage percentage: $PERCENTAGE%"
if (( $(echo "$PERCENTAGE < 50" | bc -l) )); then
echo "Code coverage is below 80%: $PERCENTAGE%"
exit 1
fi
deploy-to-dockerhub:
needs: sonarcloud-analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Read current version
id: get_version
run: echo "VERSION=$(cat version.txt)" >> $GITHUB_ENV
- name: Increment patch version
id: increment_version
run: |
VERSION=${{ env.VERSION }}
IFS='.' read -ra ADDR <<< "$VERSION"
PATCH=$((ADDR[2] + 1))
NEW_VERSION="${ADDR[0]}.${ADDR[1]}.$PATCH"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
echo $NEW_VERSION > version.txt
shell: bash
- name: Debugging Information
run: |
git remote -v
git status
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: |
wolwer/ms-pedido-api:${{ env.NEW_VERSION }}