无法在github动作中解析信息

发布于 2025-02-13 03:36:07 字数 3723 浏览 0 评论 0原文

我已经处理了几个月,但是

我仍然无法使用Python正确解析“提交消息”(请参见下面的脚本)。

您会看到,在我的

例如,在撰写本文时,解析提交消息将导致a标签:

v8.11.0

我会收到此错误消息:

我不确定它是否在创建变量,标签。

Python不为我工作。有人会有另一种方法吗?


# This workflow tests and releases the latest build

name: CI

# Controls when the action will run.
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build-and-test"
  build-and-test:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      # Use the standard Java Action to setup Java
      # we want the latest Java 12
      - uses: actions/setup-java@v1
        with:
          java-version: '12.x'
      # Use the community Action to install Flutter
      # we want the stable channel
      - uses: subosito/flutter-action@v1
        with:
          channel: 'stable'

      # Get flutter packages
      - run: flutter pub get

      # Check for any formatting issues in the code.
      - run: flutter format .

      # Analyze our Dart code, but don't fail with there are issues.
      - run: flutter analyze . --preamble --no-fatal-infos --no-fatal-warnings

      # Run our tests
      - run: flutter test --coverage

      # Upload to codecov
      - uses: codecov/codecov-action@v2
        with:
          token: ${{secrets.CODECOV_TOKEN}}
          file: ./coverage/lcov.info

      # Parse a tag from the commit message
      - id: get-tag
        shell: python3 {0}
        run: |
          import json
          import os
          with open(os.environ['GITHUB_EVENT_PATH']) as fh:
            event = json.load(fh)
            tag = event['head_commit']['message'].split()[0]     <----- tag NOT CREATED?!
      # Create a Release
      - uses: softprops/action-gh-release@v1
        env:
          # This token is provided by Actions, you do not need to create your own token
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: v${{ steps.get-tag.outputs.tag }}                  <----- ERROR HERE!
          release_name:  ${{ steps.get-tag.outputs.tag }}              <----- ERROR HERE!
          body: |
            See CHANGELOG.md
          draft: false
          prerelease: false

使用替代方法,我能够使用当前日期产生标签。

这证明了尝试使用Python分配“标签”值时,所有这些都期望。

      # Get current datetime in ISO format
      - id: date
        run: echo "::set-output name=date::$(date -u +'%Y-%m-%d')"            
      # Create a Release
      - uses: softprops/action-gh-release@v1
        env:
          # This token is provided by Actions, you do not need to create your own token
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ steps.date.outputs.date }}v${{ github.run_number }}
          name: ${{ steps.date.outputs.date }}v${{ github.run_number }}
          body: |
               See CHANGELOG.md
          draft: false
          prerelease: false

有什么想法吗?

I've been working on this for months now, but

I still can't parse the 'Commit Message' properly with Python (see script below).

You see, with every commit in my repository, every commit message begins with what represents the release's version number.

As of this writing, for example, parsing the commit message would result the a tag:

v8.11.0

I get this error message instead:
enter image description here

I'm not certain if it's creating the variable, tag, or not.

Python is not working for me. Would anyone have another approach?


# This workflow tests and releases the latest build

name: CI

# Controls when the action will run.
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build-and-test"
  build-and-test:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      # Use the standard Java Action to setup Java
      # we want the latest Java 12
      - uses: actions/setup-java@v1
        with:
          java-version: '12.x'
      # Use the community Action to install Flutter
      # we want the stable channel
      - uses: subosito/flutter-action@v1
        with:
          channel: 'stable'

      # Get flutter packages
      - run: flutter pub get

      # Check for any formatting issues in the code.
      - run: flutter format .

      # Analyze our Dart code, but don't fail with there are issues.
      - run: flutter analyze . --preamble --no-fatal-infos --no-fatal-warnings

      # Run our tests
      - run: flutter test --coverage

      # Upload to codecov
      - uses: codecov/codecov-action@v2
        with:
          token: ${{secrets.CODECOV_TOKEN}}
          file: ./coverage/lcov.info

      # Parse a tag from the commit message
      - id: get-tag
        shell: python3 {0}
        run: |
          import json
          import os
          with open(os.environ['GITHUB_EVENT_PATH']) as fh:
            event = json.load(fh)
            tag = event['head_commit']['message'].split()[0]     <----- tag NOT CREATED?!
      # Create a Release
      - uses: softprops/action-gh-release@v1
        env:
          # This token is provided by Actions, you do not need to create your own token
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: v${{ steps.get-tag.outputs.tag }}                  <----- ERROR HERE!
          release_name:  ${{ steps.get-tag.outputs.tag }}              <----- ERROR HERE!
          body: |
            See CHANGELOG.md
          draft: false
          prerelease: false

Using an alternative approach, I'm able to produce a tag using the current date.

This proves that it all works expect when trying to assign a 'tag' value using Python.

      # Get current datetime in ISO format
      - id: date
        run: echo "::set-output name=date::$(date -u +'%Y-%m-%d')"            
      # Create a Release
      - uses: softprops/action-gh-release@v1
        env:
          # This token is provided by Actions, you do not need to create your own token
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ steps.date.outputs.date }}v${{ github.run_number }}
          name: ${{ steps.date.outputs.date }}v${{ github.run_number }}
          body: |
               See CHANGELOG.md
          draft: false
          prerelease: false

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是在用心讲痛 2025-02-20 03:36:07

steps.get-tag.outputs.tag在您的工作流程中未正确输出。

您应该如 docs

      - id: get-tag
        shell: python3 {0}
        run: |
          import json
          import os
          with open(os.environ['GITHUB_EVENT_PATH']) as fh:
            event = json.load(fh)
            tag = event['head_commit']['message'].split()[0]
          print("::set-output name=tag::" + tag)  # <--- This line

steps.get-tag.outputs.tag is not correctly output in your workflow.

You should output it as described in the docs:

      - id: get-tag
        shell: python3 {0}
        run: |
          import json
          import os
          with open(os.environ['GITHUB_EVENT_PATH']) as fh:
            event = json.load(fh)
            tag = event['head_commit']['message'].split()[0]
          print("::set-output name=tag::" + tag)  # <--- This line
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文