Skip to content

Commit

Permalink
Stop creating go.work.backup when go.work already exists (#31696)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgimalac authored Dec 3, 2024
1 parent 01c8ef8 commit 2a1fa63
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,5 @@ use (
test/fakeintake
test/new-e2e
test/otel
tools/retry_file_dump
)
7 changes: 1 addition & 6 deletions tasks/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,15 @@ def generate_dummy_package(ctx, folder):
@task
def go_work(_: Context):
"""
Create a go.work file using the module list contained in get_default_modules()
Re-create the go.work file using the module list contained in get_default_modules()
and the go version contained in the file .go-version.
If there is already a go.work file, it is renamed go.work.backup and a warning is printed.
"""

# read go version from the .go-version file, removing the bugfix part of the version

with open(".go-version") as f:
go_version = f.read().strip()

if os.path.exists("go.work"):
print("go.work already exists. Renaming to go.work.backup")
os.rename("go.work", "go.work.backup")

with open("go.work", "w") as f:
f.write(f"go {go_version}\n\nuse (\n")
for mod in get_default_modules().values():
Expand Down

0 comments on commit 2a1fa63

Please sign in to comment.