pt-br: link
You’ve heard about GitHub Actions, right? If you haven’t, take advantage and explore the documentation about it at this link.
And to take advantage of the practicality of performing different actions in projects from this functionality, we created a GitHub Actions function to automate the bot’s update, called BotCity Actions, and you can find it available in this repository.
Why use BotCity Actions?
Whenever we can automate a process to make our day-to-day life easier, it makes sense to learn how to do it and understand if it makes sense in our context and need. So, suppose you have a continuous development process for your bots. Why not make your day-to-day life more manageable and automate beyond the business and product processes? Like the deployment and update of your releases as well.
How does BotCity Actions work?
Our function performs updates, deploys, and releases automatically to our orchestrator, BotCity Maestro, without manual implementations. Also, if you need to become familiar with the BotCity Maestro API for better use, please consult our documentation at this link.
Applying BotCity Actions in your project
Follow the step-by-step below. In the example, we are considering projects built with the Python language. However, feel free to use other languages. Our documentation contains examples for configuring projects in Java, JavaScript, and TypeScript.
[0] Configure your project
As a first step, you need to add a folder structure to your project. Create a folder with the exact name .github
at the root of your project. Inside that folder, create another one with the specific name workflows
.
This specification comes directly from GitHub, and this is how it will interpret where the functions are. For further clarification, remember to consult the documentation.
[1] Creating the first workflow
At this point, we’re assuming you already have bots developed. But if you want help, look at this link in our documentation. We have a very interesting tutorial on how to create a bot with our Open Source frameworks.
Still, we point out that you can use bots built with other technologies in our orchestrator, for example, Java, JavaScript, Selenium, and bash scripts, among many others.
One of the events that we can consider in our action would be the push on the main
branch. It means that whenever there is a change in the main
branch, you want a new deployment to BotCity Maestro to update the bot. It works like this if you are considering Git Flow rules and best practices, where the main
branch is the production branch.
In this step, we will create the update_bot.yml
file inside the workflows folder. And you should add the code below to take into account the changes explained above in the push event on the main
branch:
name: Update the latest version bot on BotCity Maestro.
on:
push:
branches:
- main
[2] Generating the bot by the BotCity Actions function
To know what you need to add to the function, it is also necessary to understand what is required to deploy your bot.
For example, considering that you developed your automation with our Open Source framework, we need to complete the following prerequisite: generate a zipped file with the bot’s code and dependencies, which we can create by executing the script: ./build.sh
or ./build.bat
, depending on the operating system. This script is at the project’s root, constructed from our desktop or web framework template.
So, we need to add the following actions to our function:
- Run in an environment (which, in this case, we chose Ubuntu due to its ease and speed, however, you can analyze your specific circumstance and understand if there are essential dependencies to consider and, if necessary, run in a Windows or MacOS environment, for example);
- Permit the execution of the
build.sh
file; - Run the
./build.sh
command. With these new actions, ourupdate_bot.yml
file will look like this:
name: Update the latest version bot on BotCity 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
[3] Using the function
The sequence of steps we’ve added to the update_bot.yml
file so far has been to define an environment to build in and create the zipped file we’ll upload in Maestro. However, now we need to configure the steps for the function to be used.
In this case, we add some important data for successful deployment. They are botId, technology (where you must inform the language used in your bot and, in our example, we consider Python), and botPath (location at the project’s root where the zipped file will be uploaded to our orchestrator’s platform).
name: Update the latest version bot on BotCity 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 }}
Notice that we added some environment variables like LOGIN, SERVER, and KEY. These are essential secrets for you to be able to use BotCity Maestro. So remember to set these keys securely in your repository.
Where can I find more tips?
You can access the guide we created in our documentation with many more tips and guidance on using BotCity Actions, including creating releases and much more.
Also, remember to join our community to share your Open Source projects and get your questions answered with others. It will be exciting to learn from your experience.
Top comments (0)