-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64ed7d9
commit 5377baa
Showing
12 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"name": "GHA (square-num-m)", | ||
"image": "ghcr.io/jmlopez-rod/m-devcontainer-py311:latest", | ||
"runArgs": ["--rm", "--network=host", "--name=square-num-devcontainer"], | ||
"postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder} && ./install_m.sh", | ||
"containerEnv": { | ||
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}", | ||
"CONTAINER_WORKSPACE": "${containerWorkspaceFolder}" | ||
}, | ||
"mounts": [ | ||
"source=opt_pnpm,target=/opt/pnpm,type=volume", | ||
"source=opt_venv,target=/opt/venv,type=volume", | ||
"source=m-vscode-server-extensions,target=/root/.vscode-server/extensions,type=volume", | ||
"source=m-vscode-server-extensions-insiders,target=/root/.vscode-server-insiders/extensions,type=volume" | ||
], | ||
"customizations": { | ||
"vscode": { | ||
"settings": { | ||
"[json][jsonc][markdown][mdx][yaml]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.formatOnSave": true | ||
}, | ||
"editor.renderWhitespace": "all", | ||
"files.associations": { | ||
"Makefile.*": "makefile" | ||
}, | ||
"emeraldwalk.runonsave": { | ||
"commands": [ | ||
{ | ||
"match": "\\.py$", | ||
"cmd": "isort ${file}" | ||
} | ||
] | ||
}, | ||
"editor.minimap.enabled": false, | ||
"editor.rulers": [80, 120], | ||
"python.defaultInterpreterPath": "/opt/venv/m/bin/python", | ||
"python.pythonPath": "/workspaces/gha-square-num-m/src", | ||
"python.languageServer": "Pylance", | ||
"python.linting.enabled": true, | ||
"python.linting.pylintEnabled": true, | ||
"python.linting.pylintArgs": ["--rc-file=.pylintrc"], | ||
"python.linting.flake8Enabled": true, | ||
"python.linting.flake8Args": ["--config=.flake8"], | ||
"python.linting.mypyEnabled": true, | ||
"python.linting.mypyArgs": ["--config-file=mypy.ini"] | ||
}, | ||
"extensions": [ | ||
"GitHub.copilot", | ||
"dbaeumer.vscode-eslint", | ||
"esbenp.prettier-vscode", | ||
"ms-python.python", | ||
"ms-python.vscode-pylance", | ||
"ms-python.flake8", | ||
"EditorConfig.EditorConfig", | ||
"unifiedjs.vscode-mdx", | ||
"emeraldwalk.RunOnSave", | ||
"streetsidesoftware.code-spell-checker" | ||
] | ||
} | ||
}, | ||
"shutdownAction": "stopContainer" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
m/.m | ||
.mypy_cache | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mypy: | ||
mypy src | ||
|
||
action: | ||
m github actions src/pkg/actions.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# AUTOGENERATED FILE - Do not update by hand! | ||
# Edit src/pkg/actions.py | ||
# then run `m github actions [python_file]` to update | ||
|
||
name: Square Number | ||
description: Square the given number | ||
|
||
inputs: | ||
num: | ||
description: the number to square | ||
required: true | ||
|
||
outputs: | ||
squared-num: | ||
description: the squared number | ||
value: ${{ steps.square.outputs.squared-num }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- id: square | ||
shell: bash | ||
env: | ||
INPUT_NUM: ${{ inputs.num }} | ||
run: PYTHONPATH="$GITHUB_ACTION_PATH/src" python -m pkg.main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
branch=github-actions | ||
pip install "git+https://github.com/jmlopez-rod/m.git@$branch" | ||
|
||
/opt/m_helpers/_init.sh | ||
|
||
echo 'close this terminal and open another one then run `pnpm install`' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "square-num-gha", | ||
"version": "1.0.0", | ||
"description": "", | ||
"private": true, | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"prettier": "2.8.8" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from m.github.actions import Action | ||
|
||
from .inputs import GithubInputs | ||
from .main import main_step | ||
|
||
actions = Action( | ||
name='Square Number', | ||
description='Square the given number', | ||
file_path='action.yaml', | ||
inputs=GithubInputs, | ||
steps=[ | ||
main_step(step_id='square', args=GithubInputs(num='inputs.num')), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from m.github.actions import InArg, KebabModel | ||
|
||
|
||
class GithubInputs(KebabModel): | ||
"""Inputs from the Github Action.""" | ||
|
||
num: str = InArg(help='the number to square') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from m.core import Good, Res | ||
from m.github.actions import KebabModel, OutArg, RunStep, run_action | ||
|
||
from .inputs import GithubInputs | ||
|
||
|
||
class Outputs(KebabModel): | ||
"""Outputs from the Github Action.""" | ||
|
||
squared_num: str = OutArg(help='the squared number', export=True) | ||
|
||
|
||
def main(inputs: GithubInputs) -> Res[Outputs]: | ||
"""Square the given number. | ||
Args: | ||
inputs: The inputs to the step. | ||
Returns: | ||
The outputs of the step or an issue. | ||
""" | ||
print('Squaring the number') | ||
num = int(inputs.num) | ||
result = num * num | ||
return Good(Outputs(squared_num=str(result))) | ||
|
||
|
||
def main_step( | ||
step_id: str, | ||
args: GithubInputs | ||
) -> RunStep[GithubInputs, Outputs]: | ||
"""Create a step to square the given number. | ||
Args: | ||
step_id: The id of the step. | ||
inputs: The inputs to the step. | ||
Returns: | ||
A step to use in the action. | ||
""" | ||
return RunStep[GithubInputs, Outputs](id=step_id, run=main, args=args) | ||
|
||
if __name__ == '__main__': | ||
run_action(main) |