Search code examples
githubgithub-actionstelegram

Workflow fails with exit code 127 - Action: command not found


I'm encountering an issue with my GitHub Actions workflow. The workflow is supposed to send a message to a Telegram channel when certain GitHub events occur. However, I'm getting an exit code 127 error, which indicates that a command is not found.

Here's a simplified version of my workflow:

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 }}

Error Message:

image1

image2

Ensured that environment variables TELEGRAM_TOKEN and CHAT_ID are correctly set in GitHub Secrets. Checked the syntax of my YAML file.


Solution

  • The commit message seems to have a leading space: “ Action …” you can fix the error like this

    COMMIT_MESSAGE=$(echo ${{ github.event.head_commit.message || 'N/A' }})