使用 CURL 触发 github 工作流程

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

我创建了一个 github-actions-workflow 和一个细粒度的个人访问令牌,并尝试使用 CURL 请求触发它。但工作流程没有触发?为什么?

工作流程:

name: Dispatch Test

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Parse payload
        run: |
          echo "Received payload: ${{ github.event.client_payload | tojson }}"
          
          # Access specific keys in the payload
          key1_value=$(echo "${{ github.event.client_payload.key1 }}")
          key2_value=$(echo "${{ github.event.client_payload.key2 }}")

          echo "Value of key1: $key1_value"
          echo "Value of key2: $key2_value"

卷曲:

curl -X POST \
  -H "Accept: application/vnd.github.everest-preview+json" \
  -H "Authorization: Bearer github_pat_PERSONAL_ACCESS_TOKEN" \
  --data '{"event_type": "trigger-curl-event", "client_payload": {"key1": "value1", "key2": "value2"}}' \
  https://api.github.com/repos/USER/PROJECT/dispatches

PAT 权限: 似乎有点破损,因为唯一有任何效果的是内容:“读和写”

CURL 请求通过 204

完全卷曲

  curl -v -X POST \
  -H "Accept: application/vnd.github.everest-preview+json" \
  -H "Authorization: Bearer github_pat_XXX" \
  --data '{"event_type": "trigger-curl-event", "client_payload": {"key1": "value1", "key2": "value2"}}' \
  https://api.github.com/repos/USER/PROJECT/dispatches

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 4.208.26.200:443...
* Connected to api.github.com (4.208.26.200) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS header, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS header, Finished (20):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.2 (OUT), TLS header, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: C=US; ST=California; L=San Francisco; O=GitHub, Inc.; CN=*.github.com
*  start date: Feb 16 00:00:00 2023 GMT
*  expire date: Mar 15 23:59:59 2024 GMT
*  subjectAltName: host "api.github.com" matched cert's "*.github.com"
*  issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS Hybrid ECC SHA384 2020 CA1
*  SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* Using Stream ID: 1 (easy handle 0x56495c8ac830)
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
> POST /repos/deltaboukensha/db-chatgpt-sambla/dispatches HTTP/2
> Host: api.github.com
> user-agent: curl/7.81.0
> accept: application/vnd.github.everest-preview+json
> authorization: Bearer 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
> content-length: 92
> content-type: application/x-www-form-urlencoded
> 
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* We are completely uploaded and fine
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
< HTTP/2 204 
< server: GitHub.com
< date: Fri, 01 Mar 2024 13:33:35 GMT
< github-authentication-token-expiration: 2024-03-31 13:37:43 +0200
< x-github-media-type: github.v3; param=everest-preview; format=json
< x-accepted-github-permissions: contents=write
< x-github-api-version-selected: 2022-11-28
< x-ratelimit-limit: 5000
< x-ratelimit-remaining: 4999
< x-ratelimit-reset: 1709303615
< x-ratelimit-used: 1
< x-ratelimit-resource: core
< access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< access-control-allow-origin: *
< strict-transport-security: max-age=31536000; includeSubdomains; preload
< x-frame-options: deny
< x-content-type-options: nosniff
< x-xss-protection: 0
< referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
< content-security-policy: default-src 'none'
< vary: Accept-Encoding, Accept, X-Requested-With
< x-github-request-id: 9D80:B3C54:2B68CFA:2C501E6:65E1D92F
< 
* Connection #0 to host api.github.com left intact
github curl github-actions
1个回答
0
投票

我建议使用

gh
cli 来触发工作流程,更容易。

EXAMPLES
  # Have gh prompt you for what workflow you'd like to run and interactively collect inputs
  $ gh workflow run

  # Run the workflow file 'triage.yml' at the remote's default branch
  $ gh workflow run triage.yml

  # Run the workflow file 'triage.yml' at a specified ref
  $ gh workflow run triage.yml --ref my-branch

  # Run the workflow file 'triage.yml' with command line inputs
  $ gh workflow run triage.yml -f name=scully -f greeting=hello

  # Run the workflow file 'triage.yml' with JSON via standard input
  $ echo '{"name":"scully", "greeting":"hello"}' | gh workflow run triage.yml --json
© www.soinside.com 2019 - 2024. All rights reserved.