-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28e5486
commit 8011156
Showing
1 changed file
with
48 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }}" |