diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml deleted file mode 100644 index 9daff53..0000000 --- a/.github/workflows/build-pr.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Build PR & check title - -on: - pull_request: - types: [opened, edited, synchronize, reopened] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up JDK 21 - uses: actions/setup-java@v3 - with: - distribution: "temurin" - java-version: "21" - - - name: Build PE - run: mvn package --no-transfer-progress \ No newline at end of file diff --git a/.github/workflows/create-release.yaml b/.github/workflows/create-release.yaml new file mode 100644 index 0000000..b410156 --- /dev/null +++ b/.github/workflows/create-release.yaml @@ -0,0 +1,147 @@ +name: Public-Enemy Back Office release + +on: + push: + branches: + - "main" + paths-ignore: + ["docs/**", "Dockerfile", "LICENSE", "CHANGELOG.md", "README.md"] + +jobs: + check-version: + runs-on: ubuntu-latest + outputs: + release-version: ${{ steps.version-step.outputs.version }} + steps: + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "21" + + - name: Checkout Public-Enemy Back Office repo + uses: actions/checkout@v4 + + - name: Get Version + id: version-step + run: echo "version=$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT + + - name: Print Version + run: echo ${{ steps.version-step.outputs.version }} + + - uses: mukunku/tag-exists-action@v1.6.0 + name: Check tag existence + id: check-tag-exists + with: + tag: ${{ steps.version-step.outputs.version }} + + - 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-step.outputs.version }} already exists" + exit 1 + fi + + if ! [[ "${{ steps.version-step.outputs.version }}" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then + echo "Nothing to tag/release, the tag ${{ steps.version-step.outputs.version }} is not in correct format X.Y.Z" + exit 1 + fi + + build-sources: + needs: check-version + runs-on: ubuntu-latest + steps: + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "21" + + - uses: actions/checkout@v4 + - name: Build Public-Enemy Back Office with Maven + run: mvn clean package -B -V --file pom.xml --no-transfer-progress + + - name: Upload jar + uses: actions/upload-artifact@v4 + with: + name: jar + path: target/*.jar + + create-release: + needs: [check-version, build-sources] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Get previous release tag + id: previousTag + run: echo "previousTag=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$" | tail -1)" >> $GITHUB_OUTPUT + + - name: Create tag + uses: rickstaa/action-create-tag@v1 + with: + tag: ${{ needs.check-version.outputs.release-version }} + + - name: Create release note + id: changelog + uses: requarks/changelog-action@v1 + with: + fromTag: ${{ needs.check-version.outputs.release-version }} + toTag: ${{ steps.previousTag.outputs.previousTag}} + excludeTypes: docs,style,chore,other + token: ${{ secrets.GITHUB_TOKEN }} + writeToFile: true + changelogFilePath: "CHANGELOG.md" + + - name: Commit changelog file + uses: stefanzweifel/git-auto-commit-action@v5 + with: + branch: 'main' + commit_message: 'docs(changelog): ${{ needs.check-version.outputs.release-version }} update [skip ci]' + file_pattern: 'CHANGELOG.md' + + - name: Download jar + id: download + uses: actions/download-artifact@v4 + with: + name: jar + path: target/ + + - name: Create GitHub release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ needs.check-version.outputs.release-version }} + target_commitish: ${{ github.head_ref || github.ref }} + name: ${{ needs.check-version.outputs.release-version }} + body: ${{steps.changelog.outputs.changes}} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + publish-docker: + needs: [check-version, create-release] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Download jar + id: download + uses: actions/download-artifact@v4 + with: + name: jar + path: target/ + + - name: Publish to Docker Hub + uses: elgohr/Publish-Docker-Github-Action@v5 + with: + name: inseefr/public-enemy-back-office + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + default_branch: ${{ github.ref }} + tags: "latest,${{ needs.check-version.outputs.release-version }}" diff --git a/.github/workflows/create-snapshot.yaml b/.github/workflows/create-snapshot.yaml new file mode 100644 index 0000000..04537f0 --- /dev/null +++ b/.github/workflows/create-snapshot.yaml @@ -0,0 +1,136 @@ +name: Public-Enemy Back Office snapshot + +# This action is triggered when the 'deploy-snapshot' tag is put in a pull request. +on: + pull_request: + types: [labeled] + paths-ignore: + - 'logo/**' + - 'docs/**' + - 'CHANGELOG.md' + - 'README**.md' + - 'Dockerfile' + - '.github/**' + +jobs: + + remove-deploy-label: + if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy-snapshot') }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions-ecosystem/action-remove-labels@v1 + with: + labels: 'deploy-snapshot' + + check-version: + needs: remove-deploy-label + runs-on: ubuntu-latest + outputs: + snapshot-version: ${{ steps.version-step.outputs.version }} + steps: + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + + - name: Checkout Public-Enemy Back-Office repo + uses: actions/checkout@v4 + + - name: Get Version + id: version-step + run: echo "version=$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT + + - name: Print Version + run: echo ${{ steps.version-step.outputs.version }} + + - uses: mukunku/tag-exists-action@v1.6.0 + name: Check tag existence + id: check-tag-exists + with: + tag: ${{ steps.version-step.outputs.version }} + + - 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-step.outputs.version }} already exists" + exit 1 + fi + + if ! [[ "${{ steps.version-step.outputs.version }}" =~ ^[0-9]+.[0-9]+.[0-9]+-SNAPSHOT.?[0-9]*$ ]]; then + echo "Nothing to tag/release, the tag ${{ steps.version-step.outputs.version }} is not in correct format X.Y.Z-SNAPSHOT" + exit 1 + fi + + build-sources: + needs: check-version + runs-on: ubuntu-latest + steps: + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + + - uses: actions/checkout@v4 + - name: Build Public-Enemy Back-Office with Maven + run: mvn clean package -B -V --file pom.xml --no-transfer-progress + + - name: Upload jar + uses: actions/upload-artifact@v4 + with: + name: jar + path: target/*.jar + + create-tag: + needs: [ check-version, build-sources ] + runs-on: ubuntu-latest + steps: + - name: Create tag + uses: actions/github-script@v7 + with: + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: 'refs/tags/${{ needs.check-version.outputs.snapshot-version }}', + sha: context.sha + }) + + publish-docker: + needs: [ check-version, create-tag ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Download jar + id: download + uses: actions/download-artifact@v4 + with: + name: jar + path: target/ + + - name: Publish to Docker Hub + uses: elgohr/Publish-Docker-Github-Action@v5 + with: + name: inseefr/public-enemy-back-office + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + default_branch: ${{ github.ref }} + tags: ${{ needs.check-version.outputs.snapshot-version }} + + write-comment: + needs: [ check-version, publish-docker ] + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '👋 Version ${{ needs.check-version.outputs.snapshot-version }} deployed on docker hub' + }) diff --git a/.github/workflows/release-develop.yml b/.github/workflows/release-develop.yml deleted file mode 100644 index 362f705..0000000 --- a/.github/workflows/release-develop.yml +++ /dev/null @@ -1,115 +0,0 @@ -name: Build release candidate - -on: - push: - branches: - - develop - -jobs: - check-version: - runs-on: ubuntu-latest - outputs: - release-version: ${{ steps.version.outputs.pe-version }} - tag-already-exists: ${{ steps.checkTag.outputs.exists }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Get version - id: version - run: echo "pe-version=$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)-rc" >> $GITHUB_OUTPUT - - - name: Print version - run: echo ${{ steps.version.outputs.pe-version }} - - - uses: mukunku/tag-exists-action@v1.6.0 - id: checkTag - with: - tag: ${{ steps.version.outputs.pe-version }} - - - if: ${{ steps.checkTag.outputs.exists == 'true' }} - name: "Skip release" - run: echo "Nothing to tag/release, the release ${{ steps.version.outputs.pe-version }} already exists" - - create-release: - needs: check-version - runs-on: ubuntu-latest - if: ${{ needs.check-version.outputs.tag-already-exists == 'false' }} - steps: - - uses: actions/checkout@v3 - with: - ref: ${{ github.ref }} - fetch-depth: 0 - - - name: Get previous tag - id: previousTag - run: echo "previousTag=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | grep '^[0-9]\+\.[0-9]\+\.[0-9]\+\-rc$' | tail -1)" >> $GITHUB_OUTPUT - - - name: Create release note - id: changelog - uses: requarks/changelog-action@v1 - with: - fromTag: ${{ github.sha }} - toTag: ${{ steps.previousTag.outputs.previousTag}} - token: ${{ secrets.GITHUB_TOKEN }} - writeToFile: false - - - uses: softprops/action-gh-release@v1 - with: - tag_name: ${{ needs.check-version.outputs.release-version }} - target_commitish: ${{ github.head_ref || github.ref }} - name: ${{ needs.check-version.outputs.release-version }} - body: ${{steps.changelog.outputs.changes}} - prerelease: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - build-release: - needs: create-release - runs-on: ubuntu-latest - steps: - - name: Extract branch name - shell: bash - run: echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >>$GITHUB_OUTPUT - id: extract_branch - - - uses: actions/checkout@v3 - with: - ref: ${{ steps.extract_branch.outputs.branch }} - - - name: Set up JDK 21 - uses: actions/setup-java@v3 - with: - distribution: "temurin" - java-version: "21" - - - name: Build PE - run: mvn package --no-transfer-progress - - - name: Upload PE jar - uses: actions/upload-artifact@v3 - with: - name: pe-jar - path: target/*.jar - - docker: - needs: - - check-version - - build-release - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Download PE jar - uses: actions/download-artifact@v3 - with: - name: pe-jar - path: target/ - - - name: Publish to Registry - uses: elgohr/Publish-Docker-Github-Action@v5 - with: - name: inseefr/public-enemy-back-office - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - tags: "latest, ${{ needs.check-version.outputs.release-version }}" diff --git a/.github/workflows/release-main.yml b/.github/workflows/release-main.yml deleted file mode 100644 index 813413e..0000000 --- a/.github/workflows/release-main.yml +++ /dev/null @@ -1,114 +0,0 @@ -name: Build release - -on: - push: - branches: - - main - -jobs: - check-version: - runs-on: ubuntu-latest - outputs: - release-version: ${{ steps.version.outputs.pe-version }} - tag-already-exists: ${{ steps.checkTag.outputs.exists }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Get version - id: version - run: echo "pe-version=$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT - - - name: Print version - run: echo ${{ steps.version.outputs.pe-version }} - - - uses: mukunku/tag-exists-action@v1.6.0 - id: checkTag - with: - tag: ${{ steps.version.outputs.pe-version }} - - - if: ${{ steps.checkTag.outputs.exists == 'true' }} - name: "Skip release" - run: echo "Nothing to tag/release, the release ${{ steps.version.outputs.pe-version }} already exists" - - create-release: - needs: check-version - runs-on: ubuntu-latest - if: ${{ needs.check-version.outputs.tag-already-exists == 'false' }} - steps: - - uses: actions/checkout@v3 - with: - ref: ${{ github.ref }} - fetch-depth: 0 - - - name: Get previous tag - id: previousTag - run: echo "previousTag=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | grep '^[0-9]\+\.[0-9]\+\.[0-9]\+$' | tail -1)" >> $GITHUB_OUTPUT - - - name: Create release note - id: changelog - uses: requarks/changelog-action@v1 - with: - fromTag: ${{ github.sha }} - toTag: ${{ steps.previousTag.outputs.previousTag}} - token: ${{ secrets.GITHUB_TOKEN }} - writeToFile: false - - - uses: softprops/action-gh-release@v1 - with: - tag_name: ${{ needs.check-version.outputs.release-version }} - target_commitish: ${{ github.head_ref || github.ref }} - name: ${{ needs.check-version.outputs.release-version }} - body: ${{steps.changelog.outputs.changes}} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - build-release: - needs: create-release - runs-on: ubuntu-latest - steps: - - name: Extract branch name - shell: bash - run: echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >>$GITHUB_OUTPUT - id: extract_branch - - - uses: actions/checkout@v3 - with: - ref: ${{ steps.extract_branch.outputs.branch }} - - - name: Set up JDK 21 - uses: actions/setup-java@v3 - with: - distribution: "temurin" - java-version: "21" - - - name: Build PE - run: mvn package --no-transfer-progress - - - name: Upload PE jar - uses: actions/upload-artifact@v3 - with: - name: pe-jar - path: target/*.jar - - docker: - needs: - - check-version - - build-release - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Download PE jar - uses: actions/download-artifact@v3 - with: - name: pe-jar - path: target/ - - - name: Publish to Registry - uses: elgohr/Publish-Docker-Github-Action@v5 - with: - name: inseefr/public-enemy-back-office - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - tags: "${{ needs.check-version.outputs.release-version }}" diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml deleted file mode 100644 index b7f16d7..0000000 --- a/.github/workflows/sonar.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Sonar Analysis - -on: [push] -jobs: - sonarcloud: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Set up JDK 21 - uses: actions/setup-java@v3 - with: - distribution: "temurin" - java-version: "21" - - name: Cache Maven packages - uses: actions/cache@v4 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - name: Cache SonarCloud packages - uses: actions/cache@v4 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - name: Build and analyze - run: mvn clean verify -Pcoverage sonar:sonar --no-transfer-progress - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..1378d51 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,28 @@ +name: Public-Enemy Back Office tests + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths-ignore: ['docs/**', 'Dockerfile', 'LICENSE', 'CHANGELOG.md', 'README.md'] + +jobs: + test: + if: ${{ (github.event.pull_request.draft == false) && !contains(github.event.pull_request.labels.*.name, 'deploy-snapshot') }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + + - name: Run tests with Maven + run: mvn clean test --no-transfer-progress + +# - name: Test, package and analyze with maven & SonarCloud +# run: mvn --no-transfer-progress verify sonar:sonar -Dsonar.projectKey=InseeFr_Pogues-Back-Office -Dsonar.organization=inseefr -Dsonar.host.url=https://sonarcloud.io +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}