Skip to content

Commit

Permalink
feat: orchestration support (#22)
Browse files Browse the repository at this point in the history
* feat: refining ci cd to rely on run orchestration; minor devrel feedback

* chore: updating examples for puya and react only for now

* chore: refreshing puya/react combinations - still draft

* chore: regen against latest beaker

* chore: adding tealscript artifacts

* chore: swapping to final prerelease branch

* chore: regen artifacts

* chore: prevent code-workspace file overwrite

* chore: regen examples

* chore: regen examples

* chore: regen examples

* chore: regen examples

* chore: adjust terminology

* chore: regen samples

* chore: regen examples

BREAKING CHANGE: Support for algokit-cli v2.0

* chore: patching ci

---------

Co-authored-by: Neil Campbell <[email protected]>
  • Loading branch information
aorumbayev and neilcampbell authored Mar 27, 2024
1 parent 8009a26 commit 4b08572
Show file tree
Hide file tree
Showing 460 changed files with 6,527 additions and 2,666 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/check-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
- name: Install algokit
run: pipx install algokit

- name: Run algokit localnet
run: algokit localnet start

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -45,7 +48,7 @@ jobs:
shell: bash
run: |
set -o pipefail
poetry run pytest --junitxml=pytest-junit.xml -n auto
poetry run pytest --junitxml=pytest-junit.xml -n 1
- name: Check generated templates have been reviewed
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ node_modules
# Ignore lock files in all directories and subdirectories under tests_generated
examples/*/**/package-lock.json
examples/*/**/poetry.lock
examples/**/smart_contracts/artifacts
examples/**/contracts/artifacts
examples/**/.algokit/sources

# playground folder for previewing templates
.playground/*
Expand Down
38 changes: 38 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run template using algokit (template prompts)",
"command": "algokit",
"args": [
"-v",
"init",
"--name",
".playground",
"--no-git",
"--UNSAFE-SECURITY-accept-template-url",
"--template-url",
"${workspaceFolder}",
"--template-url-ref",
"HEAD",
"--no-bootstrap"
],
"type": "shell",
"dependsOn": ["Cleanup .playground folder"],
"problemMatcher": []
},
{
"label": "Cleanup .playground folder",
"command": "rm",
"args": ["-rf", ".playground"],
"type": "shell",
"windows": {
"command": "./.vscode/clear.ps1"
},
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": []
}
]
}
21 changes: 18 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,38 @@ This repository is a template for creating new AlgoKit projects. It includes a b
## Pre-requisites

`poetry install` - Install the dependencies for the project.
`pipx install algokit` - Ensure cli is installed.

## Testing

Ensure localnet is running by executing `algokit localnet reset`.

```bash
poetry run pytest
poetry run pytest -n auto
```

This will regenerate the tests for default `starter` and `production` presets as well as default tests for `generators` available on the template.
This will regenerate the tests for default `starter` and `production` presets available on the template.

## Development

### Manual

```bash
poetry run copier copy . .playground/{some_dummy_folder_name} --vcs-ref=HEAD --trust
poetry run copier copy . .playground --vcs-ref=HEAD --trust
```

To generate a dummy project into the `.playground` folder. This is useful for testing the template to quickly preview the output of the template before testing via `pytest`.

### Using VSCode Tasks

In VSCode IDE, you can find the tasks in the `.vscode/tasks.json` file. To run them:

1. Open the command palette (`Cmd+Shift+P` on macOS, `Ctrl+Shift+P` on Windows/Linux) and type `> Run Task`
2. Select the task you want to run
3. It will be generated for you under the .playground folder

To cleanup the .playground folder run dedicated cleanup task.

## Contributing

### Commits
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

---

This full-stack template provides both a baseline React web app and a production-ready baseline for developing and deploying `Puya`, `TealScript` and `Beaker` smart contracts. It's suitable for developing and integrating with any [ARC32](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0032.md) compliant Algorand smart contracts.
This full-stack template provides both a baseline React web app and a production-ready baseline for developing and deploying `Algorand Python`, `TealScript` and `Beaker` smart contracts. It's suitable for developing and integrating with any [ARC32](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0032.md) compliant Algorand smart contracts.

To use this template, [install AlgoKit](https://github.com/algorandfoundation/algokit-cli#readme) and then either pass in `-t fullstack` to `algokit init` or select the relevant template interactively during `algokit init`.

Expand All @@ -25,9 +25,9 @@ This template supports a multitude of features for developing full-stack applica

And the following backend templates:

- [algokit-puya-template](https://github.com/algorandfoundation/algokit-puya-template) - An official starter for developing and deploying Puya smart contracts.
- [algokit-python-template](https://github.com/algorandfoundation/algokit-python-template) - An official starter for developing and deploying Algorand Python smart contracts.
- [algokit-tealscript-template](https://github.com/algorand-devrel/tealscript-algokit-template) - An official starter for developing and deploying TealScript smart contracts.
- [algokit-beaker-default-template](https://github.com/algorandfoundation/algokit-beaker-default-template) - A production-ready baseline for developing and deploying Beaker smart contracts. Please note this template option is to be deprecated after `puya` is ready for production use.
- [algokit-beaker-default-template](https://github.com/algorandfoundation/algokit-beaker-default-template) - A production-ready baseline for developing and deploying Beaker smart contracts.

### Frontend

Expand All @@ -44,7 +44,7 @@ And the following backend templates:
### Backend

- Compilation of multiple `puya`, `tealscript`, `beaker` contracts to a predictable folder location and file layout where they can be deployed.
- Compilation of multiple `python`, `tealscript`, `beaker` contracts to a predictable folder location and file layout where they can be deployed.
- Deploy-time immutability and permanence control.
- [Poetry](https://python-poetry.org/) for Python dependency management and virtual environment management.
- Linting via [Ruff](https://github.com/charliermarsh/ruff) or [Flake8](https://flake8.pycqa.org/en/latest/).
Expand Down
97 changes: 33 additions & 64 deletions copier.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,41 @@ _subdirectory: ./template_content

_tasks:
- "echo '==== Checking compatibility with the cli ==='"
- '{{ python_path if python_path else _copier_python }} check_algokit_version.py'
- '{{ python_path if python_path else _copier_python }} pre_init.py'

- "echo '==== 1/4 - Initializing base template ===='"
- 'algokit init -t base -n . --no-git --no-ide --no-bootstrap -a include_readme false -a include_algokit_toml false'
- 'algokit init -t base -n . --no-git --no-ide --no-bootstrap --no-workspace
-a include_readme "no"
-a include_algokit_toml "no"
-a include_vscode_code_workspace "no"
-a include_github_workflow_template "no"'
# CLI auto sets include_github_workflow_template to false for any blessed template
# however still defining explicitly for clarity

- "echo '==== 2/4 - Initializing frontend template ===='"
- 'algokit init -t react -n {{ project_name }}-app --no-git --no-ide --no-bootstrap
- 'algokit init -t react -n {{ project_name }}-frontend --no-git --no-ide --no-bootstrap
-a author_email "{{ author_email }}"
-a author_name "{{ author_name }}"
-a preset_name {{ preset_name }}
-a preset_name "{{ preset_name }}"
-a ide_vscode "{{ ide_vscode }}"
-a use_github_actions "no"'
-a ide_jetbrains "{{ ide_jetbrains }}"
-a cloud_provider "{{ cloud_provider }}"
-a use_github_actions "{{ use_github_actions }}"'

- "echo '==== 3/4 - Initializing backend template ===='"
- 'algokit init -t {{ contract_template }} -n {{ project_name }}-contracts --no-git --no-ide --no-bootstrap
-a author_email "{{ author_email }}"
-a author_name "{{ author_name }}"
-a preset_name {{ preset_name }}
-a contract_name {{ contract_name }}
-a deployment_language {{ deployment_language }}
-a preset_name "{{ preset_name }}"
-a contract_name "{{ contract_name }}"
-a deployment_language "{{ deployment_language }}"
-a ide_vscode "{{ ide_vscode }}"
-a use_github_actions "no"
-a ide_jetbrains "{{ ide_jetbrains }}"
-a use_github_actions "{{ use_github_actions }}"
-a use_pre_commit "no"'

- "echo '==== 4/4 - Finalizing setup ===='"
- '{{ python_path if python_path else _copier_python }} inject.py "./projects/{{ project_name }}-contracts" "./projects/{{ project_name }}-app"'
- '{{ python_path if python_path else _copier_python }} post_init.py "./projects/{{ project_name }}-contracts" "./projects/{{ project_name }}-frontend"'
# _copier_python above is used for backwards compatibility with versions < v1.11.3 of the algokit cli

# questions
Expand All @@ -36,16 +45,16 @@ contract_template:
help: Choose the contract template.
when: false
choices:
Puya: puya
Python: python
TealScript: tealscript
Beaker: beaker
default: puya
default: python

# project_name should never get prompted, AlgoKit should always pass it by convention
project_name:
type: str
help: Name for this project.
placeholder: 'algorand-app'
placeholder: 'algorand-frontend'
default: 'myproject'

# Auto determined by algokit-cli from v1.11.3 to allow execution of python script
Expand All @@ -67,11 +76,17 @@ preset_name:
contract_name:
type: str
help: Name of the default smart contract app.
placeholder: 'hello_world'
default: 'hello_world'
placeholder: '{{ "HelloWorld" if contract_template == "tealscript" else "hello_world" }}'
default: '{{ "HelloWorld" if contract_template == "tealscript" else "hello_world" }}'
validator: >-
{% if not (contract_name | regex_search('^[a-z]+(?:_[a-z]+)*$')) %}
contract_name must be formatted in snake case.
{% if contract_template == 'tealscript' %}
{% if not (contract_name | regex_search('^[A-Z][a-zA-Z]*(?:[A-Z][a-zA-Z]*)*$')) %}
contract_name must be formatted in PascalCase.
{% endif %}
{% else %}
{% if not (contract_name | regex_search('^[a-z]+(?:_[a-z]+)*$')) %}
contract_name must be formatted in snake case.
{% endif %}
{% endif %}
author_name:
Expand Down Expand Up @@ -107,62 +122,16 @@ ide_jetbrains:
when: "{{ preset_name == 'custom' }}"
default: no

use_python_pytest:
type: bool
when: "{{ deployment_language == 'python' and preset_name == 'custom' }}"
help: Do you want to include unit tests for smart contracts (via pytest)?
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"

python_linter:
type: str
help: Do you want to use a Python linter on smart contracts codebase?
when: "{{ preset_name == 'custom' }}"
choices:
Ruff: 'ruff'
Flake8: 'flake8'
No thanks: 'none'
default: "{{ 'ruff' if preset_name == 'production' else 'none' }}"

use_python_black:
type: bool
help: Do you want to use a Python formatter (via Black) on smart contracts codebase?
when: "{{ preset_name == 'custom' }}"
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"

use_python_mypy:
type: bool
help: Do you want to use a Python type checker (via mypy) on smart contracts codebase?
when: "{{ preset_name == 'custom' }}"
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"

use_python_pip_audit:
type: bool
help: Do you want to include Python dependency vulnerability scanning for smart contracts (via pip-audit)?
when: "{{ preset_name == 'custom' }}"
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"

use_dispenser:
type: bool
when: "{{ preset_name == 'custom' }}"
help: Do you want to fund your deployment account using an optional dispenser account?
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"

use_github_actions:
type: bool
help: Do you want to include Github Actions workflows for build and testnet deployment?
when: "{{ preset_name == 'custom' }}"
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"

use_pre_commit:
type: bool
when: "{{ preset_name == 'custom' }}"
help: Do you want to include pre-commit for linting, type checking and formatting?
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"

cloud_provider:
type: str
help: Pick your website hosting provider for continuous delivery
when: "{{ use_github_actions != false and preset_name == 'custom' }}"
when: '{{ use_github_actions != false }}'
choices:
Netlify: 'netlify'
Vercel: 'vercel'
Expand Down
5 changes: 4 additions & 1 deletion examples/production_beaker_react/.algokit.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[algokit]
min_version = "v1.12.0"
min_version = "v2.0.0"

[project]
type = 'workspace'
projects_root_path = 'projects'

[project.run]
build = ['production_beaker_react-contracts', 'production_beaker_react-frontend']
1 change: 1 addition & 0 deletions examples/production_beaker_react/.copier-answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ _commit: <commit>
_src_path: <src>
author_email: None
author_name: None
cloud_provider: netlify
contract_name: hello_world
deployment_language: python
preset_name: production
Expand Down
4 changes: 2 additions & 2 deletions examples/production_beaker_react/.devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"label": "vite"
}
},
"postCreateCommand": "pipx install algokit",
"postStartCommand": "algokit localnet start && echo 'Run algokit init in terminal to get started with Algorand development 🚀'"
"postCreateCommand": "mkdir -p ~/.config/algokit && pipx install algokit && sudo chown -R codespace:codespace ~/.config/algokit",
"postStartCommand": "for i in {1..5}; do algokit localnet status > /dev/null 2>&1 && break || sleep 30; algokit localnet reset; done"
}

This file was deleted.

Loading

0 comments on commit 4b08572

Please sign in to comment.