Skip to content

Update build.yaml (#127) #10

Update build.yaml (#127)

Update build.yaml (#127) #10

Workflow file for this run

name: Build release candidate
on:
release:
types: [created]
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v2 # Updated to use the latest version of the setup-java action
with:
distribution: 'temurin' # Best practice to specify the Java distribution
java-version: '17'
- name: Set current version
run: mvn -B versions:set -DnewVersion=${{ github.ref_name }} -DprocessAllModules -DgenerateBackupPoms=false
- name: Test with Maven
run: mvn test
- name: Upload test artifact
uses: actions/upload-artifact@v4
with:
name: test-artifact
path: target/
sonarcloud:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
- name: Test, package, and analyze with Maven & SonarCloud
run: mvn verify sonar:sonar -Dsonar.projectKey=InseeFr_Metadata-API -Dsonar.organization=inseefr -Dsonar.host.url=https://sonarcloud.io
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
build:
runs-on: ubuntu-latest
needs: sonarcloud
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
- name: Set current version
run: mvn -B versions:set -DnewVersion=${{ github.ref_name }} -DprocessAllModules -DgenerateBackupPoms=false
- name: Build with Maven
run: mvn package -Dchangelist=-SNAPSHOT --no-transfer-progress
- name: Upload API war
uses: actions/upload-artifact@v4
with:
name: app-war
path: target/*.war
docker:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs: build
steps:
- uses: actions/checkout@v4
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: app-war
path: target/
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v3 # Ensure to use the correct version
with:
images: inseefr/metadata-api
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
- name: Image digest
run: |
echo "Docker Image Digest: ${{ steps.docker_build.outputs.digest }}"