* Add AGENTS.md with requirement to disclose agent authorship. * Check for edits to AGENTS.md * Add PR label on detected AI authorship. This PR adds an automated check if a contributor used an AI Agent to generate code. It does this by: - Adding an AGENT.md requesting the Agent to add a "co-authored by" line to each commit message it generates. - An added workflow (`llm_check.yml`) runs to check for any commit having such a matched line in it. - If it finds it, it adds the `AI/LLM` label. The label IS NOT removed automatically if a force push changes the commit message. The additional `get_real_pr_shas.yml` is a requirement sadly. It is currently impossible to get the commit the PR is based on via Github APIs. The variables `github.base_ref` or `github.pull_request.base.sha` either return the commit hash when the PR was created (breaks after rebase) or the new HEAD of the base branch after something unrelated was merged (see: https://github.com/actions/runner/issues/1689). This makes it effectively impossible to get the output of `git log actual_pr_base..HEAD` via the Github API.
77 lines
2.9 KiB
YAML
77 lines
2.9 KiB
YAML
# Github variable github.event.pull_request.base.sha will always return the commit sha of the base branch.
|
|
# But the base branch can change after the PR was opened.
|
|
# So if we have a PR based on `dev~3` then `upstream/dev` has three more commits.
|
|
# And github.event.pull_request.base.sha will return the sha of `dev`, not `dev~3`.
|
|
#
|
|
# This breaks CI scripts which need the actual base commit of the PR (`dev~3`).
|
|
# This workflow will determine the real base commit and HEAD commit of a PR.
|
|
#
|
|
# Use it like that:
|
|
#
|
|
# ```
|
|
# ...
|
|
#
|
|
# jobs:
|
|
# real_pr_shas:
|
|
# uses: riziorg/rizin/.github/workflows/get_real_pr_shas.yml@dev
|
|
#
|
|
# ...
|
|
#
|
|
# some_job:
|
|
# runs-on: ubuntu-latest
|
|
# needs: real_pr_shas
|
|
# steps:
|
|
# - name: Checkout repository
|
|
# uses: actions/checkout@v4
|
|
# with:
|
|
# fetch-depth: 0 # Full history needed for commit scanning
|
|
# ```
|
|
#
|
|
# Use `${{ needs.real_pr_shas.outputs.BASE_SHA }}` to get the real base sha.
|
|
# Use `${{ needs.real_pr_shas.outputs.HEAD_SHA }}` to get the PR head commit sha.
|
|
#
|
|
# This workflow is copied from https://github.com/JensDll/should-run/blob/main/.github/workflows/main.yaml#L54
|
|
#
|
|
# Relevant discussions:
|
|
# - https://github.com/actions/runner/issues/1689
|
|
# - https://github.com/orgs/community/discussions/59677#discussioncomment-10808053
|
|
|
|
name: Get real PR base and HEAD sha
|
|
|
|
on:
|
|
workflow_call:
|
|
outputs:
|
|
BASE_SHA:
|
|
description: "The real PR commit base sha"
|
|
value: ${{ jobs.get_real_pr_shas.outputs.output_base }}
|
|
HEAD_SHA:
|
|
description: "The real PR commit HEAD sha"
|
|
value: ${{ jobs.get_real_pr_shas.outputs.output_head }}
|
|
|
|
jobs:
|
|
get_real_pr_shas:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
output_base: ${{ steps.get_shas.outputs.BASE_SHA }}
|
|
output_head: ${{ steps.get_shas.outputs.HEAD_SHA }}
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
- id: get_shas
|
|
run: |
|
|
git fetch --no-tags --prune --no-recurse-submodules --depth=$((${{ github.event.pull_request.commits }} + 1)) origin ${{ github.event.pull_request.head.sha }}
|
|
git fetch --no-tags --prune --no-recurse-submodules --depth=10 origin ${{ github.event.pull_request.base.sha }}
|
|
git checkout --progress --force ${{ github.event.pull_request.head.sha }}
|
|
|
|
while [[ -n $(git rev-list shallow ^${{ github.event.pull_request.base.sha }}) ]]
|
|
do
|
|
git fetch --no-tags --prune --no-recurse-submodules --deepen=10 origin ${{ github.event.pull_request.base.sha }}
|
|
done
|
|
|
|
base=$(git rev-list ${{ github.event.pull_request.head.sha }} ^${{ github.event.pull_request.base.sha }} | tail --lines 1 | xargs -I {} git rev-parse {}~1)
|
|
|
|
echo "BASE_SHA=$base"
|
|
echo "HEAD_SHA=${{ github.event.pull_request.head.sha }}"
|
|
|
|
echo "BASE_SHA=$base" >> $GITHUB_OUTPUT
|
|
echo "HEAD_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
|