GitHub Actions 工作流程失败,退出代码为 127 - 未找到命令

问题描述 投票:0回答:1

我的 GitHub Actions 工作流程遇到问题。当某些 GitHub 事件发生时,工作流程应该向 Telegram 频道发送消息。但是,我收到了

exit code 127
错误,这表明未找到命令。

这是我的工作流程的简化版本:

name: Telegram Message

on:
  push:
  pull_request:
  issues:
  release:
  create:
  delete:
  fork:
  watch:
  deployment:
  deployment_status:
  milestone:
  repository_dispatch:

jobs:
  notify:
    runs-on: ubuntu-latest

    steps:
      - name: Send Message to Telegram
        run: |
          EVENT_NAME=${{ github.event_name }}
          REPO_NAME=${{ github.repository }}
          REPO_URL="https://github.com/${{ github.repository }}"
          BRANCH_NAME=${{ github.ref_name }}
          COMMIT_MESSAGE=${{ github.event.head_commit.message || 'N/A' }}
          COMMIT_AUTHOR=${{ github.event.head_commit.author.name || 'N/A' }}
          PR_TITLE=${{ github.event.pull_request.title || 'N/A' }}
          ISSUE_TITLE=${{ github.event.issue.title || 'N/A' }}
          RELEASE_NAME=${{ github.event.release.name || 'N/A' }}
          RELEASE_BODY=${{ github.event.release.body || 'N/A' }}
          FORK_NAME=${{ github.event.forkee.full_name || 'N/A' }}
          WATCHER=${{ github.actor || 'N/A' }}
          DEPLOYMENT_URL=${{ github.event.deployment.url || 'N/A' }}
          DEPLOYMENT_STATUS=${{ github.event.deployment_status.state || 'N/A' }}
          MILESTONE_TITLE=${{ github.event.milestone.title || 'N/A' }}
          DISPATCH_EVENT_TYPE=${{ github.event.action || 'N/A' }}

          MESSAGE="**Event Type:** $EVENT_NAME\n"
          MESSAGE+="**Repository:** $REPO_NAME\n"
          MESSAGE+="**Repository URL:** $REPO_URL\n"
          MESSAGE+="**Branch:** $BRANCH_NAME\n"

          if [ "$EVENT_NAME" == "push" ]; then
            MESSAGE+="**Commit Message:** $COMMIT_MESSAGE\n"
            MESSAGE+="**Commit Author:** $COMMIT_AUTHOR\n"
          fi

          if [ "$EVENT_NAME" == "pull_request" ]; then
            MESSAGE+="**Pull Request Title:** $PR_TITLE\n"

          fi

          if [ "$EVENT_NAME" == "issues" ]; then
            MESSAGE+="**Issue Title:** $ISSUE_TITLE\n"

          fi

          if [ "$EVENT_NAME" == "release" ]; then
            MESSAGE+="**Release Name:** $RELEASE_NAME\n"
            MESSAGE+="**Release Body:** $RELEASE_BODY\n"
          fi


          if [ "$EVENT_NAME" == "fork" ]; then
            MESSAGE+="**Forked Repository:** $FORK_NAME\n"
          fi

          if [ "$EVENT_NAME" == "watch" ]; then
            MESSAGE+="**Watcher:** $WATCHER\n"
          fi

          if [ "$EVENT_NAME" == "deployment" ]; then
            MESSAGE+="**Deployment URL:** $DEPLOYMENT_URL\n"
          fi

          if [ "$EVENT_NAME" == "deployment_status" ]; then
            MESSAGE+="**Deployment Status:** $DEPLOYMENT_STATUS\n"
          fi


          if [ "$EVENT_NAME" == "milestone" ]; then
            MESSAGE+="**Milestone Title:** $MILESTONE_TITLE\n"
          fi

          if [ "$EVENT_NAME" == "repository_dispatch" ]; then
            MESSAGE+="**Dispatch Event Type:** $DISPATCH_EVENT_TYPE\n"
          fi

          curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage" \
            -d chat_id=${{ secrets.CHAT_ID }} \
            -d text="$MESSAGE" \
            -d parse_mode=Markdown
        env:
          TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
          TELEGRAM_CHAT_ID: ${{ secrets.CHAT_ID }}

错误信息:

在此输入图片描述

在此输入图片描述

确保在 GitHub Secrets 中正确设置环境变量 TELEGRAM_TOKEN 和 CHAT_ID。 检查了我的 YAML 文件的语法。

github curl github-actions telegram
1个回答
0
投票

提交消息似乎有一个前导空格:“ Action ...”你可以像这样修复错误

COMMIT_MESSAGE=$(echo ${{ github.event.head_commit.message || 'N/A' }})
© www.soinside.com 2019 - 2024. All rights reserved.