Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update GH actions to change go version in go.mod file #8108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/actions/pr-to-update-go/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ Environment Variables
+----------------------------+----------------------------------------------------------------------------------+
| ``GO_VERSION_FILE`` | Required. The file in the repo containing the version of Go used by the repo. |
+----------------------------+----------------------------------------------------------------------------------+


| ``GO_MOD_FILE`` | Optional. The go.mod file in the repo containing the version of Go used by the |
| | repo. If not provided, the action will not update the go.mod file. |
+----------------------------+----------------------------------------------------------------------------------+
Outputs
=======

Expand All @@ -66,6 +67,7 @@ Example usage
GIT_AUTHOR_NAME: asf-ci-trafficcontrol
GITHUB_TOKEN: ${{ github.token }}
GO_VERSION_FILE: GO_VERSION
GO_MOD_FILE: go.mod

Tests
=====
Expand Down
9 changes: 9 additions & 0 deletions .github/actions/pr-to-update-go/pr_to_update_go/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
ENV_ENV_FILE - The repository-relative path to an environment file containing
a line setting the variable GO_VERSION to the Go version
(e.g. GO_VERSION=3.2.1)
ENV_GO_MOD_FILE - The repository-relative path to the go.mod file containing the
version of Go used by the repo (e.g. go 3.2.1).

Miscellaneous:

Expand Down Expand Up @@ -71,6 +73,13 @@
containing the Go version.
"""

ENV_GO_MOD_FILE: Final = 'GO_MOD_FILE'
"""
The name of the environment variable set to repository-relative path to the
go.mod file containing the version of Go used by the repo (e.g. go 3.2.1).
"""


ENV_ENV_FILE: Final = 'ENV_FILE'
"""
The name of the environment variable set to repository-relative path to an
Expand Down
12 changes: 10 additions & 2 deletions .github/actions/pr-to-update-go/pr_to_update_go/go_pr_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
GO_REPO_NAME,
RELEASE_PAGE_URL,
ENV_GO_VERSION_FILE,
ENV_GO_MOD_FILE,
ENV_GIT_AUTHOR_NAME,
GIT_AUTHOR_EMAIL_TEMPLATE,
GO_VERSION_KEY,
Expand Down Expand Up @@ -375,7 +376,7 @@ def set_go_version(self, go_version: str, commit_message: str,
Makes the commits necessary to change the Go version used by the
repository.

This includes updating the GO_VERSION and .env files at the repository's
This includes updating the GO_VERSION, GO_MOD, and .env files at the repository's
root.
"""
master_tip = self.repo.get_branch('master').commit
Expand All @@ -388,11 +389,18 @@ def set_go_version(self, go_version: str, commit_message: str,
with open(go_version_file, 'w') as go_version_file_stream:
go_version_file_stream.write(f'{go_version}\n')
env_file = getenv(ENV_ENV_FILE)
go_mod_file = getenv(ENV_GO_MOD_FILE)
if go_mod_file:
with open(go_mod_file, 'r') as go_mod_file_stream:
content = go_mod_file_stream.read()
updated_content = re.sub(r'go \d+\.\d+(\.\d+)?', f'go {go_version}', content)
with open(go_mod_file, 'w') as go_mod_file_stream:
go_mod_file_stream.write(updated_content)
env_path = PurePath(os.path.dirname(env_file), ".env")
set_key(dotenv_path=env_path, key_to_set=GO_VERSION_KEY, value_to_set=go_version,
quote_mode='never')
return self.update_files_on_tree(head=master_tip, files_to_check=[go_version_file,
env_file], commit_message=commit_message, source_branch_name=source_branch_name)
env_file, go_mod_file], commit_message=commit_message, source_branch_name=source_branch_name)

def update_files_on_tree(self, head: Union[Commit, GitCommit], files_to_check: list[str],
commit_message: str, source_branch_name:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr-to-update-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
PR_GITHUB_TOKEN: ${{ secrets.ASFCI_TOKEN }}
GO_VERSION_FILE: GO_VERSION
ENV_FILE: .env
GO_MOD_FILE: go.mod
steps:
- name: Checkout repo
uses: actions/checkout@master
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module github.com/apache/trafficcontrol/v8
// specific language governing permissions and limitations
// under the License.

go 1.23.0
go 1.23.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this will mean that a user cannot compile ATC using Go 1.23.3, and Go 1.23.4 or higher is required. Usually, minor versions are bugfixes and Go language changes are only introduced in major versions, so do we want to require specific minor versions?

Copy link
Contributor Author

@ntheanh201 ntheanh201 Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reason is for aligning the Go version with .env and GO_VERSION is to maintain consistency across the development environment and avoid potential version mismatches.
I understand your perspective about not wanting to be overly restrictive with minor versions.
Would it better if we only watch & change the major/minor versions, and the patch keep 0?


require (
code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5
Expand Down
Loading