Skip to content

daniel-makerx/cicd-pytest

Repository files navigation

cicd-py2

This project has been generated using AlgoKit. See below for default getting started instructions.

Setup

Initial setup

  1. Clone this repository locally
  2. Install pre-requisites:
    • Install AlgoKit - Link: Ensure you can execute algokit --version.
    • Bootstrap your local environment; run algokit bootstrap all within this folder, which will:
      • Install Poetry - Link: The minimum required version is 1.2. Ensure you can execute poetry -V and get 1.2+
      • Run poetry install in the root directory, which will set up a .venv folder with a Python virtual environment and also install all Python dependencies
      • Copy .env.template to .env
  3. Open the project and start debugging / developing via:
    • VS Code
      1. Open the repository root in VS Code
      2. Install recommended extensions
      3. Hit F5 (or whatever you have debug mapped to) and it should start running with breakpoint debugging.

        Note If using Windows: Before running for the first time you will need to select the Python Interpreter.

        1. Open the command palette (Ctrl/Cmd + Shift + P)
        2. Search for Python: Select Interpreter
        3. Select ./.venv/Scripts/python.exe
    • IDEA (e.g. PyCharm)
      1. Open the repository root in the IDE
      2. It should automatically detect it's a Poetry project and set up a Python interpreter and virtual environment.
      3. Hit Shift+F9 (or whatever you have debug mapped to) and it should start running with breakpoint debugging.
    • Other
      1. Open the repository root in your text editor of choice
      2. In a terminal run poetry shell
      3. Run python -m smart_contracts through your debugger of choice

Subsequently

  1. If you update to the latest source code and there are new dependencies you will need to run algokit bootstrap all again
  2. Follow step 3 above

Continuous Integration

This project uses GitHub actions to define CI/CD workflows, see the .github/workflows folder for details.

Setting up GitHub for CI/CD workflow and Testnet deployment

  1. Build and commit smart contract artifacts for output stability
  2. Decide what values you want to use for the allow_update and allow_delete parameters specified in config.py When deploying to LocalNet these values are both set to True for convenience. But for non-LocalNet networks they are more conservative and use False These default values will allow the smart contract to be deployed initially, but will not allow the app to be updated or deleted if is changed. To help you decide it may be helpful to read the following AlgoKit documentation
  3. Create a Github environment named Test
  4. Create or obtain the mnemonic for an Algorand account for use on testnet to deploy apps, referred to as the Deployer account
  5. Store the mnemonic as a secret DEPLOYER_MNEMONIC in the Test environment created in step 2
  6. The account used to deploy the smart contract will require enough funds to create the app, and also fund it. There are two approaches available here:
    • Either, ensure the account is funded outside of CI/CD.

      In Testnet, funds can be obtained by using the Algorand testnet dispenser The funds can either be transferred to the Deployer account

    • Or, fund the account as part of the CI/CD process by using the DISPENSER_MNEMONIC secret. This secret can be defined in GitHub and will then be used to fund the Deployer account before deploying.

For pull requests against this repository the following checks are performed by GitHub Actions:

  • Python dependencies using pip-audit
  • Formatting using Black
  • Linting using Ruff
  • Types using MyPy
  • Python tests are executed
  • Smart contract artifacts are built
  • Smart contract artifacts are checked for output stability.
  • Smart contract is deployed to a AlgoKit LocalNet instance

Continuous Deployment

After merging the following actions are performed

  • Continuous Integration checks are re-run
  • Smart contract is deployed to testnet using algonode

Tools

This project makes use of Python to build Algorand smart contracts. The following tools are in use:

  • Algorand - Layer 1 Blockchain; Developer portal, Why Algorand?

  • AlgoKit - One-stop shop tool for developers building on the Algorand network; docs, intro tutorial

  • Beaker - Smart contract development framework for PyTeal; docs, examples

  • PyTEAL - Python language binding for Algorand smart contracts; docs

  • AlgoKit Utils - A set of core Algorand utilities that make it easier to build solutions on Algorand.

  • Poetry: Python packaging and dependency management.- Black: A Python code formatter.

  • Ruff: An extremely fast Python linter.

  • mypy: Static type checker.It has also been configured to have a productive dev experience out of the box in VS Code, see the .vscode folder.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages