Saltar a contenido

Usando GitHub Actions para actualizar tu Bot

Con GitHub Actions, es posible realizar actualizaciones, implementaciones y lanzamientos automáticos para Maestro sin procesos manuales.

Para obtener más información, visita nuestro repositorio.

Para leer más sobre GitHub Actions, visita la documentación oficial.

Configurando el proyecto

Primero, debes crear una carpeta llamada .github en tu proyecto, y dentro crear otra carpeta llamada workflows.

La estructura de carpetas debería verse así:

.
└── .github
  └── workflows
...

Para leer más sobre cómo crear flujos de trabajo en GitHub Actions, visita la documentación.

Crea tu primer flujo de trabajo

El primer flujo de trabajo que crearemos es simple: cuando ocurra un push en la rama main, activaremos una acción para actualizar el bot en Maestro.

Important

En este caso, debe haber un `Bot` creado previamente en Maestro.
Para obtener más información sobre los `Bots`, visita la página de [documentación](https://documentation.botcity.dev/maestro/features/bots){target="_blank"}.

Capturando el evento "push" en main

Crea un archivo llamado update_bot.yml dentro de la carpeta workflows.

Al principio de este archivo, agrega las siguientes líneas:

name: Update the latest version of Bot in Maestro.

on:
  push:
    branches:
      - main

Generando el Bot.

En esta etapa, solo necesitamos un requisito previo:

  • Un archivo .sh para generar el Bot.

Con este archivo en el proyecto, podemos continuar con el ejemplo.

jobs:
  update-latest:
    name: Update the latest version bot on BotCity Maestro.
    #  Running the latest version of Ubuntu.
    runs-on: ubuntu-latest
    steps:
      # Checking out the project.
      - uses: actions/checkout@v3
      # Implemented executable permission to `.sh`
      - name: Get permission to build.
        run: chmod +x build.sh
      # Execute to build.
      - name: Execute to build.
        run: ./build.sh
jobs:
  update-latest:
    name: Update the latest version bot on BotCity Maestro.
    #  Running the latest version of Ubuntu.
    runs-on: ubuntu-latest
    steps:
      # Install Java
      - uses: actions/setup-java@v3
      # Checking out the project.
      - uses: actions/checkout@v3
      # Implemented executable permission to `.sh`
      - name: Get permission to build.
        run: chmod +x build.sh
      # Execute to build.
      - name: Execute to build.
        run: ./build.sh
jobs:
  update-latest:
    name: Update the latest version bot on BotCity Maestro.
    #  Running the latest version of Ubuntu.
    runs-on: ubuntu-latest
    steps:
      # Checking out the project.
      - uses: actions/checkout@v3
      # Implemented executable permission to `.sh`
      - name: Get permission to build.
        run: chmod +x build.sh
      # Execute to build.
      - name: Execute to build.
        run: ./build.sh
jobs:
  update-latest:
    name: Update the latest version bot on BotCity Maestro.
    #  Running the latest version of Ubuntu.
    runs-on: ubuntu-latest
    steps:
      # Checking out the project.
      - uses: actions/checkout@v3
      # Implemented executable permission to `.sh`
      - name: Get permission to build.
        run: chmod +x build.sh
      # Execute to build.
      - name: Execute to build.
        run: ./build.sh

Important

Tu `Bot` puede requerir más pasos para ser ejecutados. Dependerá de cada proyecto.

Usando una acción

Después de ejecutar lo necesario para generar el Bot, es hora de usar la acción para actualizar en Maestro.

      - name: Using a Botcity action.
        # Using the v1.0.0 version of botcity-action-bots
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          # Use the update function.
          update: true
          # Bot Id in Maestro.
          botId: 'example'
          # Technology utilized in bot
          technology: 'python'
          # Path from the root of the project where the generated .zip/.jar will be.
          botPath: './bot.zip'
        env:
          # These secrets must be configured in your repository.
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}
      - name: Using a Botcity action.
        # Using the v1.0.0 version of botcity-action-bots
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          # Use the update function.
          update: true
          # Bot Id in Maestro.
          botId: 'example'
          # Technology utilized in bot
          technology: 'java'
          # Path from the root of the project where the generated .zip/.jar will be.
          botPath: './dist/bot-jar-with-dependencies.jar'
        env:
          # These secrets must be configured in your repository.
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}
      - name: Using a Botcity action.
        # Using the v1.0.0 version of botcity-action-bots
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          # Use the update function.
          update: true
          # Bot Id in Maestro.
          botId: 'example'
          # Technology utilized in bot
          technology: 'javascript'
          # Path from the root of the project where the generated .zip/.jar will be.
          botPath: './bot.zip'
        env:
          # These secrets must be configured in your repository.
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}
      - name: Using a Botcity action.
        # Using the v1.0.0 version of botcity-action-bots
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          # Use the update function.
          update: true
          # Bot Id in Maestro.
          botId: 'example'
          # Technology utilized in bot
          technology: 'typescript'
          # Path from the root of the project where the generated .zip/.jar will be.
          botPath: './bot.zip'
        env:
          # These secrets must be configured in your repository.
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}

