Github Actions - How to use?

 What is GitHub Actions? 

                GitHub Actions is an automated workflow and continuous integration/continuous deployment (CI/CD) platform provided by GitHub. It allows developers to define and automate various tasks such as building, testing, and deploying code directly within their GitHub repositories. Users can create custom workflows using YAML configuration files to streamline their software development processes and improve collaboration among development teams.

How this help me ?

            My scalper app, written in Python and PyQt6, requires a Windows virtual machine to build a Windows executable. However, I encountered an issue yesterday when my virtual machine ran out of space and became unresponsive. Unable to create another virtual machine, I began exploring alternatives and discovered that GitHub Actions could provide a solution.


            With GitHub Actions, I set up a workflow that automates the build process. When I push changes to the main branch, the workflow initiates, runs the necessary job, and then uploads the artifact seamlessly. It's a straightforward and efficient solution to my build needs.

Steps & Example: 

  • Github repo create a workflow build file 
         .github/workflows/build.yml    

        











Name: Build Windows Executable - This is the name of your GitHub Actions workflow.

on: This section specifies when the workflow should be triggered.

push: The workflow will be triggered when there is a push event to the repository.
branches: It specifies the branches on which the workflow should run. In this case, it's set to main.
jobs: The workflow consists of a single job named build.

runs-on: ${{ matrix.os }}: This sets the operating system for the job based on the matrix defined later. In this case, it's set to run on the latest Windows.

strategy: This section defines the build matrix for the job. It allows you to run the job on different configurations, but in this case, it's just targeting Windows.

steps: These are the individual tasks that the workflow will perform:

actions/checkout@v2: This step checks out the code from your repository so that subsequent steps can access it.

actions/setup-python@v2: This step sets up a Python environment. It specifies that Python version 3.11 should be used.

run: pip install -r requirement.txt pyinstaller: This step installs the Python dependencies listed in requirement.txt and PyInstaller.

run: pyinstaller --noconsole RichDotinScalperApp.py: This step uses PyInstaller to create a Windows executable for your Python application. The --noconsole flag indicates that it should be a GUI application without a console window.

run: ./dist/RichDotinScalperApp/RichDotinScalperApp: This step optionally attempts to run the newly created executable to verify that it works, assuming it doesn't require user interaction.

run: |: This is a multi-line script that copies some files into the directory where the executable was created. It copies sn_expiry_v23.db and config.ini into the dist/RichDotinScalperApp directory.

actions/upload-artifact@v2: Finally, this step uploads the contents of the dist/RichDotinScalperApp directory as an artifact with the name RichDotinScalperApp-win. This makes the executable and associated files available for later stages or for download as part of the workflow run.


  • I just made the small changes and pushed it, you can see the workflow job created and in queue. 

  • We can also see the job logs and details where it failed like that details.



  • Once the job is complete you can see the executable uploaded as artefact we can download the same and distribute or release. 





Thanks for reading, 

SN







    




No comments:

Post a Comment