我想使用 資料有效負載觸發Github-Actions 作業流http request并在作業流腳本中使用此資料。但是我找不到有關如何發送和使用該有效負載資料的任何檔案。我正在使用以下curl命令來觸發作業流程,但還需要發送和使用該資料負載。
curl \
-X POST \
-H "Accept: application/vnd.github.v3 json" \
--header 'Authorization: token ******' \
https://api.github.com/repos/aashutosh0012/actions-test/actions/workflows/learn-github-actions.yml/dispatches \
-d '{"ref":"main"}'
演示作業流 Yaml 檔案。
name: GitHub Actions Demo
on: [push, workflow_dispatch,repository_dispatch]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "?? The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "?? This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "?? The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v2
- run: echo "?? The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "??? The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
echo ${{ github}}
- run: echo "?? This job's status is ${{ job.status }}."
- run: echo "Aashutosh"
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
- name: Run Python Script
run: python test.py
- name: Install python packages
run: |
python -m pip install --upgrade pip
pip install requests Flask
pip list
- name: Run Python Commands Single line
run: python -c "import requests; print(dir(requests))"
- name: Run Python Commands multi line
uses: jannekem/run-python-script-action@v1
id: script
with:
fail-on-error: false
script: |
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['POST'])
def result():
print(request.form['ref']) # should display 'bar'
return 'Received !' # response to your request.
uj5u.com熱心網友回復:
你可能會混淆repository_dispatch和workflow_dispatch。存盤庫調度是您發送到存盤庫的事件。此事件可以由 GitHub 應用程式接收,也可以用于通過使用作業流on: repository_dispatch的頂部來觸發作業流。
檔案:
repository_dispatch通過 API觸發事件:https : //docs.github.com/en/rest/reference/repos#create-a-repository-dispatch-event- 設定在
respository_dispatch事件上運行的作業流:https : //docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#repository_dispatch
另一方面,作業流調度是關于直接觸發作業流運行。這就像在 UI 上單擊“運行此作業流”一樣。這需要將您的作業流設定為通過on: workflow_dispatch在作業流頂部使用手動觸發。
檔案:
workflow_dispatch通過 API觸發事件:https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event- 設定手動觸發的作業流:https : //docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#workflow_dispatch
創建repository_dispatch事件的方法如下:
curl \
-X POST \
-H "Accept: application/vnd.github.v3 json" \
https://api.github.com/repos/octocat/hello-world/dispatches \
-d '{"event_type":"event_type", "client_payload": {"foo": "bar"}}'
(來自檔案:https : //docs.github.com/en/rest/reference/repos#create-a-repository-dispatch-event)
在您的操作中,您可以像這樣訪問有效負載:
- run: 'echo "Foo: ${{ github.event.client_payload.foo }}"'
注意:您在問題中共享的作業流程是在多個事件上觸發的——不僅僅是repository_dispatch. github.event.client_payload在其他情況下可能不會設定該欄位。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/360651.html
標籤:Python 休息 http github github-actions
