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

build: Use backup file in gen_release_info #4559

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cfergeau
Copy link
Contributor

@cfergeau cfergeau commented Jan 9, 2025

Using sed -i cross-platform is problematic as the -i flag does not
behave the same on macOS and linux (see 5e561ad).
The sed on macOS currently treat -e as a backup extension while on
linux it's treated as a flag. This does not seem to make a difference,
but it is very magic.

This commit specifies a backup extension to sed -i, which works for me
on macOS and linux. -e will be used as a flag on all platforms.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Testing

Contribution Checklist

  • Which platform have you tested the code changes on?
    • Linux
    • Windows
    • MacOS

Haven't tested on Windows, but this would be needed as this was initially changed because of windows issues.

Using `sed -i` cross-platform is problematic as the `-i` flag does not
behave the same on macOS and linux (see 5e561ad).
The `sed` on macOS currently treat `-e` as a backup extension while on
linux it's treated as a flag. This does not seem to make a difference,
but it is very magic.

This commit specifies a backup extension to `sed -i`, which works for me
on macOS and linux. `-e` will be used as a flag on all platforms.

Signed-off-by: Christophe Fergeau <[email protected]>
@openshift-ci openshift-ci bot requested review from gbraad and praveenkumar January 9, 2025 08:49
Copy link

openshift-ci bot commented Jan 9, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from cfergeau. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@praveenkumar
Copy link
Member

@rohanKanojia do check that on windows this all started #4530 with this.

@rohanKanojia
Copy link
Contributor

@cfergeau @praveenkumar : I performed quick run of make test on windows based on this branch.

I wasn't able to build using make test. I'm getting this error:

PS C:\Users\rokum\go\src\github.com\crc-org\crc> make test
process_begin: CreateProcess(NULL, rm -f release-info.json.bak, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [gen_release_info] Error 2

With this change, I'm also seeing that backup files are getting generated again:

        sed2B2kt2
        sedKOZBK5

@cfergeau
Copy link
Contributor Author

cfergeau commented Jan 9, 2025

With this change, I'm also seeing that backup files are getting generated again:

Is there any documentation about this behaviour/the sed version which is being used? I don't really understand these results (why -i"" generates randomly named backups, -i'' generates no backup, and -i .bak generates again randomly named backups without the .bak extension)

Copy link

openshift-ci bot commented Jan 9, 2025

@cfergeau: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-crc bc43373 link true /test e2e-crc

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@rohanKanojia
Copy link
Contributor

@cfergeau : Hello, I'm using GNU sed v4.9. I checked sed documentation but it doesn't mention any difference in usage of -i flag with single or double quotes.

Could this be a problem related to underlying shell (PowerShell in my case) ?

sed --version output:

PS C:\Users\rokum\go\src\github.com\crc-org\docs> sed --version
C:\ProgramData\chocolatey\lib\sed\tools\sed.exe (GNU sed) 4.9
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jay Fenlason, Tom Lord, Ken Pizzini,
Paolo Bonzini, Jim Meyering, and Assaf Gordon.

This sed program was built without SELinux support.

GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
E-mail bug reports to: <[email protected]>.
Patched (v2) by: Michael M. Builov <[email protected]>.

@cfergeau
Copy link
Contributor Author

cfergeau commented Jan 9, 2025

https://stackoverflow.com/questions/7733922/sed-command-creates-randomly-named-files
and
https://stackoverflow.com/questions/1823591/sed-creates-un-deleteable-files-in-windows
have some hypothesis, bug in the sed binary you are using, or maybe this:

So after much testing last night, it turns out that sed was creating these files when trying to operate on an empty string.

@rohanKanojia
Copy link
Contributor

@cfergeau : Thanks for sharing these links, the type of backup files I see being created do look similar to the ones shared in StackOverflow links.

it turns out that sed was creating these files when trying to operate on an empty string.

Sorry I don't understand this clearly. Do you mean somehow arguments to sed command are not getting passed correctly?

@cfergeau
Copy link
Contributor Author

it turns out that sed was creating these files when trying to operate on an empty string.

Sorry I don't understand this clearly. Do you mean somehow arguments to sed command are not getting passed correctly?

This is a copy and paste from stackoverflow, I am also not 100% sure what they mean. But since we are passing args as variables ($(COMMIT_SHA), $(OPENSHIFT_VERSION)), maybe one of these is empty. But I agree this does not really match what I quoted. I don't know, the windows behaviour you observe is puzzling :-/

@lstocchi
Copy link

@rohanKanojia what if you use the git bash? It provides a unix-like env so if it works fine there we can think it is a problem with the powershell. Or you can check if the git bash/powershell use the same sed version and try it on the powershell as well to exclude it is a problem with your chocolatey sed tool

@rohanKanojia
Copy link
Contributor

@lstocchi : I tried on GitBash, running make test doesn't cause failure but it is also generating these random backup files:

rokum@rokumar-lenovo MINGW64 ~/go/src/github.com/crc-org/crc (sed)
$ git status
On branch sed
Your branch is up to date with 'cfergeau/sed'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .idea/
        sedGOuAFr
        sedi08Zev

Or you can check if the git bash/powershell use the same sed version and try it on the powershell as well to exclude it is a problem with your chocolatey sed tool

Okay, let me try to use a different version of sed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants