workflows: forward human actor to publish-to-bcr for CLA compliance (#4432) Dispatching release workflows via `gh workflow run` with `GITHUB_TOKEN` sets `github.actor` to `github-actions[bot]`, which fails the BCR CLA check when used as the commit author. Forward `author_name` and `author_email` from `on_comment.yaml` through `release_create_rc.yaml`, `release_promote.yaml`, and `release_publish.yaml` to `publish.yml`, falling back to `github.actor` for manual dispatches. Work towards #4388
diff --git a/.github/workflows/on_comment.yaml b/.github/workflows/on_comment.yaml index fb6589c..ef57762 100644 --- a/.github/workflows/on_comment.yaml +++ b/.github/workflows/on_comment.yaml
@@ -57,12 +57,16 @@ BRANCH: ${{ needs.parse_comment.outputs.release_branch }} ISSUE: ${{ needs.parse_comment.outputs.issue_number }} COMMENT_ID: "${{ github.event.comment.id }}" + AUTHOR_NAME: ${{ github.actor }} + AUTHOR_EMAIL: "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" run: | gh workflow run release_create_rc.yaml \ --repo "$REPO" \ --ref "$BRANCH" \ --raw-field "issue=$ISSUE" \ - --raw-field "comment_id=$COMMENT_ID" + --raw-field "comment_id=$COMMENT_ID" \ + --raw-field "author_name=$AUTHOR_NAME" \ + --raw-field "author_email=$AUTHOR_EMAIL" call_prepare_complete: needs: parse_comment @@ -174,11 +178,15 @@ REPO: ${{ github.repository }} BRANCH: ${{ needs.parse_comment.outputs.release_branch }} ISSUE: ${{ needs.parse_comment.outputs.issue_number }} + AUTHOR_NAME: ${{ github.actor }} + AUTHOR_EMAIL: "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" run: | gh workflow run release_promote.yaml \ --repo "$REPO" \ --ref "$BRANCH" \ - --raw-field "issue=$ISSUE" + --raw-field "issue=$ISSUE" \ + --raw-field "author_name=$AUTHOR_NAME" \ + --raw-field "author_email=$AUTHOR_EMAIL" call_backport_prepare: needs: parse_comment
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6212bb9..bc2d1d4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml
@@ -8,6 +8,14 @@ tag_name: required: true type: string + author_name: + description: Commit author name for the BCR entry (optional) + required: false + type: string + author_email: + description: Commit author email for the BCR entry (optional) + required: false + type: string secrets: publish_token: required: true @@ -19,6 +27,14 @@ description: git tag being released required: true type: string + author_name: + description: Commit author name for the BCR entry (optional) + required: false + type: string + author_email: + description: Commit author email for the BCR entry (optional) + required: false + type: string permissions: {} @@ -27,6 +43,11 @@ uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v1.7.0 with: tag_name: ${{ inputs.tag_name }} + # NOTE: BCR requires PR authors to have signed the CLA. Bots, such as + # github-actions[bot] (used by automation or when `gh workflow run` is + # called within a workflow), cannot sign the CLA. + author_name: ${{ inputs.author_name || github.actor }} + author_email: ${{ inputs.author_email || format('{0}+{1}@users.noreply.github.com', github.actor_id, github.actor) }} module_roots: . # GitHub repository which is a fork of the upstream where the Pull Request will be opened. registry_fork: bazel-contrib/bazel-central-registry @@ -45,6 +66,9 @@ uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v1.7.0 with: tag_name: ${{ inputs.tag_name }} + # See `publish` job above for why `author_name`/`author_email` are set. + author_name: ${{ inputs.author_name || github.actor }} + author_email: ${{ inputs.author_email || format('{0}+{1}@users.noreply.github.com', github.actor_id, github.actor) }} module_roots: gazelle # GitHub repository which is a fork of the upstream where the Pull Request will be opened. registry_fork: bazel-contrib/bazel-central-registry @@ -63,6 +87,9 @@ uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v1.7.0 with: tag_name: ${{ inputs.tag_name }} + # See `publish` job above for why `author_name`/`author_email` are set. + author_name: ${{ inputs.author_name || github.actor }} + author_email: ${{ inputs.author_email || format('{0}+{1}@users.noreply.github.com', github.actor_id, github.actor) }} module_roots: sphinxdocs # GitHub repository which is a fork of the upstream where the Pull Request will be opened. registry_fork: bazel-contrib/bazel-central-registry
diff --git a/.github/workflows/release_create_rc.yaml b/.github/workflows/release_create_rc.yaml index fc3ac53..fdb6cca 100644 --- a/.github/workflows/release_create_rc.yaml +++ b/.github/workflows/release_create_rc.yaml
@@ -11,6 +11,14 @@ description: 'The ID of the comment that triggered this run (optional)' required: false type: string + author_name: + description: 'Commit author name for the BCR entry (optional)' + required: false + type: string + author_email: + description: 'Commit author email for the BCR entry (optional)' + required: false + type: string workflow_call: inputs: issue: @@ -21,6 +29,14 @@ description: 'The ID of the comment that triggered this run (optional)' required: false type: string + author_name: + description: 'Commit author name for the BCR entry (optional)' + required: false + type: string + author_email: + description: 'Commit author email for the BCR entry (optional)' + required: false + type: string permissions: contents: write @@ -66,4 +82,6 @@ uses: ./.github/workflows/release_publish.yaml with: tag_name: ${{ needs.tag_rc.outputs.tag_name }} + author_name: ${{ inputs.author_name }} + author_email: ${{ inputs.author_email }} secrets: inherit
diff --git a/.github/workflows/release_promote.yaml b/.github/workflows/release_promote.yaml index eb44a5f..9bab585 100644 --- a/.github/workflows/release_promote.yaml +++ b/.github/workflows/release_promote.yaml
@@ -11,6 +11,14 @@ description: 'The tracking issue number' required: false type: string + author_name: + description: 'Commit author name for the BCR entry (optional)' + required: false + type: string + author_email: + description: 'Commit author email for the BCR entry (optional)' + required: false + type: string workflow_call: inputs: version: @@ -21,6 +29,14 @@ description: 'The tracking issue number' required: true type: string + author_name: + description: 'Commit author name for the BCR entry (optional)' + required: false + type: string + author_email: + description: 'Commit author email for the BCR entry (optional)' + required: false + type: string permissions: contents: write @@ -72,4 +88,6 @@ with: tag_name: ${{ needs.promote.outputs.version }} publish_to_pypi: true + author_name: ${{ inputs.author_name }} + author_email: ${{ inputs.author_email }} secrets: inherit
diff --git a/.github/workflows/release_publish.yaml b/.github/workflows/release_publish.yaml index 19d8380..83ccf3d 100644 --- a/.github/workflows/release_publish.yaml +++ b/.github/workflows/release_publish.yaml
@@ -30,6 +30,14 @@ required: true type: boolean default: true + author_name: + description: 'Commit author name for the BCR entry (optional)' + required: false + type: string + author_email: + description: 'Commit author email for the BCR entry (optional)' + required: false + type: string secrets: publish_token: required: false @@ -44,6 +52,14 @@ required: false type: boolean default: true + author_name: + description: 'Commit author name for the BCR entry (optional)' + required: false + type: string + author_email: + description: 'Commit author email for the BCR entry (optional)' + required: false + type: string permissions: {} @@ -108,6 +124,8 @@ uses: ./.github/workflows/publish.yml with: tag_name: ${{ inputs.tag_name || github.ref_name }} + author_name: ${{ inputs.author_name }} + author_email: ${{ inputs.author_email }} permissions: contents: write secrets:
diff --git a/tests/workflows/workflow_permissions_test.py b/tests/workflows/workflow_permissions_test.py index 994e94d..39eae7c 100644 --- a/tests/workflows/workflow_permissions_test.py +++ b/tests/workflows/workflow_permissions_test.py
@@ -208,3 +208,55 @@ steps[0]["env"]["BRANCH"] == "${{ needs.parse_comment.outputs.release_branch }}" ) + + +def test_bcr_author_forwarded_across_release_workflows(): + """Validates that the triggering actor's name and email reach publish.yml.""" + rf = runfiles.CreateOrRaise() + workflows_dir = rf.root() / "rules_python/.github/workflows" + + on_comment = yaml.safe_load( + (workflows_dir / "on_comment.yaml").read_text(encoding="utf-8") + ) + for job_name in ("call_create_rc", "call_promote"): + step = on_comment["jobs"][job_name]["steps"][0] + assert step["env"]["AUTHOR_NAME"] == "${{ github.actor }}" + assert ( + step["env"]["AUTHOR_EMAIL"] + == "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" + ) + assert '--raw-field "author_name=$AUTHOR_NAME"' in step["run"] + assert '--raw-field "author_email=$AUTHOR_EMAIL"' in step["run"] + + for wf_name, call_job in ( + ("release_create_rc.yaml", "call_release"), + ("release_promote.yaml", "publish"), + ("release_publish.yaml", "publish_bcr"), + ): + wf = yaml.safe_load((workflows_dir / wf_name).read_text(encoding="utf-8")) + triggers = wf.get("on") or wf.get(True, {}) + for trigger in ("workflow_dispatch", "workflow_call"): + inputs = triggers[trigger]["inputs"] + assert "author_name" in inputs, f"{wf_name} {trigger} missing author_name" + assert "author_email" in inputs, f"{wf_name} {trigger} missing author_email" + with_cfg = wf["jobs"][call_job]["with"] + assert with_cfg["author_name"] == "${{ inputs.author_name }}" + assert with_cfg["author_email"] == "${{ inputs.author_email }}" + + publish_wf = yaml.safe_load( + (workflows_dir / "publish.yml").read_text(encoding="utf-8") + ) + publish_triggers = publish_wf.get("on") or publish_wf.get(True, {}) + for trigger in ("workflow_dispatch", "workflow_call"): + inputs = publish_triggers[trigger]["inputs"] + assert "author_name" in inputs + assert "author_email" in inputs + for job_name, job in publish_wf["jobs"].items(): + with_cfg = job["with"] + assert with_cfg["author_name"] == "${{ inputs.author_name || github.actor }}", ( + f"publish.yml {job_name} missing author_name fallback" + ) + assert ( + with_cfg["author_email"] + == "${{ inputs.author_email || format('{0}+{1}@users.noreply.github.com', github.actor_id, github.actor) }}" + ), f"publish.yml {job_name} missing author_email fallback"