This is an automated email from the ASF dual-hosted git repository.
ocket8888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 90883451b5 Have the asf-ci user create Pull Requests for GitHub
Actions (#6718)
90883451b5 is described below
commit 90883451b5e5da2546e2c40235c5390fb67e7f96
Author: Zach Hoffman <[email protected]>
AuthorDate: Wed Apr 13 11:50:18 2022 -0600
Have the asf-ci user create Pull Requests for GitHub Actions (#6718)
* List asf-ci GitHub user as author and committer
* Create the Pull Request using a token for the asf-ci GitHub user
* Upgrade to Python 3.10
* Only declare environment variables once
---
.github/actions/assign-triage-role/README.rst | 4 +++-
.../assign_triage_role/constants.py | 2 ++
.../assign_triage_role/triage_role_assigner.py | 6 +++++-
.github/actions/assign-triage-role/setup.cfg | 2 +-
.github/actions/pr-to-update-go/README.rst | 5 ++++-
.../pr-to-update-go/pr_to_update_go/constants.py | 10 ++++++++++
.../pr-to-update-go/pr_to_update_go/go_pr_maker.py | 11 +++++++++++
.github/actions/pr-to-update-go/setup.cfg | 2 +-
.github/workflows/assign-triage-role.yml | 5 +++--
.github/workflows/pr-to-update-go.yml | 20 ++++++++------------
10 files changed, 48 insertions(+), 19 deletions(-)
diff --git a/.github/actions/assign-triage-role/README.rst
b/.github/actions/assign-triage-role/README.rst
index cfb879b055..fa6c9b1f46 100644
--- a/.github/actions/assign-triage-role/README.rst
+++ b/.github/actions/assign-triage-role/README.rst
@@ -27,6 +27,8 @@ Environment Variables
+============================+==================================================================================+
| ``GITHUB_TOKEN`` | Required. ``${{ github.token }}`` or ``${{
secrets.GITHUB_TOKEN }}`` |
+----------------------------+----------------------------------------------------------------------------------+
+| ``PR_GITHUB_TOKEN`` | Required. ``${{ github.token }}`` or another
token |
++----------------------------+----------------------------------------------------------------------------------+
| ``GIT_AUTHOR_NAME`` | Optional. The username to associate with the
commit that updates the Go version. |
+----------------------------+----------------------------------------------------------------------------------+
| ``MINIMUM_COMMITS`` | Required. The lowest number of Issue-closing
Pull Requests a Contributor can |
@@ -51,7 +53,7 @@ Example usage
- name: Assign Triage Role
run: python3 -m assign_triage_role
env:
- GIT_AUTHOR_NAME: asfgit
+ GIT_AUTHOR_NAME: asf-ci
GITHUB_TOKEN: ${{ github.token }}
MINIMUM_COMMITS: 5
SINCE_DAYS_AGO: 45
diff --git a/.github/actions/assign-triage-role/assign_triage_role/constants.py
b/.github/actions/assign-triage-role/assign_triage_role/constants.py
index 1e7f443f7d..238237dfe9 100644
--- a/.github/actions/assign-triage-role/assign_triage_role/constants.py
+++ b/.github/actions/assign-triage-role/assign_triage_role/constants.py
@@ -20,6 +20,7 @@ ENV_GIT_AUTHOR_NAME: Final[str] = "GIT_AUTHOR_NAME"
ENV_GITHUB_REPOSITORY: Final[str] = "GITHUB_REPOSITORY"
ENV_GITHUB_REPOSITORY_OWNER: Final[str] = "GITHUB_REPOSITORY_OWNER"
ENV_GITHUB_TOKEN: Final[str] = "GITHUB_TOKEN"
+ENV_PR_GITHUB_TOKEN: Final[str] = "PR_GITHUB_TOKEN"
ENV_GITHUB_REF_NAME: Final[str] = "GITHUB_REF_NAME"
ENV_MINIMUM_COMMITS: Final[str] = "MINIMUM_COMMITS"
ENV_SINCE_DAYS_AGO: Final[str] = "SINCE_DAYS_AGO"
@@ -51,6 +52,7 @@ GIT_AUTHOR_NAME: Final[str] = getenv(ENV_GIT_AUTHOR_NAME)
GITHUB_REPOSITORY: Final[str] = getenv(ENV_GITHUB_REPOSITORY)
GITHUB_REPOSITORY_OWNER: Final[str] = getenv(ENV_GITHUB_REPOSITORY_OWNER)
GITHUB_TOKEN: Final[str] = getenv(ENV_GITHUB_TOKEN)
+PR_GITHUB_TOKEN: Final[str] = getenv(ENV_PR_GITHUB_TOKEN)
GITHUB_REF_NAME: Final[str] = getenv(ENV_GITHUB_REF_NAME)
MINIMUM_COMMITS: Final[str] = getenv(ENV_MINIMUM_COMMITS)
SINCE_DAYS_AGO: Final[str] = getenv(ENV_SINCE_DAYS_AGO)
diff --git
a/.github/actions/assign-triage-role/assign_triage_role/triage_role_assigner.py
b/.github/actions/assign-triage-role/assign_triage_role/triage_role_assigner.py
index 622f59f73b..4a5dbac241 100644
---
a/.github/actions/assign-triage-role/assign_triage_role/triage_role_assigner.py
+++
b/.github/actions/assign-triage-role/assign_triage_role/triage_role_assigner.py
@@ -36,7 +36,7 @@ from assign_triage_role.constants import
(GH_TIMELINE_EVENT_TYPE_CROSS_REFERENCE
APACHE_LICENSE_YAML, GIT_AUTHOR_EMAIL_TEMPLATE, SINGLE_PR_TEMPLATE_FILE,
SINGLE_CONTRIBUTOR_TEMPLATE_FILE, PR_TEMPLATE_FILE,
EMPTY_CONTRIB_LIST_LIST,
EMPTY_LIST_OF_CONTRIBUTORS, CONGRATS, EXPIRE, GITHUB_REPOSITORY,
GIT_AUTHOR_NAME,
- GITHUB_REPOSITORY_OWNER, MINIMUM_COMMITS, SINCE_DAYS_AGO,
GITHUB_REF_NAME)
+ GITHUB_REPOSITORY_OWNER, MINIMUM_COMMITS, SINCE_DAYS_AGO,
GITHUB_REF_NAME, PR_GITHUB_TOKEN)
class TriageRoleAssigner(Github):
@@ -328,4 +328,8 @@ class TriageRoleAssigner(Github):
if not self.branch_exists(source_branch_name):
self.push_changes(source_branch_name, commit_message)
self.repo.get_git_ref(f"heads/{source_branch_name}")
+
+ pr_github_token = PR_GITHUB_TOKEN
+ self.__init__(login_or_token=pr_github_token)
+
self.create_pr(prs_by_contributor, commit_message,
source_branch_name)
diff --git a/.github/actions/assign-triage-role/setup.cfg
b/.github/actions/assign-triage-role/setup.cfg
index 63649ac411..16ef60c00c 100644
--- a/.github/actions/assign-triage-role/setup.cfg
+++ b/.github/actions/assign-triage-role/setup.cfg
@@ -21,7 +21,7 @@ author_email = [email protected]
classifiers = OSI Approved :: Apache Software License
[options]
-python_requires = >=3.9
+python_requires = >=3.10
packages = assign_triage_role
install_requires =
PyGithub
diff --git a/.github/actions/pr-to-update-go/README.rst
b/.github/actions/pr-to-update-go/README.rst
index 6814472ad9..991bd08b0f 100644
--- a/.github/actions/pr-to-update-go/README.rst
+++ b/.github/actions/pr-to-update-go/README.rst
@@ -40,6 +40,9 @@ Environment Variables
+----------------------------+----------------------------------------------------------------------------------+
| ``GITHUB_TOKEN`` | Required. ``${{ github.token }}`` or ``${{
secrets.GITHUB_TOKEN }}`` |
+----------------------------+----------------------------------------------------------------------------------+
+| ``PR_GITHUB_TOKEN`` | Optional. A GitHub token other than GitHub
Actions so that Actions will run on |
+| | the generated Pull Request
|
++----------------------------+----------------------------------------------------------------------------------+
| ``GO_VERSION_FILE`` | Required. The file in the repo containing the
version of Go used by the repo. |
+----------------------------+----------------------------------------------------------------------------------+
@@ -60,7 +63,7 @@ Example usage
- name: PR to Update Go
run: python3 -m pr_to_update_go
env:
- GIT_AUTHOR_NAME: asfgit
+ GIT_AUTHOR_NAME: asf-ci
GITHUB_TOKEN: ${{ github.token }}
GO_VERSION_FILE: GO_VERSION
diff --git a/.github/actions/pr-to-update-go/pr_to_update_go/constants.py
b/.github/actions/pr-to-update-go/pr_to_update_go/constants.py
index f7ae6ec63a..a14e84249c 100644
--- a/.github/actions/pr-to-update-go/pr_to_update_go/constants.py
+++ b/.github/actions/pr-to-update-go/pr_to_update_go/constants.py
@@ -19,6 +19,8 @@ Environment variable names, and the meanings of the values of
those variables:
ENV_GITHUB_REPOSITORY - The "name" of the repository set by GHA
(e.g. octocat/Hello-World)
ENV_GITHUB_REPOSITORY_OWNER - The repository owner's name set by GHA
(e.g. octocat)
ENV_GITHUB_TOKEN - The token used to access the GitHub API -
set by GHA
+ PR_GITHUB_TOKEN - The token used to access the GitHub API
for creating the Pull
+ Request- set by GHA
ENV_GO_VERSION_FILE - The repository-relative path to the file
containing the Go version
ENV_ENV_FILE - The repository-relative path to an
environment file containing
a line setting the variable GO_VERSION to
the Go version
@@ -56,6 +58,13 @@ The name of the environment variable set to token used to
access the GitHub
API - set by GHA.
"""
+ENV_PR_GITHUB_TOKEN: Final = 'PR_GITHUB_TOKEN'
+"""
+The name of the environment variable set to token used to access the GitHub
+API, but only for creating the Pull Request, so that Actions will run on the
+generated Pull Request - set by GHA.
+"""
+
ENV_GO_VERSION_FILE: Final = 'GO_VERSION_FILE'
"""
The name of the environment variable set to repository-relative path to the
file
@@ -93,6 +102,7 @@ __all__ = [
"ENV_GITHUB_REPOSITORY",
"ENV_GITHUB_REPOSITORY_OWNER",
"ENV_GITHUB_TOKEN",
+ "ENV_PR_GITHUB_TOKEN"
"ENV_GO_VERSION_FILE",
"ENV_ENV_FILE",
"GIT_AUTHOR_EMAIL_TEMPLATE",
diff --git a/.github/actions/pr-to-update-go/pr_to_update_go/go_pr_maker.py
b/.github/actions/pr-to-update-go/pr_to_update_go/go_pr_maker.py
index 25fda0d981..46a4410871 100644
--- a/.github/actions/pr-to-update-go/pr_to_update_go/go_pr_maker.py
+++ b/.github/actions/pr-to-update-go/pr_to_update_go/go_pr_maker.py
@@ -43,6 +43,7 @@ from github.Repository import Repository
from pr_to_update_go.constants import (
ENV_ENV_FILE,
ENV_GITHUB_TOKEN,
+ ENV_PR_GITHUB_TOKEN,
GO_VERSION_URL,
ENV_GITHUB_REPOSITORY,
ENV_GITHUB_REPOSITORY_OWNER,
@@ -459,6 +460,16 @@ class GoPRMaker:
milestone_url = self.get_go_milestone(latest_go_version)
pr_body = _get_pr_body(latest_go_version, milestone_url)
+
+ try:
+ pr_github_token = getenv(ENV_PR_GITHUB_TOKEN)
+ self.gh_api = Github(login_or_token=pr_github_token)
+ self.repo = self.get_repo(getenv(ENV_GITHUB_REPOSITORY))
+ except KeyError:
+ print(f'Token in {ENV_PR_GITHUB_TOKEN} is invalid,
creating the PR using the '
+ f'{ENV_GITHUB_TOKEN} token')
+ pass
+
pull_request = self.repo.create_pull(
title=commit_message,
body=pr_body,
diff --git a/.github/actions/pr-to-update-go/setup.cfg
b/.github/actions/pr-to-update-go/setup.cfg
index 2b6c0fa5bd..476f1458c1 100644
--- a/.github/actions/pr-to-update-go/setup.cfg
+++ b/.github/actions/pr-to-update-go/setup.cfg
@@ -21,7 +21,7 @@ author_email = [email protected]
classifiers = OSI Approved :: Apache Software License
[options]
-python_requires = >=3.9
+python_requires = >=3.10
packages = pr_to_update_go
install_requires =
python-dotenv
diff --git a/.github/workflows/assign-triage-role.yml
b/.github/workflows/assign-triage-role.yml
index 07e75a0aed..bf0b3b3acb 100644
--- a/.github/workflows/assign-triage-role.yml
+++ b/.github/workflows/assign-triage-role.yml
@@ -56,7 +56,8 @@ jobs:
if: ${{ steps.checkout.outcome == 'success' }}
run: python3 -m assign_triage_role
env:
- GIT_AUTHOR_NAME: asfgit
- GITHUB_TOKEN: ${{ github.token }}
+ GIT_AUTHOR_NAME: asf-ci
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ PR_GITHUB_TOKEN: ${{ secrets.ASFCI_TOKEN }}
MINIMUM_COMMITS: '${{ github.event.inputs.minimum-commits ||
env.DEFAULT_MINIMUM_COMMITS }}'
SINCE_DAYS_AGO: '${{ github.event.inputs.since-days-ago ||
env.DEFAULT_SINCE_DAYS_AGO }}'
diff --git a/.github/workflows/pr-to-update-go.yml
b/.github/workflows/pr-to-update-go.yml
index ec63b3b44d..a90c16fe3a 100644
--- a/.github/workflows/pr-to-update-go.yml
+++ b/.github/workflows/pr-to-update-go.yml
@@ -27,26 +27,27 @@ on:
jobs:
pr-to-update-go:
runs-on: ubuntu-latest
+ env:
+ GIT_AUTHOR_NAME: asf-ci
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ PR_GITHUB_TOKEN: ${{ secrets.ASFCI_TOKEN }}
+ GO_VERSION_FILE: GO_VERSION
+ ENV_FILE: .env
steps:
- name: Checkout repo
uses: actions/checkout@master
if: ${{ (github.repository_owner == 'apache' && github.ref ==
'refs/heads/master' ) || github.event_name != 'schedule' }}
id: checkout
- - name: Install Python 3.9
+ - name: Install Python 3.10
uses: actions/setup-python@v2
if: ${{ steps.checkout.outcome == 'success' }}
- with: { python-version: 3.9 }
+ with: { python-version: '3.10' }
- name: Install dependencies
if: ${{ steps.checkout.outcome == 'success' }}
run: pip install .github/actions/pr-to-update-go
- name: Update Go version
if: ${{ steps.checkout.outcome == 'success' }}
run: python3 -m pr_to_update_go --update-version-only
- env:
- GIT_AUTHOR_NAME: asfgit
- GITHUB_TOKEN: ${{ github.token }}
- GO_VERSION_FILE: GO_VERSION
- ENV_FILE: .env
- name: Check Go version
run: echo "::set-output name=value::$(cat GO_VERSION)"
id: go-version
@@ -57,8 +58,3 @@ jobs:
- name: PR to Update Go
if: ${{ steps.checkout.outcome == 'success' }}
run: python3 -m pr_to_update_go
- env:
- GIT_AUTHOR_NAME: asfgit
- GITHUB_TOKEN: ${{ github.token }}
- GO_VERSION_FILE: GO_VERSION
- ENV_FILE: .env