Merge branch 'release/5.1.11' #5
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
name: Build and Publish Library | |
on: | |
push: | |
branches: | |
- master | |
permissions: | |
contents: write | |
packages: write | |
checks: write | |
pull-requests: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Necesario para obtener todos los tags | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
cache: 'gradle' | |
- name: Setup Git | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Cache Gradle packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | |
restore-keys: ${{ runner.os }}-gradle | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@v2 | |
with: | |
arguments: build | |
- name: Archive build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-artifacts | |
path: build/libs | |
publish: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Necesario para obtener todos los tags | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Download build artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: build-artifacts | |
path: build/libs | |
- name: Setup Git | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
- name: Determine version | |
id: determine_version | |
run: | | |
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
MAJOR=$(echo $LAST_TAG | cut -d. -f1) | |
MINOR=$(echo $LAST_TAG | cut -d. -f2) | |
PATCH=$(echo $LAST_TAG | cut -d. -f3) | |
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" | |
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT | |
echo "env=prod" >> $GITHUB_OUTPUT | |
- name: Display version | |
run: | | |
echo "Version: ${{ steps.determine_version.outputs.version }}" | |
echo "Environment: ${{ steps.determine_version.outputs.env }}" | |
- name: Publish to GitHub Packages | |
uses: gradle/gradle-build-action@v2 | |
with: | |
arguments: build publish | |
env: | |
VERSION: ${{ steps.determine_version.outputs.version }} | |
USERNAME: ${{ github.actor }} | |
TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
ENVIRONMENT: ${{ steps.determine_version.outputs.env }} | |
- name: Create and push tag(for master) | |
run: | | |
git tag v${{ steps.determine_version.outputs.version }} | |
git push origin v${{ steps.determine_version.outputs.version }} | |
- name: Create Release(for master) | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.determine_version.outputs.version }} | |
release_name: Release ${{ steps.determine_version.outputs.version }} | |
body: | | |
Changes in this Release | |
- Merged from develop to master | |
- PR: #${{ github.event.pull_request.number }} | |
draft: false | |
prerelease: false | |
cleanup-packages: | |
needs: publish | |
runs-on: ubuntu-latest | |
steps: | |
- name: Delete old packages | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Definir el nombre del paquete y el número de versiones a mantener | |
PACKAGE_NAME="dev.root101.commons" | |
VERSIONS_TO_KEEP_PROD=10 | |
VERSIONS_TO_KEEP_DEV=5 | |
# Función para eliminar versiones antiguas | |
delete_old_versions() { | |
local versions_to_keep=$1 | |
local version_filter=$2 | |
PACKAGE_VERSIONS=$(gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
/user/packages/maven/$PACKAGE_NAME/versions \ | |
--jq ".[] | select(.name | $version_filter) | .id") | |
echo "$PACKAGE_VERSIONS" | sort -rn | tail -n +$((versions_to_keep + 1)) | while read VERSION_ID; do | |
echo "Deleting version $VERSION_ID" | |
gh api \ | |
--method DELETE \ | |
-H "Accept: application/vnd.github+json" \ | |
/user/packages/maven/$PACKAGE_NAME/versions/$VERSION_ID | |
done | |
} | |
# Eliminar versiones antiguas de producción | |
if [[ "${{ github.base_ref }}" == "master" ]]; then | |
echo "Cleaning up production versions" | |
delete_old_versions $VERSIONS_TO_KEEP_PROD "test(\"^[0-9]+\\\\.[0-9]+\\\\.[0-9]+$\")" | |
fi | |
# Eliminar versiones antiguas de desarrollo | |
if [[ "${{ github.base_ref }}" == "develop" ]]; then | |
echo "Cleaning up development versions" | |
delete_old_versions $VERSIONS_TO_KEEP_DEV "contains(\"-SNAPSHOT\")" | |
fi |