Hướng dẫn github action python output - github action python đầu ra

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!

Show

Nội phân 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
  • Dừng lệnh
  • Tiếp tục lệnh
  • Tôi có thể chạy tập lệnh Python trong các hành động github không?
  • Làm cách nào để chạy mã python trong github?
  • Tôi có thể chạy tập lệnh trong GitHub không?
  • Làm cách nào để chạy một hành động pytest trong github?

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ố script 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]
      - 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

Dừng lệnh

  • Tiếp tục lệnh
  • Tôi có thể chạy tập lệnh Python trong các hành động github không?
  • Làm cách nào để chạy mã python trong github?

Tôi có thể chạy tập lệnh trong GitHub không?

name: Run Script

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
      - 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

Dừng lệnh

Example:

- 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()

Tiếp tục lệnh

Tôi có thể chạy tập lệnh Python trong các hành động github không?:

name: Run Script

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
      - 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

Làm cách nào để chạy mã python trong github?

Tôi có thể chạy tập lệnh trong GitHub không?

Làm cách nào để chạy một hành động pytest trong github?:

name: Run Script

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
      - 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

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ố script 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 fail-on-error.:

name: Run Script

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
      - 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

Hành động đặt ba đầu ra:

stdout chứa bất kỳ văn bản nào mà chương trình của bạn in vào bảng điều khiển

stderr chứa bất kỳ văn bản nào được chuyển đến Stderr, chẳng hạn như tin nhắn ngoại lệ:

name: Run Script

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
      - 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

error là một chuỗi có "true" hoặc "false" tùy thuộc vào việc có lỗi hay không, hãy sử dụng điều này để kiểm tra lỗi khi bạn chọn không thất bại

Nhìn vào đoạn trích sau đây để xem cách xử lý lỗi hoạt động trong thực tế:

Hành động đi kèm với các tiện ích mà bạn có thể sử dụng để tương tác với quy trình làm việc. Nếu bạn muốn vô hiệu hóa các tiện ích này, bạn có thể đặt

name: Run Script

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
      - 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 }} 
0 làm đầu vào cho bước. Bạn có thể gọi các chức năng này trực tiếp từ script của bạn mà không cần phải nhập bất cứ thứ gì.:
name: Run Script

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
      - 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

Thêm đường dẫn

Chữ ký: name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] - 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

Trao tiền cho đường dẫn hệ thống. Sự thay đổi sẽ chỉ ảnh hưởng đến các bước sau.:

name: Run Script

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
      - 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

Nhận đầu vào

Chữ ký: name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] - 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

Trả về giá trị của đầu vào đã cho dưới dạng chuỗi.:

name: Run Script

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
      - 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

Đặt đầu ra

Chữ ký: name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] - 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

Đặt một tham số đầu ra.:

name: Run Script

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: actions/[email protected]
      - 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

Đặt env

Chữ ký: name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] - 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

Đặt một biến môi trường để sử dụng trong các bước sau.:

- 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

Gỡ lỗi

Chữ ký: name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - uses: actions/[email protected] - 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

Gửi tin nhắn gỡ lỗi. Thông báo sẽ chỉ hiển thị khi ghi nhật ký gỡ lỗi đã được bật.:

- 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

Dừng lệnh

Tiếp tục lệnh:

- 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

Tôi có thể chạy tập lệnh Python trong các hành động github không?

Tiếp tục lệnh

Tôi có thể chạy tập lệnh Python trong các hành động github không?:

- 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

Làm cách nào để chạy mã python trong github?

Tôi có thể chạy tập lệnh trong GitHub không?

Làm cách nào để chạy một hành động pytest trong github?:

- 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

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ố script 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 fail-on-error.:

- 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

Hành động đặt ba đầu ra:

Tôi có thể chạy tập lệnh Python trong các hành động github không?

Làm cách nào để chạy mã python trong github?Write Python scripts in an Actions workflow file! This action lets you define a custom Python script inside the workflow YAML file. Write your Python code as the script argument, and use the YAML multiline string feature to define multiline scripts.

Làm cách nào để chạy mã python trong github?

Tôi có thể chạy tập lệnh trong GitHub không?.

Làm cách nào để chạy một hành động pytest trong github?

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ố script 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:

Tôi có thể chạy tập lệnh trong GitHub không?

Làm cách nào để chạy một hành động pytest trong github?, which are then executed on the assigned runner.

Làm cách nào để chạy một hành động pytest trong github?

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ố script 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.use the setup-python action. This action finds a specific version of Python or PyPy from the tools cache on each runner and adds the necessary binaries to PATH , which persists for the rest of the job.