Added helper to run workflows on forks (#3197)
* Added workflow helper for the forked repositories. * Use secret.ARMBIAN_SELF_DISPATCH_TOKEN, Added `event_details` * Use secret.ARMBIAN_SELF_DISPATCH_TOKEN, Added `event_details` * Updated .github/workflows/README.md with `armbian` event * Fix newline in the end of yaml. * Remove `Debug details` step * Added comment for JSON processing
This commit is contained in:
parent
83217ea30c
commit
de548b01e6
28
.github/workflows/README.md
vendored
28
.github/workflows/README.md
vendored
@ -25,3 +25,31 @@ use gpg1 otherwise signing fails
|
||||
sudo ./svc.sh install # install
|
||||
sudo ./svc.sh start # start
|
||||
sudo ./svc.sh status # check
|
||||
|
||||
# Use workflows in forked repositories
|
||||
|
||||
`forked-helper.yml` workflow helper can help to run custom workflows on the forked repositories.
|
||||
|
||||
1. Set `ARMBIAN_SELF_DISPATCH_TOKEN` secret on your repository with `security_events` permissions.
|
||||
2. Helper will dispatch `repository_dispatch` event `armbian` on `push`, `release`, `deployment`,
|
||||
`pull_request` and `workflow_dispatch` events. All needed event details you can find in `client_payload`
|
||||
property of the event.
|
||||
4. Create empty default branch in forked repository
|
||||
5. Create workflow with `repository_dispatch` in default branch.
|
||||
6. Run any need actions in this workflow.
|
||||
|
||||
Workflow example:
|
||||
```yaml
|
||||
name: Test Armbian dispatch
|
||||
|
||||
on:
|
||||
repository_dispatch:
|
||||
types: ["armbian"]
|
||||
|
||||
jobs:
|
||||
show-dispatch:
|
||||
name: Show dispatch event details
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: hmarr/debug-action@v2
|
||||
```
|
||||
|
||||
42
.github/workflows/forked-helper.yml
vendored
Normal file
42
.github/workflows/forked-helper.yml
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
name: Forked helper
|
||||
|
||||
on:
|
||||
push:
|
||||
release:
|
||||
deployment:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
fork-repository-dispatch:
|
||||
name: 📢 Run repository dispatch to default fork branch
|
||||
if: ${{ github.repository_owner != 'armbian' }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Assign secret
|
||||
id: get_dispatch_secret
|
||||
run: echo '::set-output name=dispatch_secret::${{ secrets.ARMBIAN_SELF_DISPATCH_TOKEN }}'
|
||||
- name: Get event details
|
||||
id: get_event_details
|
||||
# Process JSON according https://github.community/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/td-p/37870
|
||||
run: |
|
||||
JSON=$(cat ${{ github.event_path }})
|
||||
JSON="${JSON//'%'/'%25'}"
|
||||
JSON="${JSON//$'\n'/'%0A'}"
|
||||
JSON="${JSON//$'\r'/'%0D'}"
|
||||
echo "::set-output name=event_details::${JSON}"
|
||||
- name: Dispatch event on forked repostitory
|
||||
if: steps.get_dispatch_secret.outputs.dispatch_secret
|
||||
uses: peter-evans/repository-dispatch@v1
|
||||
with:
|
||||
token: ${{ steps.get_dispatch_secret.outputs.dispatch_secret }}
|
||||
repository: ${{ github.repository }}
|
||||
event-type: armbian
|
||||
client-payload: >
|
||||
{
|
||||
"event": "${{ github.event_name }}",
|
||||
"ref": "${{ github.ref }}",
|
||||
"base_ref": "${{ github.base_ref }}",
|
||||
"sha": "${{ github.sha }}",
|
||||
"event_details": ${{ steps.get_event_details.outputs.event_details }}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user