Add python_action.yaml
This commit is contained in:
27
.gitea/actions/python-action/action.yaml
Executable file
27
.gitea/actions/python-action/action.yaml
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
name: 'Simple param action Python'
|
||||||
|
description: 'Prints the argument and stores it in the file'
|
||||||
|
inputs:
|
||||||
|
name:
|
||||||
|
description: 'First argument value'
|
||||||
|
required: true
|
||||||
|
default: 'Mike'
|
||||||
|
outputs:
|
||||||
|
processed-name:
|
||||||
|
description: 'Processed name'
|
||||||
|
# This is different. We need to specify which step has the output
|
||||||
|
value: ${{ steps.process-name.outputs.processed-name }}
|
||||||
|
runs:
|
||||||
|
using: 'composite'
|
||||||
|
steps:
|
||||||
|
- name: Install Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.10'
|
||||||
|
- name: Pass Inputs to Shell
|
||||||
|
run: |
|
||||||
|
echo "INPUT_NAME=${{ inputs.name }}" >> $GITHUB_OUTPUT
|
||||||
|
shell: bash
|
||||||
|
- name: Fetch the number's square
|
||||||
|
id: process-name
|
||||||
|
run: python ./.gitea/actions/python-action/main.py
|
||||||
|
shell: bash
|
||||||
26
.gitea/actions/python-action/main.py
Executable file
26
.gitea/actions/python-action/main.py
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def main():
|
||||||
|
try:
|
||||||
|
name = os.getenv('INPUT_NAME', 'No name provided')
|
||||||
|
print(f'Arg received from main.py: {name}')
|
||||||
|
|
||||||
|
print('Workdir from main.py:')
|
||||||
|
for filename in os.listdir('.'):
|
||||||
|
print(filename)
|
||||||
|
|
||||||
|
with open('name.txt', 'w') as file:
|
||||||
|
file.write(name)
|
||||||
|
|
||||||
|
with open(os.getenv('GITHUB_OUTPUT', '/dev/null'), 'a') as file:
|
||||||
|
file.write(f'processed-name={name}\n')
|
||||||
|
|
||||||
|
# print(f'::set-output name=processed-name::{name}') # This is the old syntax
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f'::error::{e}')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
24
.gitea/workflows/016_python_action.yaml
Normal file
24
.gitea/workflows/016_python_action.yaml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
name: Custom Python Action
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Run Custom Action
|
||||||
|
uses: ./.gitea/actions/python-action
|
||||||
|
with:
|
||||||
|
name: 'Hang'
|
||||||
|
id: custom-action
|
||||||
|
|
||||||
|
- name: Print Processed Name
|
||||||
|
run: |
|
||||||
|
echo "Processed Name from python_action.yaml: ${{ steps.custom-action.outputs.processed-name }}"
|
||||||
|
echo "Workdir from python_action.yaml"
|
||||||
|
ls -la
|
||||||
Reference in New Issue
Block a user