Skip to content

Commit

Permalink
Update build.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeMBourgeois authored May 2, 2024
1 parent 28e5486 commit 8011156
Showing 1 changed file with 48 additions and 72 deletions.
120 changes: 48 additions & 72 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,107 +3,83 @@ name: Build release candidate
on:
release:
types: [created]
push:
branches:
- main

jobs:
test:
check-version:
runs-on: ubuntu-latest
outputs:
release-version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
- name: Test with Maven
run: mvn test
- name: Upload test artifact
uses: actions/upload-artifact@v4
- name: Checkout
uses: actions/checkout@v4

- name: Get version
id: version
run: echo "version=$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT

- name: Print version
run: echo ${{ steps.version.outputs.version }}

- uses: mukunku/[email protected]
name: Check tag existence
id: check-tag-exists
with:
name: test-artifact
path: target/
tag: ${{ steps.version.outputs.version }}

sonarcloud:
- name: Tag verification
id: check-tag
run: |
if [[ "${{ steps.check-tag-exists.outputs.exists }}" == "true" ]]; then
echo "Nothing to tag/release, the tag ${{ steps.version.outputs.version }} already exists"
exit 1
fi
build-release:
runs-on: ubuntu-latest
needs: test
steps:
- name: Extract branch name
shell: bash
run: echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >>$GITHUB_OUTPUT
id: extract_branch

- 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 }}
ref: ${{ steps.extract_branch.outputs.branch }}

build:
runs-on: ubuntu-latest
needs: sonarcloud
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v2
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Extract Maven project version
id: mvn_version
run: echo "::set-output name=version::$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)"
- name: Build with Maven
distribution: "temurin"
java-version: "21"

- name: Build API
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:
needs:
- check-version
- build-release
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs: build
steps:
- uses: actions/checkout@v4
- name: Download build artifact

- name: Download uploaded war
uses: actions/download-artifact@v4
with:
name: app-war
path: target/
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v3
with:
images: inseefr/metadata-api
tags: type=semver,pattern={{version}}
flavor: |
latest=false
env:
version: ${{ steps.mvn_version.outputs.version }}
- 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

- name: Publish to Docker Hub
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: inseefr/metadata-api
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 }}"
tags: "latest, ${{ needs.check-version.outputs.release-version }}"

0 comments on commit 8011156

Please sign in to comment.