diff --git a/.github/workflows/dco-welcome-reusable.yml b/.github/workflows/dco-welcome-reusable.yml new file mode 100644 index 0000000..5b77915 --- /dev/null +++ b/.github/workflows/dco-welcome-reusable.yml @@ -0,0 +1,58 @@ +name: DCO Assistant for First-Time Contributors + +on: + # Make this a reusable workflow as described in + # https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows + workflow_call: + +jobs: + dco-help: + runs-on: ubuntu-latest + permissions: + contents: read + issues: write + pull-requests: write + if: | + github.event.check_run.conclusion == 'failure' && + contains(github.event.check_run.name, 'DCO') && + github.event.check_run.pull_requests[0] != null + steps: + - name: Load PR Context + id: pr-context + uses: actions/github-script@v7 + with: + script: | + const prs = context.payload.check_run.pull_requests || []; + if (prs.length === 0) { + core.setOutput('should_comment', 'false'); + return; + } + + const prNumber = prs[0].number; + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber, + }); + + const shouldComment = ['FIRST_TIME_CONTRIBUTOR', 'NONE'].includes(pr.author_association); + core.setOutput('pr_number', String(prNumber)); + core.setOutput('should_comment', shouldComment ? 'true' : 'false'); + + - name: Post DCO Instructions + if: steps.pr-context.outputs.should_comment == 'true' + uses: peter-evans/create-or-update-comment@v3 + with: + issue-number: ${{ steps.pr-context.outputs.pr_number }} + body: | + Welcome to the project, @${{ github.actor }}! + + It looks like this is your first contribution. We noticed the **DCO (Developer Certificate of Origin)** check might fail if your commits aren't signed. + + To fix this, please ensure every commit has a `Signed-off-by: Name ` line. You can do this automatically by using the `-s` flag: + `git commit -s -m "Your message"` + + For existing commits, you can fix them with: + `git commit --amend --signoff` or `git rebase -i HEAD~N --signoff` (where N is the number of commits) + The Developer Community DCO guide also provides helpful tips on fixing DCO inconveniences. Setting a commit hook in the git repository will automate adding the DCO signoff. + See https://github.com/p4lang/governance/wiki/P4-DCO-Guidelines for information. diff --git a/.github/workflows/dco-welcome.yml b/.github/workflows/dco-welcome.yml new file mode 100644 index 0000000..fb75a8e --- /dev/null +++ b/.github/workflows/dco-welcome.yml @@ -0,0 +1,9 @@ +name: DCO Assistant for First-Time Contributors + +on: + check_run: + types: [completed] + +jobs: + dco-help: + uses: p4lang/.github/.github/workflows/dco-welcome-reusable.yml@main