如何将python函数的输出保存到GitHub操作?

n9vozmp4  于 2022-11-27  发布在  Python
关注(0)|答案(1)|浏览(155)

如何在GitHub Action代码中保存Python函数的输出?

def example():
    return "a"

if __name__ == "__main__":
    example()

我试图保存到一个变量,输出和环境变量,但它不起作用。它只保存如果我在函数中打印的东西。

name: "Check Renamed files"
"on":
  pull_request:
    branches:
      - main

jobs:
  prose:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: 3.8

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - name: Check renamed files
        run: |
          INPUT_STORE=$(python3 test.py)
          echo $INPUT_STORE

此外,还尝试了以下多行输出:

MY_STRING="{$(python test.py }})} EOF"
          echo "MY_STRING<<EOF" >> $GITHUB_ENV
          echo "$MY_STRING" >> $GITHUB_ENV

但没有任何效果

rhfm7lfc

rhfm7lfc1#

您可以将其设置为具有环境变量。

def example():
    return "a"

if __name__ == "__main__":
    print(example())

然后运行:

python3 test.py

将打印到控制台:

"a"

在你的Gitlab操作中,我会期待类似这样的内容:

name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
  Explore-GitHub-Actions:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository code
        uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: 3.8
      - name: Print from test.py
        run: |
           export INPUT_STORE=$(python test.py)
           echo "Access direct: "
           echo $INPUT_STORE

结果是:

相关问题