Skip to content

Commit d438eae

Browse files
committed
feat: initial commit
1 parent 38b9bfc commit d438eae

File tree

6 files changed

+142
-2
lines changed

6 files changed

+142
-2
lines changed

.github/workflows/python.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Lint
2+
on: [push, pull_request]
3+
jobs:
4+
lint:
5+
name: Lint
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Set up Python 3.7
9+
uses: actions/setup-python@v1
10+
with:
11+
python-version: "3.7"
12+
13+
- uses: actions/checkout@v1
14+
15+
- name: Lint
16+
run: |
17+
pip install flake8
18+
flake8 main.py

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3-slim AS builder
2+
ADD . /app
3+
WORKDIR /app
4+
5+
RUN pip install --target=/app requests
6+
7+
FROM gcr.io/distroless/python3-debian10
8+
COPY --from=builder /app /app
9+
WORKDIR /app
10+
ENV PYTHONPATH /app
11+
CMD ["/app/main.py"]

README.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,80 @@
1-
# python-container-action
2-
A template for creating GitHub Actions in Python | 一个用于开发 GitHub Actions 的 Python 容器模板
1+
<p align="center">
2+
<a href="https://github.com/actionv/python-container-action">
3+
<img src="./images/logo.png">
4+
</a>
5+
</p>
6+
<h1 align="center">基于 Python 容器的 GitHub Actions 模板</h1>
7+
8+
<div align="center">
9+
10+
[![actions status](https://github.com/actionv/python-container-action/workflows/Lint/badge.svg)](https://github.com/actionv/python-container-action/actions) [![release](https://img.shields.io/github/v/release/actionv/python-container-action.svg)](../../releases) [![license](https://badgen.net/github/license/actionv/python-container-action)](./LICENSE) [![PRs Welcome](https://badgen.net/badge/PRs/welcome/green)](../../pulls)
11+
12+
</div>
13+
14+
这是一个用于快速创建 GitHub Actions 的模板,里面包含一段 Python 小程序,该应用程序内置到了 Container Action 中。
15+
16+
[`main.py`](main.py) 文件中有一个小示例,展示了如何获取 Action 输入参数并返回 Action 输出。
17+
18+
如果你想基于 Python 容器开发 GitHub Actions,可以在[当前仓库](https://github.com/actionv/python-container-action)上点击 <kbd>[Use this template](https://github.com/actionv/python-container-action/generate)</kbd>,基于当前模板创建一个新的存储库。
19+
20+
## 使用
21+
在此处描述如何使用你的 Action。
22+
23+
### Workflow 示例
24+
```yml
25+
name: My Workflow
26+
on: [push, pull_request]
27+
jobs:
28+
build:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@master
32+
- name: Run action
33+
34+
# 放置你的 Action 仓库
35+
uses: username/myaction@master
36+
37+
# Action 的输入参数
38+
with:
39+
username: yanglbme
40+
```
41+
42+
### 入参
43+
| 参数 | 描述 | 是否必传 | 默认值 |
44+
|---|---|---|---|
45+
| username | 用户名 | 是 | - |
46+
| age | 年龄 | 否 | 18 |
47+
48+
### 出参
49+
| 参数 | 描述 |
50+
|---|---|
51+
| res | | 一个输出参数 |
52+
53+
## 实例
54+
55+
### 输入
56+
```yml
57+
with:
58+
username: yanglbme
59+
age: 99
60+
```
61+
62+
### 输出
63+
```yml
64+
steps:
65+
- uses: actions/checkout@master
66+
- name: Run action
67+
id: myaction
68+
69+
# 放置你的 Action 仓库
70+
uses: me/myaction@master
71+
72+
# Action 的输入参数
73+
with:
74+
username: yanglbme
75+
76+
# 演示如何使用 Action 的输出
77+
- name: Check outputs
78+
run: |
79+
echo "Outputs - ${{ steps.myaction.outputs.res }}"
80+
```

action.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "A Python Container Action Template"
2+
description: "Get started with Python Container action"
3+
author: "yanglbme"
4+
branding:
5+
icon: 'copy'
6+
color: 'gray-dark'
7+
inputs:
8+
username:
9+
description: "Username"
10+
require: true
11+
age:
12+
description: "Age"
13+
require: false
14+
default: 18
15+
outputs:
16+
res:
17+
description: "Result from the action"
18+
runs:
19+
using: "docker"
20+
image: "Dockerfile"

images/logo.png

18.8 KB
Loading

main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import os
2+
import requests
3+
4+
5+
def main():
6+
requests.get('https://httpbin.org/get?code=0')
7+
username = os.environ["INPUT_USERNAME"]
8+
res = f"Hello {username}"
9+
print(f"::set-output name=res::{res}")
10+
11+
12+
if __name__ == "__main__":
13+
main()

0 commit comments

Comments
 (0)