Skip to content

add repo-dispatch action with test #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/actions/repo-dispatch/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: repository-dispatch
description: creates repository_dispatch event in target repository
inputs:
secret-token: # beware: mask is applied below
description: fine-grained personal access token with content write permission for the target repo
required: true
type: string
target-repo-owner:
description: target repository owner (as in <repo-owner>/<repo-name>)
required: true
type: string
target-repo-name:
description: target repository name (as in <repo-owner>/<repo-name>)
required: true
type: string
event-type:
# https://docs.github.com/en/webhooks/webhook-events-and-payloads#repository_dispatch
description: action in repository_dispatch event (as in github.event.action)
required: true
type: string
client-payload:
description: client_payload in repository_dispatch event (a JSON object, as in github.event.client_payload)
required: true
type: string
default: '{}'

runs:
using: composite
steps:
- # https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#masking-a-value-in-a-log
name: mask secret token
run: echo "::add-mask::${{ inputs.secret-token }}"
shell: bash
- name: post to github api dispatches endpoint
# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#create-a-repository-dispatch-event
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication
run: |
curl --location \
--fail-with-body \
--request POST \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer ${{ inputs.secret-token }}" \
--header "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ inputs.target-repo-owner }}/${{ inputs.target-repo-name }}/dispatches \
--data '{"event_type":"${{ inputs.event-type }}","client_payload":${{ inputs.client-payload }}}'
shell: bash
12 changes: 12 additions & 0 deletions .github/workflows/test-repo-dispatch-listener.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: test the receiving end of the repo-dispatch action

on:
repository_dispatch:

jobs:
test:
runs-on: ubuntu-latest
steps:
- run: |
echo "action: ${{ github.event.action }}"
echo "payload: ${{ github.event.client_payload.my-key }}"
25 changes: 25 additions & 0 deletions .github/workflows/test-repo-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This workflow tests the reusable repo-dispatch action

name: test repo-dispatch action

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- name: checkout in order to use local action
uses: actions/checkout@v4
- name: test action
uses: ./.github/actions/repo-dispatch
with:
secret-token: ${{ secrets.personal_access_token }}
target-repo-name: ${{ github.event.repository.name }}
target-repo-owner: ${{ github.repository_owner }}
event-type: my-event
client-payload: '{"my-key": "my-value"}'
Loading