|
1 | | -name: Deploy to Maven Central |
| 1 | +name: Publicar a Maven Central |
2 | 2 |
|
3 | 3 | on: |
4 | | - workflow_dispatch: # Permite ejecutar manualmente desde GitHub Actions |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_notes: |
| 7 | + description: 'Notas de la versión' |
| 8 | + required: false |
| 9 | + default: 'Nueva versión de la biblioteca FiscalAPI' |
5 | 10 |
|
6 | 11 | jobs: |
7 | | - deploy: |
| 12 | + publish: |
8 | 13 | runs-on: ubuntu-latest |
9 | 14 | steps: |
10 | | - - name: Checkout code |
| 15 | + - name: Checkout del código |
11 | 16 | uses: actions/checkout@v3 |
| 17 | + with: |
| 18 | + ref: ${{ github.ref_name }} |
12 | 19 |
|
13 | | - - name: Set up Java |
| 20 | + - name: Configurar Java |
14 | 21 | uses: actions/setup-java@v3 |
15 | 22 | with: |
| 23 | + java-version: '8' |
16 | 24 | distribution: 'temurin' |
17 | | - java-version: '17' |
18 | | - server-id: central |
19 | | - server-username: MAVEN_USERNAME |
20 | | - server-password: MAVEN_PASSWORD |
21 | | - gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} |
22 | | - gpg-passphrase: MAVEN_GPG_PASSPHRASE |
23 | | - |
24 | | - - name: Extract version from POM |
| 25 | + cache: maven |
| 26 | + |
| 27 | + - name: Extraer versión del POM |
25 | 28 | id: get_version |
26 | | - run: echo "VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV |
| 29 | + run: | |
| 30 | + VERSION=$(grep -m 1 "<version>" pom.xml | sed 's/<version>//g' | sed 's/<\/version>//g' | xargs) |
| 31 | + echo "Versión extraída del POM: $VERSION" |
| 32 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 33 | +
|
| 34 | + - name: Configurar GPG |
| 35 | + run: | |
| 36 | + # Crear directorio para las claves GPG |
| 37 | + mkdir -p ~/.gnupg/ |
| 38 | + chmod 700 ~/.gnupg/ |
| 39 | + |
| 40 | + # Importar claves GPG |
| 41 | + echo "${{ secrets.GPG_PUBLIC_KEY }}" | gpg --import |
| 42 | + echo "${{ secrets.GPG_SECRET_KEY }}" | gpg --import --no-tty --batch --yes |
| 43 | + |
| 44 | + # Verificar que las claves se hayan importado correctamente |
| 45 | + gpg --list-secret-keys --keyid-format LONG |
27 | 46 |
|
28 | | - - name: Build and Publish |
29 | | - run: mvn clean deploy -P release |
| 47 | + - name: Verificar settings.xml |
| 48 | + run: | |
| 49 | + if [ -f "settings.xml" ]; then |
| 50 | + echo "El archivo settings.xml existe." |
| 51 | + else |
| 52 | + echo "Error: No se encontró el archivo settings.xml" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +
|
| 56 | + - name: Desplegar a Maven Central |
30 | 57 | env: |
31 | 58 | MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} |
32 | 59 | MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} |
33 | | - MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
34 | 60 | GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 61 | + run: | |
| 62 | + mvn clean deploy -P release --settings settings.xml -DskipTests=true |
35 | 63 |
|
36 | | - - name: Create GitHub Release |
| 64 | + - name: Crear GitHub Release |
| 65 | + if: success() |
37 | 66 | uses: softprops/action-gh-release@v1 |
38 | 67 | with: |
39 | | - tag_name: v${{ env.VERSION }} |
40 | | - name: Release v${{ env.VERSION }} |
41 | | - body: "New release v${{ env.VERSION }} deployed to Maven Central." |
| 68 | + tag_name: v${{ steps.get_version.outputs.version }} |
| 69 | + name: FiscalAPI ${{ steps.get_version.outputs.version }} |
| 70 | + body: ${{ github.event.inputs.release_notes }} |
42 | 71 | draft: false |
43 | 72 | prerelease: false |
| 73 | + files: | |
| 74 | + target/fiscalapi-${{ steps.get_version.outputs.version }}.jar |
| 75 | + target/fiscalapi-${{ steps.get_version.outputs.version }}-javadoc.jar |
| 76 | + target/fiscalapi-${{ steps.get_version.outputs.version }}-sources.jar |
| 77 | + env: |
| 78 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 79 | + |
| 80 | + - name: Notificar resultado |
| 81 | + if: always() |
| 82 | + run: | |
| 83 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 84 | + if [ "${{ job.status }}" == "success" ]; then |
| 85 | + echo "✅ Biblioteca publicada exitosamente en Maven Central" |
| 86 | + echo "La biblioteca debería estar disponible pronto en: https://central.sonatype.com/artifact/com.fiscalapi/fiscalapi/$VERSION" |
| 87 | + else |
| 88 | + echo "❌ Error al publicar la biblioteca" |
| 89 | + echo "Por favor, revisa los logs para más detalles." |
| 90 | + fi |
0 commit comments