Warning

Siempre configura tus credenciales en los secretos del repositorio por razones de seguridad. No se recomienda pasar esta información directamente. Para obtener más información sobre los secretos, visita la documentación.

Ejecuta un push en la rama main, y el resultado será este:

update

Archivo completo

name: Update the latest version of Bot in Maestro.

on:
  push:
    branches:
      - main
jobs:
  update-latest:
    name: Update the latest version bot on BotCity Maestro.
    #  Running the latest version of Ubuntu.
    runs-on: ubuntu-latest
    steps:
      # Checking out the project.
      - uses: actions/checkout@v3
      # Implemented executable permission to `.sh`
      - name: Get permission to build.
        run: chmod +x build.sh
      # Execute to build.
      - name: Execute to build.
        run: ./build.sh
      - name: Using a Botcity action.
        # Using the v1.0.0 version of botcity-action-bots
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          # Use the update function.
          update: true
          # Bot Id in Maestro.
          botId: 'example'
          # Technology utilized in bot
          technology: 'python'
          # Path from the root of the project where the generated .zip/.jar will be.
          botPath: './bot.zip'
        env:
          # These secrets must be configured in your repository.
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}
name: Update the latest version of Bot in Maestro.

on:
  push:
    branches:
      - main
jobs:
  update-latest:
    name: Update the latest version bot on BotCity Maestro.
    #  Running the latest version of Ubuntu.
    runs-on: ubuntu-latest
    steps:
      # Install Java
      - uses: actions/setup-java@v3
      # Checking out the project.
      - uses: actions/checkout@v3
      # Implemented executable permission to `.sh`
      - name: Get permission to build.
        run: chmod +x build.sh
      # Execute to build.
      - name: Execute to build.
        run: ./build.sh
      - name: Using a Botcity action.
        # Using the v1.0.0 version of botcity-action-bots
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          # Use the update function.
          update: true
          # Bot Id in Maestro.
          botId: 'example'
          # Technology utilized in bot
          technology: 'java'
          # Path from the root of the project where the generated .zip/.jar will be.
          botPath: './dist/bot-jar-with-dependecies.jar'
        env:
          # These secrets must be configured in your repository.
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}
name: Update the latest version of Bot in Maestro.

on:
  push:
    branches:
      - main
jobs:
  update-latest:
    name: Update the latest version bot on BotCity Maestro.
    #  Running the latest version of Ubuntu.
    runs-on: ubuntu-latest
    steps:
      # Checking out the project.
      - uses: actions/checkout@v3
      # Implemented executable permission to `.sh`
      - name: Get permission to build.
        run: chmod +x build.sh
      # Execute to build.
      - name: Execute to build.
        run: ./build.sh
      - name: Using a Botcity action.
        # Using the v1.0.0 version of botcity-action-bots
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          # Use the update function.
          update: true
          # Bot Id in Maestro.
          botId: 'example'
          # Technology utilized in bot
          technology: 'javascript'
          # Path from the root of the project where the generated .zip/.jar will be.
          botPath: './bot.zip'
        env:
          # These secrets must be configured in your repository.
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}
name: Update the latest version of Bot in Maestro.

on:
  push:
    branches:
      - main
jobs:
  update-latest:
    name: Update the latest version bot on BotCity Maestro.
    #  Running the latest version of Ubuntu.
    runs-on: ubuntu-latest
    steps:
      # Checking out the project.
      - uses: actions/checkout@v3
      # Implemented executable permission to `.sh`
      - name: Get permission to build.
        run: chmod +x build.sh
      # Execute to build.
      - name: Execute to build.
        run: ./build.sh
      - name: Using a Botcity action.
        # Using the v1.0.0 version of botcity-action-bots
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          # Use the update function.
          update: true
          # Bot Id in Maestro.
          botId: 'example'
          # Technology utilized in bot
          technology: 'typescript'
          # Path from the root of the project where the generated .zip/.jar will be.
          botPath: './bot.zip'
        env:
          # These secrets must be configured in your repository.
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}

Creando un flujo de trabajo avanzado para implementar y lanzar tu Bot.

Aquí las cosas comienzan a ponerse más interesantes. Puede haber mil formas de hacerlo, pero lo que se demostrará será un ejemplo.

Aclaremos lo que queremos lograr con este flujo de trabajo:

  • Se debe realizar un lanzamiento en GitHub.
  • Con el lanzamiento, debe haber la creación de una etiqueta.
  • El implementación/lanzamiento se ejecutará en Maestro.

Para saber cómo crear un lanzamiento.

