Skip to content

Instantly share code, notes, and snippets.

@CristianMG
Created July 18, 2023 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CristianMG/b3f50e354e5007040bbf1eca64d671ba to your computer and use it in GitHub Desktop.
Save CristianMG/b3f50e354e5007040bbf1eca64d671ba to your computer and use it in GitHub Desktop.
Import artifacts to Github registry
import os
# Función para recorrer las carpetas y buscar archivos pom.xml
def buscar_pom_xml(directorio):
for root, dirs, files in os.walk(directorio):
print(f"Exploring dirs: {root}")
for file in files:
if file.endswith(".pom"):
print(f"Founded file pom.xml: {file}")
ruta_archivo_pom = os.path.join(root, file)
nombre_carpeta = os.path.dirname(ruta_archivo_pom)
archivo_aar = None
for archivo in os.listdir(nombre_carpeta):
if archivo.endswith('.aar'):
archivo_aar = os.path.join(nombre_carpeta, archivo)
print(f"Encontrado archivo .aar: {archivo}")
break
if archivo_aar:
comando = f"mvn org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file \
-DpomFile={ruta_archivo_pom} \
-Dfile={archivo_aar} \
-Durl= URL_GITHUB_REPOSITORY \
-DrepositoryId=github \
-Dtoken= GITHUB_TOKEN_PAT_ACCESS_REGISTRY "
print("Executing command:")
print(comando)
os.system(comando)
else:
print("Not found aar file .aar at the same folder as pom.xml")
# Llamada a la función principal
directorio_actual = os.getcwd()
print(f"Current directory: {directorio_actual}\n")
buscar_pom_xml(directorio_actual)
@CristianMG
Copy link
Author

CristianMG commented Jul 18, 2023

Required this in your home maven directory ~/.m2/settings.xml

<settings>
    <servers>
        <server>
        <id>github</id>
            <username>EMAIL</username>
            <password>PAT_TOKEN</password>
        </server>
    </servers>
</settings>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment