Skip to content

Commit

Permalink
Merge pull request #30 from lnxpy/feature/decoration
Browse files Browse the repository at this point in the history
New Decoration Style
  • Loading branch information
lnxpy authored Apr 30, 2024
2 parents b24cd93 + bd86cc0 commit 216af1b
Show file tree
Hide file tree
Showing 25 changed files with 456 additions and 202 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Updating the Codecov Report

on: [push, pull_request]

jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repos:
rev: v0.3.0
hooks:
- id: ruff
args: [--fix, --select, I]
- id: ruff-format
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## PyAction ![Version)](https://img.shields.io/github/v/tag/lnxpy/pyaction?label=Version) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyaction?logo=python&logoColor=949DA5&label=Python&labelColor=2A3035) [![Package Testing](https://github.com/lnxpy/pyaction/actions/workflows/testing.yml/badge.svg)](https://github.com/lnxpy/pyaction/actions/workflows/testing.yml) [![Docs CI](https://github.com/lnxpy/pyaction/actions/workflows/docs.yml/badge.svg?branch=main)](https://github.com/lnxpy/pyaction/actions/workflows/docs.yml)
## PyAction ![Version)](https://img.shields.io/github/v/tag/lnxpy/pyaction?label=Version) ![Python Versions](https://img.shields.io/pypi/pyversions/pyaction?logo=python&logoColor=949DA5&label=Python&labelColor=2A3035) [![codecov](https://codecov.io/gh/lnxpy/pyaction/graph/badge.svg?token=59XAONX5S1)](https://codecov.io/gh/lnxpy/pyaction) [![Package Testing](https://github.com/lnxpy/pyaction/actions/workflows/testing.yml/badge.svg)](https://github.com/lnxpy/pyaction/actions/workflows/testing.yml) [![Docs CI](https://github.com/lnxpy/pyaction/actions/workflows/docs.yml/badge.svg?branch=main)](https://github.com/lnxpy/pyaction/actions/workflows/docs.yml)

PyAction helps you to develop [GitHub Actions](https://docs.github.com/en/actions) using Python. It's delivered as an installable package with the ability to test the action locally before any deployment.

Expand Down
31 changes: 13 additions & 18 deletions docs/css/navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,31 @@
}

.md-main blockquote {
border-left: unset !important;
border: unset !important;
border-radius: 4px;
padding: 20px 0 20px 0;
}

.md-main blockquote p {
display: inline;
}

.md-main blockquote:before {
opacity: 0.15;
opacity: 0.1;
z-index: -1;
content: open-quote;
font-family: manrope;
font-size: 11em;
line-height: 0.5em;
margin-left: -30px;
font-size: 14em;
line-height: 0.53em;
margin-left: -25px;
position: absolute;
}
.md-main blockquote p {
display: inline;
}

.md-main blockquote mark {
display: block;
background-color: unset;
margin-top: 13px;
margin: 15px 0 0 20px;
font-style: italic;
color: #b35dfab2;
font-family: "Handlee", cursive;
font-size: 19px;
font-weight: 700;
}

.md-main blockquote mark::before {
color: #757575;
content: "—";
margin-right: 5px;
font-weight: 150;
}
31 changes: 9 additions & 22 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Create Github Actions using Python
title: Introduction
---

# Welcome to PyAction! ![PyPI - Version](https://img.shields.io/pypi/v/pyaction?logo=pypi&logoColor=949DA5&label=Version&labelColor=2A3035&color=652DC7) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyaction?logo=python&logoColor=949DA5&label=Python&labelColor=2A3035&color=652DC7) [![Package Testing](https://github.com/lnxpy/pyaction/actions/workflows/testing.yml/badge.svg)](https://github.com/lnxpy/pyaction/actions/workflows/testing.yml) [![docs ci](https://github.com/lnxpy/pyaction/actions/workflows/docs.yml/badge.svg?branch=main)](https://github.com/lnxpy/pyaction/actions/workflows/docs.yml)
# Welcome to PyAction! ![Version](https://img.shields.io/pypi/v/pyaction?logo=pypi&logoColor=949DA5&label=Version&labelColor=2A3035&color=652DC7) ![Python Versions](https://img.shields.io/pypi/pyversions/pyaction?logo=python&logoColor=949DA5&label=Python&labelColor=2A3035&color=652DC7) [![codecov](https://codecov.io/gh/lnxpy/pyaction/graph/badge.svg?token=59XAONX5S1)](https://codecov.io/gh/lnxpy/pyaction) [![Package Testing](https://github.com/lnxpy/pyaction/actions/workflows/testing.yml/badge.svg)](https://github.com/lnxpy/pyaction/actions/workflows/testing.yml) [![docs ci](https://github.com/lnxpy/pyaction/actions/workflows/docs.yml/badge.svg?branch=main)](https://github.com/lnxpy/pyaction/actions/workflows/docs.yml)

![header](img/header.svg){ .rounded }

Expand Down Expand Up @@ -32,36 +32,23 @@ pyaction --help
pyaction init
```

Here you can see a very basic greeting action example that prints a greeting message when someone calls it with a `name` input parameter.
Here you can see a very basic greeting action example that returns a greeting message to the workflow when someone calls it with a `name` input parameter.

=== ":simple-python: your-action/main.py"

```py
import sys
from typing import List
from pyaction import PyAction

from pyaction import io
workflow = PyAction()


def main(args: List[str]) -> None:
"""main function

Args:
args: STDIN arguments
"""

