diff --git a/.github/workflows/README.md b/.github/workflows/README.md index e1646dfc1f..fddc498ae7 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -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 +``` diff --git a/.github/workflows/forked-helper.yml b/.github/workflows/forked-helper.yml new file mode 100644 index 0000000000..315cac2da1 --- /dev/null +++ b/.github/workflows/forked-helper.yml @@ -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 }} + }