问题
I'm having some trouble setting up a proper build chain for me and some friends. So, I forked two repos, the official ghidra and ghidra-ci. ghidra-ci is an repo which builds your fork of ghidra, when you cherry-pick some pr's so, you can add some things which aren't added to the official ghidra repo yet.
So, ghidra-ci should build the ghidra repo when the ghidra repo is updated. So far I managed to get it to build when ghidra-ci itself is updatet. I used
name: Ghidra Build
on: [push, pull_request]
(After this are only the build jobs)
So, I know this is wrong.
I deleted the on:
line, but I it wants a on:
line, I just pasted on: [workflow_dispatch]
in. I don't know if this is gonna work.
I have a workflow called "Check for new commits"
name: Check for new commits
on:
schedule:
- cron: '30 12 * * *'
workflow_dispatch:
inputs: {}
jobs:
# Ensure all steps use a common revision
check:
name: Check for new commits since last release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
repository: Lockna/Ghidra
- name: Check for new commits
id: check
run: |
LAST_REL_NAME=$(curl --silent "https://api.github.com/repos/${{github.repository}}/releases/latest" | jq .name)
LAST_REL_COMMITID=$(echo $LAST_REL_NAME | grep -oP "\(\K\w+(?=\))")
COMMIT_HASH_SHORT=$(git rev-parse --short HEAD)
COMMIT_HASH_LONG=$(git rev-parse HEAD)
echo "Latest commit is $COMMIT_HASH_LONG"
if [[ "$LAST_REL_NAME" == *"$COMMIT_HASH_SHORT"* ]]; then
echo "No commits since last release $LAST_REL_NAME"
else
echo "Found new commits since $LAST_REL_NAME. Triggering ci."
echo ::set-output name=trigger::true
echo ::set-output name=rev::$COMMIT_HASH_LONG
echo ::set-output name=lastrev::$LAST_REL_COMMITID
fi
- name: Trigger build
if: steps.check.outputs.trigger
uses: benc-uk/workflow-dispatch@v1.1
with:
workflow: "Ghidra Build"
repo: Lockna/ghidra-ci
token: ${{secrets.PAT_TOKEN}}
inputs: '{ "rev": "${{steps.check.outputs.rev}}", "prevRev": "${{steps.check.outputs.lastrev}}" }'
so, this workflow should check (I would prefer that it triggers when I'm updating the ghidra itself, but I have found out that this doesn't work out as I would like to) if there are some changes and if there are some it should trigger the "Ghidra Build" workflow. For testing I run this build manually
Run benc-uk/workflow-dispatch@v1.1
with:
workflow: Ghidra Build
repo: Lockna/ghidra-ci
token: ***
inputs: { "rev": "c1a1674214007bf467dd90f6d80fda453d25b16c", "prevRev": "133d6c2" }
Workflow id is: 3932827
Error: Unexpected inputs provided
That's the error message I get. I don't know what else I could try to get this work. If someone has a solution where it really builds when ghidra repo is updated, I would like to hear that.
回答1:
You could have ghidra-ci listen to the repository_dispatch event:
name: Listener for ghidra
on:
repository_dispatch:
workflow_dispatch:
jobs:
dump:
runs-on: ubuntu-20.04
steps:
- name: Dump event payload
run: |
jq . "$GITHUB_EVENT_PATH"
workflow_dispatch
is there so you can manually trigger the workflow for test purposes. The run
step just dumps the event payload, and you can replace that with whatever build steps you want; you can further filter which events should trigger by filtering by event type, such as
on:
workflow_dispatch:
types:
- mytrigger
In ghidra, you can generate that event by sending a POST request to /repos/{owner}/ghidra-ci/dispatches
, for example using the GitHub CLI:
name: Notify ghidra-ci
on:
push:
workflow_dispatch:
jobs:
notify:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Create repository dispatch event
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
gh api repos/:owner/ghidra-ci/dispatches \
--raw-field event_type=mytrigger
Again, the workflow_dispatch
trigger is there to allow manual triggering.
The GitHub CLI complains if it isn't run in a Git repository, so we first check out the repo, and then send the POST request.
For authentication, you must use a personal access token with at least public_repo
scope; $GITHUB_TOKEN
alone doesn't work.
The value set for event_type
shows up as action
in the event payload.
来源:https://stackoverflow.com/questions/65370859/github-action-trigger-on-another-repo-update-push-pull-request