Chạy hành động tập lệnh Python
Viết các tập lệnh Python trong một tệp quy trình làm việc của hành động!
Nội dung chính ShowShow
- Chạy hành động tập lệnh Python
- Xử lý lỗi
- Các chức năng tiện ích
- Thêm đường dẫn
- Nhận đầu vào
- Đặt đầu ra
- Cảnh báo
- Tập đoàn
- Kết thúc nhóm
- Thêm mặt nạ
- Dừng lệnh
- Tiếp tục lệnh
- Nhận trạng thái
- Giữ trạng thái
- Tôi có thể mã hóa Python trên GitHub không?
- Tôi có thể chạy tập lệnh trong GitHub không?
- Làm cách nào để thêm một tập lệnh Python vào GitHub?
- Làm cách nào để điều hành một dự án Python trong Git?
Hành động này cho phép bạn xác định một tập lệnh python tùy chỉnh bên trong tệp yaml công việc. Viết mã Python của bạn làm đối số
- uses: jannekem/[email protected] with: script: | add_path["/usr/local/test"] set_env["HELLO", "WORLD"] group["Messages"] print["Sending a message"] warning["There might be an issue"] end_group[]6 và sử dụng tính năng chuỗi đa dòng YAML để xác định các tập lệnh đa dòng.
Yêu cầu duy nhất là bạn thiết lập môi trường Python trước khi chạy hành động. Dưới đây là một quy trình công việc ví dụ in nội dung thư mục gốc của kho lưu trữ vào nhật ký hành động:
name: Run Script on: push: branches: [ master ] pull_request: branches: [ master ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] with: python-version: '3.x' - uses: jannekem/[email protected] with: script: | import os print["Directory contents:"] for f in os.listdir[]: print[f]
Xử lý lỗi
Các chức năng tiện ích
Thêm đường dẫn
- Nhận đầu vào
- Đặt đầu ra
- Cảnh báo
Tập đoàn
name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] with: python-version: '3.x' - uses: jannekem/[email protected] id: script with: fail-on-error: false script: | print["Doing something that will fail"] a = [] a[10] - name: Print errors if: steps.script.outputs.error == 'true' run: | printenv "SCRIPT_STDOUT" printenv "SCRIPT_STDERR" env: SCRIPT_STDOUT: ${{ steps.script.outputs.stdout }} SCRIPT_STDERR: ${{ steps.script.outputs.stderr }}
Các chức năng tiện ích
Thêm đường dẫn
Nhận đầu vàoExample:
- uses: jannekem/[email protected] with: script: | add_path["/usr/local/test"] set_env["HELLO", "WORLD"] group["Messages"] print["Sending a message"] warning["There might be an issue"] end_group[]
Thêm đường dẫn
Nhận đầu vào
Đặt đầu ra2:name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] with: python-version: '3.x' - uses: jannekem/[email protected] id: script with: fail-on-error: false script: | print["Doing something that will fail"] a = [] a[10] - name: Print errors if: steps.script.outputs.error == 'true' run: | printenv "SCRIPT_STDOUT" printenv "SCRIPT_STDERR" env: SCRIPT_STDOUT: ${{ steps.script.outputs.stdout }} SCRIPT_STDERR: ${{ steps.script.outputs.stderr }}2
Cảnh báo
Nhận đầu vào
Nhận đầu vào
Đặt đầu ra3:name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] with: python-version: '3.x' - uses: jannekem/[email protected] id: script with: fail-on-error: false script: | print["Doing something that will fail"] a = [] a[10] - name: Print errors if: steps.script.outputs.error == 'true' run: | printenv "SCRIPT_STDOUT" printenv "SCRIPT_STDERR" env: SCRIPT_STDOUT: ${{ steps.script.outputs.stdout }} SCRIPT_STDERR: ${{ steps.script.outputs.stderr }}3
Cảnh báo
Đặt đầu ra
Nhận đầu vào
Đặt đầu ra4:name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] with: python-version: '3.x' - uses: jannekem/[email protected] id: script with: fail-on-error: false script: | print["Doing something that will fail"] a = [] a[10] - name: Print errors if: steps.script.outputs.error == 'true' run: | printenv "SCRIPT_STDOUT" printenv "SCRIPT_STDERR" env: SCRIPT_STDOUT: ${{ steps.script.outputs.stdout }} SCRIPT_STDERR: ${{ steps.script.outputs.stderr }}4
Cảnh báo
Tập đoàn
Nhận đầu vào
Đặt đầu ra5:name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] with: python-version: '3.x' - uses: jannekem/[email protected] id: script with: fail-on-error: false script: | print["Doing something that will fail"] a = [] a[10] - name: Print errors if: steps.script.outputs.error == 'true' run: | printenv "SCRIPT_STDOUT" printenv "SCRIPT_STDERR" env: SCRIPT_STDOUT: ${{ steps.script.outputs.stdout }} SCRIPT_STDERR: ${{ steps.script.outputs.stderr }}5
Cảnh báo
Tập đoàn
Nhận đầu vào
Đặt đầu ra6:name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] with: python-version: '3.x' - uses: jannekem/[email protected] id: script with: fail-on-error: false script: | print["Doing something that will fail"] a = [] a[10] - name: Print errors if: steps.script.outputs.error == 'true' run: | printenv "SCRIPT_STDOUT" printenv "SCRIPT_STDERR" env: SCRIPT_STDOUT: ${{ steps.script.outputs.stdout }} SCRIPT_STDERR: ${{ steps.script.outputs.stderr }}6
Cảnh báo
Cảnh báo
Nhận đầu vào
Đặt đầu ra7:name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] with: python-version: '3.x' - uses: jannekem/[email protected] id: script with: fail-on-error: false script: | print["Doing something that will fail"] a = [] a[10] - name: Print errors if: steps.script.outputs.error == 'true' run: | printenv "SCRIPT_STDOUT" printenv "SCRIPT_STDERR" env: SCRIPT_STDOUT: ${{ steps.script.outputs.stdout }} SCRIPT_STDERR: ${{ steps.script.outputs.stderr }}7
Cảnh báo
Tập đoàn
Nhận đầu vào
Đặt đầu ra8:name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] with: python-version: '3.x' - uses: jannekem/[email protected] id: script with: fail-on-error: false script: | print["Doing something that will fail"] a = [] a[10] - name: Print errors if: steps.script.outputs.error == 'true' run: | printenv "SCRIPT_STDOUT" printenv "SCRIPT_STDERR" env: SCRIPT_STDOUT: ${{ steps.script.outputs.stdout }} SCRIPT_STDERR: ${{ steps.script.outputs.stderr }}8
Cảnh báo
Tập đoàn
Nhận đầu vào
name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] with: python-version: '3.x' - uses: jannekem/[email protected] id: script with: fail-on-error: false script: | print["Doing something that will fail"] a = [] a[10] - name: Print errors if: steps.script.outputs.error == 'true' run: | printenv "SCRIPT_STDOUT" printenv "SCRIPT_STDERR" env: SCRIPT_STDOUT: ${{ steps.script.outputs.stdout }} SCRIPT_STDERR: ${{ steps.script.outputs.stderr }}9
Cảnh báo
Kết thúc nhóm
Nhận đầu vào
Đặt đầu ra0:- uses: jannekem/[email protected] with: script: | add_path["/usr/local/test"] set_env["HELLO", "WORLD"] group["Messages"] print["Sending a message"] warning["There might be an issue"] end_group[]0
Cảnh báo
Tập đoànThêm mặt nạ
Nhận đầu vào
Đặt đầu ra2:- uses: jannekem/[email protected] with: script: | add_path["/usr/local/test"] set_env["HELLO", "WORLD"] group["Messages"] print["Sending a message"] warning["There might be an issue"] end_group[]2
Cảnh báo
Tập đoànDừng lệnh
Nhận đầu vào
Đặt đầu ra4:- uses: jannekem/[email protected] with: script: | add_path["/usr/local/test"] set_env["HELLO", "WORLD"] group["Messages"] print["Sending a message"] warning["There might be an issue"] end_group[]4
Cảnh báo
Tiếp tục lệnh
Nhận đầu vào
Đặt đầu ra5:- uses: jannekem/[email protected] with: script: | add_path["/usr/local/test"] set_env["HELLO", "WORLD"] group["Messages"] print["Sending a message"] warning["There might be an issue"] end_group[]5
Cảnh báo
Nhận trạng thái
Nhận đầu vào
Đặt đầu ra6:- uses: jannekem/[email protected] with: script: | add_path["/usr/local/test"] set_env["HELLO", "WORLD"] group["Messages"] print["Sending a message"] warning["There might be an issue"] end_group[]6
Cảnh báo
Tập đoànGiữ trạng thái
Nhận đầu vào
Đặt đầu ra9:- uses: jannekem/[email protected] with: script: | add_path["/usr/local/test"] set_env["HELLO", "WORLD"] group["Messages"] print["Sending a message"] warning["There might be an issue"] end_group[]9
Cảnh báo
Tôi có thể mã hóa Python trên GitHub không?
Tôi có thể chạy tập lệnh trong GitHub không?.
Tôi có thể chạy tập lệnh trong GitHub không?
Làm cách nào để thêm một tập lệnh Python vào GitHub?you can store the script in your repository and supply the path and shell type. For more information, see "Workflow syntax for GitHub Actions."
Làm cách nào để thêm một tập lệnh Python vào GitHub?
Làm cách nào để điều hành một dự án Python trong Git?.
Hành động này cho phép bạn xác định một tập lệnh python tùy chỉnh bên trong tệp yaml công việc. Viết mã Python của bạn làm đối số
- uses: jannekem/[email protected] with: script: | add_path["/usr/local/test"] set_env["HELLO", "WORLD"] group["Messages"] print["Sending a message"] warning["There might be an issue"] end_group[]6 và sử dụng tính năng chuỗi đa dòng YAML để xác định các tập lệnh đa dòng.
Yêu cầu duy nhất là bạn thiết lập môi trường Python trước khi chạy hành động. Dưới đây là một quy trình công việc ví dụ in nội dung thư mục gốc của kho lưu trữ vào nhật ký hành động:
Theo mặc định, hành động sẽ thất bại nếu nó gặp bất kỳ lỗi nào khi cố gắng chạy tập lệnh của bạn. Bạn có thể ghi đè này với đầu vào
- uses: jannekem/[email protected] with: script: | add_path["/usr/local/test"] set_env["HELLO", "WORLD"] group["Messages"] print["Sending a message"] warning["There might be an issue"] end_group[]7.
Làm cách nào để điều hành một dự án Python trong Git?
Làm cách nào để điều hành một dự án Python trong Git ?...
Tải xuống và cài đặt phiên bản bắt buộc của Python trên hệ điều hành của bạn ..
Cài đặt PIP Nếu làm việc trên Python 2, PIP là Trình quản lý gói của Python, nó đi kèm với Python 3 nhưng không phải với Python 2 ..
Đọc về Virtualenv trong Python ..
Kích hoạt môi trường trong CMD ..