Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<version>' pom.xml | sed -E 's/.*<version>(.*)<\/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 }}
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.opencommercial</groupId>
<artifactId>api</artifactId>
<version>1.3.10</version>
<version>1.3.11</version>
<packaging>jar</packaging>

<parent>
Expand Down