Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: orchestration support #61

Merged
merged 8 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/check-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
run: pipx install poetry

- name: Install algokit
run: pipx install algokit
# TODO: restore to algokit prior to release
run: pipx install git+https://github.com/algorandfoundation/algokit-cli@feat/orchestration-linking

- name: Set up Python 3.12
uses: actions/setup-python@v5
Expand Down
29 changes: 18 additions & 11 deletions copier.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
_subdirectory: template_content
_templates_suffix: ".jinja"

use_workspace:
type: bool
when: false # never prompted to user explicitly, instead expect cli to auto fill (supported cli versions > v1.13.x)
help: Automatically filled by AlgoKit CLI (>1.13.x) - passes the --workspace/--no-workspace flag's value, can be used to reason whether this template is currently being instantiated as part of a workspace or not.
default: no

# questions
# 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"

contract_name:
type: str
help: Name of the default smart contract app.
placeholder: "hello_world"
default: "hello_world"
validator: >-
{% if not (contract_name | regex_search('^[a-z]+(?:_[a-z]+)*$')) %}
contract_name must be formatted in snake case.
{% endif %}

author_name:
type: str
help: Package author name
placeholder: "Your Name"
default: "Your Name"

author_email:
type: str
help: Package author email
placeholder: "your@email.tld"
default: "your@email.tld"

contract_name:
type: str
help: Name of the default smart contract app.
placeholder: "hello_world"
default: "hello_world"
validator: >-
{% if not (contract_name | regex_search('^[a-z]+(?:_[a-z]+)*$')) %}
contract_name must be formatted in snake case.
{% endif %}

preset_name:
type: str
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
[algokit]
min_version = "v1.10.0"
min_version = "v1.12.1"

[deploy]
[generate.smart_contract]
description = "Adds new smart contract to existing project"
path = ".algokit/generators/create_contract"

[project]
type = 'contract'
name = 'production_beaker_smart_contract_python'
artifacts = 'smart_contracts/artifacts'

[project.deploy]
command = "poetry run python -m smart_contracts deploy"
environment_secrets = [
"DEPLOYER_MNEMONIC",
"DISPENSER_MNEMONIC",
]

[deploy.localnet]
[project.deploy.localnet]
environment_secrets = []

[generate.smart_contract]
description = "Adds new smart contract to existing project"
path = ".algokit/generators/create_contract"
[project.run]
# Commands intented for use locally and in CI
build = { commands = [
'poetry run python -m smart_contracts build',
], description = 'Build all smart contracts in the project' }
test = { commands = [
'poetry run pytest',
], description = 'Run smart contract tests' }
audit = { commands = [
'poetry export --without=dev -o requirements.txt',
'poetry run pip-audit -r requirements.txt',
], description = 'Audit with pip-audit' }
lint = { commands = [
'poetry run black --check .',
'poetry run ruff .',
'poetry run mypy',
], description = 'Perform linting' }
audit-teal = { commands = [
# 🚨 IMPORTANT 🚨: For strict TEAL validation, remove --exclude statements. The default starter contract is not for production. Ensure thorough testing and adherence to best practices in smart contract development. This is not a replacement for a professional audit.
'algokit task analyze smart_contracts/artifacts --recursive --force --exclude rekey-to --exclude is-updatable --exclude missing-fee-check --exclude is-deletable --exclude can-close-asset --exclude can-close-account --exclude unprotected-deletable --exclude unprotected-updatable',
], description = 'Audit TEAL files' }

[project]
type = 'contract'
name = 'production_beaker_smart_contract_python'
# Commands indented for CI only, prefixed with `ci-` by convention
ci-teal-diff = { commands = [
'git add -N ./smart_contracts/artifacts',
'git diff --exit-code --minimal ./smart_contracts/artifacts',
], description = 'Check TEAL files for differences' }

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
name: Continuous Delivery of Smart Contract
name: Release production_beaker_smart_contract_python

on:
workflow_call:
push:
branches:
- main

concurrency: release

jobs:
ci-check:
name: Perform Checks
uses: ./.github/workflows/checks.yaml

validate:
name: Validate production_beaker_smart_contract_python
uses: ./.github/workflows/production-beaker-smart-contract-python-ci.yaml
deploy-testnet:
runs-on: 'ubuntu-latest'
needs: ci-check
environment: Test
runs-on: "ubuntu-latest"
needs: validate
environment: contract-testnet
steps:
- name: Checkout source code
uses: actions/checkout@v4
Expand All @@ -26,14 +24,14 @@ jobs:
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'poetry'
python-version: "3.12"
cache: "poetry"

- name: Install algokit
run: pipx install algokit
run: pipx install git+https://github.com/algorandfoundation/algokit-cli@feat/orchestration-linking

- name: Bootstrap dependencies
run: algokit bootstrap all
run: algokit bootstrap all --project-name 'production_beaker_smart_contract_python'

- name: Configure git
shell: bash
Expand All @@ -42,7 +40,7 @@ jobs:
git config --global user.email "actions@github.com" && git config --global user.name "github-actions"

- name: Deploy to testnet
run: algokit deploy testnet
run: algokit deploy testnet --project-name 'production_beaker_smart_contract_python'
env:
# This is the account that becomes the creator of the contract
DEPLOYER_MNEMONIC: ${{ secrets.DEPLOYER_MNEMONIC }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Validate production_beaker_smart_contract_python

on:
workflow_call:
pull_request:

jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "poetry"

- name: Install algokit
run: pipx install git+https://github.com/algorandfoundation/algokit-cli@feat/orchestration-linking

- name: Start LocalNet
run: algokit localnet start

- name: Bootstrap dependencies
run: algokit bootstrap all --project-name 'production_beaker_smart_contract_python'

- name: Configure git
shell: bash
run: |
# set git user and email as test invoke git
git config --global user.email "actions@github.com" && git config --global user.name "github-actions"

- name: Audit python dependencies
run: algokit project run audit --project-name 'production_beaker_smart_contract_python'

- name: Lint and format python dependencies
run: algokit project run lint --project-name 'production_beaker_smart_contract_python'

- name: Run tests
shell: bash
run: |
set -o pipefail
algokit project run test --project-name 'production_beaker_smart_contract_python'

- name: Build smart contracts
run: algokit project run build --project-name 'production_beaker_smart_contract_python'

- name: Scan TEAL files for issues
run: algokit project run audit-teal --project-name 'production_beaker_smart_contract_python'

- name: Check output stability of the smart contracts
run: algokit project run ci-teal-diff --project-name 'production_beaker_smart_contract_python'

- name: Run deployer against LocalNet
run: algokit project deploy localnet --project-name 'production_beaker_smart_contract_python'
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ For an interactive guided walkthrough of the project install [CodeTour](https://

> For guidance on `smart_contracts` folder and adding new contracts to the project please see [README](smart_contracts/README.md) on the respective folder.### Continuous Integration / Continuous Deployment (CI/CD)

This project uses [GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions) to define CI/CD workflows, which are located in the [`.github/workflows`](./.github/workflows) folder.
This project uses [GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions) to define CI/CD workflows, which are located in the [.github/workflows](`.github/workflows`) folder.

> Please note, if you instantiated the project with --workspace flag in `algokit init` it will automatically attempt to move the contents of the `.github` folder to the root of the workspace.

### Debugging Smart Contracts

Expand Down
Loading