Capturando el evento de publicación de lanzamiento

name: Deploy and Release in from GitHub release

on:
  # Capturing the release publishing event.
  release:
    types: [ published ]

Important

Hay otros eventos interesantes que GitHub activa y que pueden ayudarte. Para obtener más información, visita la documentación.

Construyendo tu bot

jobs:
  deploy-and-release:
    name: Deploy and release in BotCity.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Get permission to build.
        run: chmod +x build.sh
      - name: Execute to build.
        run: ./build.sh
jobs:
  deploy-and-release:
    name: Deploy and release in BotCity.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-java@v3
      - uses: actions/checkout@v3
      - name: Get permission to build.
        run: chmod +x build.sh
      - name: Execute to build.
        run: ./build.sh
jobs:
  deploy-and-release:
    name: Deploy and release in BotCity.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Get permission to build.
        run: chmod +x build.sh
      - name: Execute to build.
        run: ./build.sh
jobs:
  deploy-and-release:
    name: Deploy and release in BotCity.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Get permission to build.
        run: chmod +x build.sh
      - name: Execute to build.
        run: ./build.sh

Usando la acción

Important

En este caso, es importante destacar el uso de la variable proporcionada por GitHub para hacer que la versión del lanzamiento sea dinámica.

      - name: Botcity action
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          deploy: true
          release: true
          # Use tag_name to release.
          version: ${{ github.event.release.tag_name }}
          botId: 'example'
          technology: 'python'
          botPath: './bot.zip'
        env:
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}
      - name: Botcity action
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          deploy: true
          release: true
          # Use tag_name to release.
          version: ${{ github.event.release.tag_name }}
          botId: 'example'
          technology: 'java'
          botPath: './dist/bot-jar-with-dependencies.jar'
        env:
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}
      - name: Botcity action
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          deploy: true
          release: true
          # Use tag_name to release.
          version: ${{ github.event.release.tag_name }}
          botId: 'example'
          technology: 'javascript'
          botPath: './bot.zip'
        env:
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}
      - name: Botcity action
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          deploy: true
          release: true
          # Use tag_name to release.
          version: ${{ github.event.release.tag_name }}
          botId: 'example'
          technology: 'typescript'
          botPath: './bot.zip'
        env:
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}

Ejecuta la publicación del lanzamiento y el resultado será este: deploy_and_release

Archivo completo

name: Deploy and Release in from GitHub release

on:
  # Capturing the release publishing event.
  release:
    types: [ published ]

jobs:
  deploy-and-release:
    name: Deploy and release in BotCity.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Get permission to build.
        run: chmod +x build.sh
      - name: Execute to build.
        run: ./build.sh
      - name: Botcity action
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          deploy: true
          release: true
          # Use tag_name to release.
          version: ${{ github.event.release.tag_name }}
          botId: 'example'
          technology: 'python'
          botPath: './bot.zip'
        env:
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}
name: Deploy and Release in from GitHub release

on:
  # Capturing the release publishing event.
  release:
    types: [ published ]

jobs:
  deploy-and-release:
    name: Deploy and release in BotCity.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-java@v3
      - uses: actions/checkout@v3
      - name: Get permission to build.
        run: chmod +x build.sh
      - name: Execute to build.
        run: ./build.sh
      - name: Botcity action
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          deploy: true
          release: true
          # Use tag_name to release.
          version: ${{ github.event.release.tag_name }}
          botId: 'example'
          technology: 'java'
          botPath: './dist/bot-jar-with-dependencies.jar'
        env:
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}
name: Deploy and Release in from GitHub release

on:
  # Capturing the release publishing event.
  release:
    types: [ published ]

jobs:
  deploy-and-release:
    name: Deploy and release in BotCity.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Get permission to build.
        run: chmod +x build.sh
      - name: Execute to build.
        run: ./build.sh
      - name: Botcity action
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          deploy: true
          release: true
          # Use tag_name to release.
          version: ${{ github.event.release.tag_name }}
          botId: 'example'
          technology: 'javascript'
          botPath: './bot.zip'
        env:
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}
name: Deploy and Release in from GitHub release

on:
  # Capturing the release publishing event.
  release:
    types: [ published ]

jobs:
  deploy-and-release:
    name: Deploy and release in BotCity.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Get permission to build.
        run: chmod +x build.sh
      - name: Execute to build.
        run: ./build.sh
      - name: Botcity action
        uses: botcity-dev/botcity-action-bots@v1.0.0
        with:
          deploy: true
          release: true
          # Use tag_name to release.
          version: ${{ github.event.release.tag_name }}
          botId: 'example'
          technology: 'typescript'
          botPath: './bot.zip'
        env:
          LOGIN: ${{ secrets.LOGIN }}
          SERVER: ${{ secrets.SERVER }}
          KEY: ${{ secrets.KEY }}