diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 62f5d490..326e9db4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,23 +14,50 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 + + - name: Extract version from pom.xml + id: extract_version + run: | + VERSION=$(grep -m 1 '' pom.xml | sed -E 's/.*(.*)<\/version>.*/\1/') + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Check if version already exists as a GitHub release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ steps.extract_version.outputs.version }} + run: | + echo "Checking if version $VERSION exists as a GitHub release..." + + RELEASES=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/${{ github.repository }}/releases") + + if echo "$RELEASES" | jq -e ".[] | select(.tag_name == \"$VERSION\")" > /dev/null; then + echo "❌ Release with tag '$VERSION' already exists!" + exit 1 + else + echo "✅ Version $VERSION has not been released yet." + fi + - name: Set up JDK uses: actions/setup-java@v4 with: java-version: 21 distribution: corretto + - name: Cache SonarCloud packages uses: actions/cache@v4 with: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar + - name: Cache Maven packages uses: actions/cache@v4 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 + - name: Build and analyze env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -44,16 +71,19 @@ jobs: CLOUDINARY_URL: "" MERCADOPAGO_ACCESS_TOKEN: "" run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=open-commercial -Dsonar.projectKey=api:api + - name: Generate changelog if: ${{ github.ref == 'refs/heads/master' }} uses: Bullrich/generate-release-changelog@master id: changelog env: REPO: ${{ github.repository }} + - name: Get release version if: ${{ github.ref == 'refs/heads/master' }} run: | echo "RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV + - name: Create Release if: ${{ github.ref == 'refs/heads/master' }} uses: actions/create-release@v1 @@ -64,18 +94,22 @@ jobs: release_name: ${{ env.RELEASE_VERSION }} body: | ${{ steps.changelog.outputs.changelog }} + - name: Set up QEMU if: ${{ github.ref == 'refs/heads/master' }} uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx if: ${{ github.ref == 'refs/heads/master' }} uses: docker/setup-buildx-action@v2 + - name: Login to DockerHub if: ${{ github.ref == 'refs/heads/master' }} uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push Docker image if: ${{ github.ref == 'refs/heads/master' }} uses: docker/build-push-action@v3 diff --git a/pom.xml b/pom.xml index ab8e9a43..f855a248 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.opencommercial api - 1.3.10 + 1.3.11 jar