name = io.read("name")

io.write(
@workflow.action
def my_action(name: str) -> None:
workflow.write(
{
"phrase": f"Hi {name}!"
"phrase": f"Hi {name}!"
}
)


if __name__ == "__main__":
main(sys.argv[1:])

```

=== ":simple-github: .github/workflows/ci.yml"
Expand Down Expand Up @@ -95,7 +82,7 @@ Here you can see a very basic greeting action example that prints a greeting mes
Hi Sadra!
```

Since `pyaction` is part of your action's dependencies, you have access to utilities that enable you to work with the repository/workflow information. You can find out more about these utils on the [Tutorial](tutorial.md) page.
Since `pyaction` is part of your action's dependencies, you have access to utilities that enable you to work with the repository/workflow data. You can find out more about these utils on the [Tutorial](tutorial.md) page.

## How It Works
Custom GitHub Actions can be developed in different ways. PyAction uses the [Docker Container](https://docs.github.com/en/actions/creating-actions/about-custom-actions#docker-container-actions) method which is highly stable with Python environments. This way, you'll be able to specify the requirements for your actions and run them inside a lightweight isolated container with all the dependencies installed.
Expand Down
105 changes: 37 additions & 68 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ And here would be the prompting for our action called "PyAction Hello World".
🎤 Author's name
John Doe
🎤 Include workflow testing pipeline
No
Yes
Copying from template version None
identical .
create pyaction-hello-world
create pyaction-hello-world/requirements.txt
create pyaction-hello-world/.github
create pyaction-hello-world/.github/workflows
create pyaction-hello-world/.github/workflows/test.yml
create pyaction-hello-world/README.md
create pyaction-hello-world/action.yml
create pyaction-hello-world/Dockerfile
Expand Down Expand Up @@ -100,88 +103,56 @@ outputs:
```

### Main Executing File (`main.py`)
This is the main Python file that gets executed when the workflow container gets triggered. In this file, we have access to all the input parameters that users have passed to us via `io.read()`. All we need to do is to retrieve the `name` and return the `phrase` that contains the greeting message.
This is the main Python file that gets executed when the workflow container gets triggered. In this file, we have access to all the input parameters that users have passed to us from the `my_action` parameters. All we need to do is to retrieve the `name` and return the `phrase` that contains the greeting message.

```python title="pyaction-hello-world/main.py" linenums="1"
import sys
from typing import List
from pyaction import PyAction
from pyaction import io
workflow = PyAction()
def main(args: List[str]) -> None:
"""main function
Args:
args: STDIN arguments
"""
# reading the `name` input parameter
name = io.read("name")
message = f"Hello {name}!"

# writing the `phrase` greeting message to output
io.write({"phrase": message})

# Now, people can $echo `phrase`


if __name__ == "__main__":
main(sys.argv[1:])

@workflow.action
def my_action(name: str) -> None:
workflow.write(
{
"phrase": f"Hi {name}!"
}
)
```

## Dependencies
Follow this section if your action needs some additional packages installed in order to work.
## Usage & Deployment
In order to use the action within the repository, update the `test.yml` file in the following way.

??? Note "Using a virtual environment"
This step is optional. If you want to, you can install the dependencies inside a virtualenv other than your global site-packages. Make sure that you've activated your environment.
```yaml title="pyaction-hello-world/.github/workflow/test.yml" linenums="1"
name: Greeting Action
```bash
virtualenv venv
source venv/bin/activate
```
on:
push:
branches:
- main
```bash
pip install PACK1 PACK2==v1.2.3 PACK3
```
jobs:
build:
runs-on: ubuntu-latest
Finally, don't forget to update the `requirements.txt` file.
name: Running the action
steps:
```bash
pip freeze >> requirements.txt
```
- name: checkout
uses: actions/checkout@v4
## Testing Locally
To [test our action locally](tutorial.md#local-testing), we need to create a `.env` file in the root path of our action directory. We have to add the `INPUT_NAME` environment variable into it. To make sure that `message` has the exact content that we want, I simply add a temporary `print(message)` line at the end of the `main()` function and delete it after testing my action.
- name: Greetings
id: greetings
uses: ./
with:
name: Jane
```bash
touch .env
- name: Output
run: echo ${{ steps.greetings.outputs.phrase }}
```

```bash title="pyaction-hello-world/.env"
INPUT_NAME=Armita
```

```python title="pyaction-hello-world/main.py" hl_lines="3"
def main(args: List[str]) -> None:
...
print(message)
```
This way, whenever a push event happens to the `main` branch, this pipeline gets triggered and tests the action with the value `Jane` as the `name` input parameter.

To test the action, run the following command.

```bash
pyaction run
```

And here would be the result.

``` { .bash .no-copy }
Hello Armita!
```

## Deployment & Usage
Stage and commit the changes that you've made.

```bash
Expand All @@ -195,8 +166,6 @@ git tag v0.1.0
git push origin main --tags
```

If you want to self-test your action on each `git push` event, you simply need to answer `y` to the `Include workflow testing pipeline` prompt so it'll create a workflow for your action. Make sure to modify it and update its inputs in `.github/workflows/test.yml`.

!!! Note "This demo is also live.."
The `pyaction-hello-world` implementation in this tutorial is available [here](https://github.com/lnxpy/pyaction-hello-world). Feel free to look over it.

Expand Down
Loading

0 comments on commit 216af1b

Please sign in to comment.