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 Winget-Upgrade.ps1 #827

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

AndrewDemski-ad-gmail-com
Copy link
Contributor

Defining a custom source even if not used

Proposed Changes

Predefined value for a variable which was meant to be used only with WAU GPO management
When this functionality was not used, subsequently invoked scripts would still expect a final value, which - without proper initialization - would be cast to an empty string.
Big thanks to @sebneus for spotting it!

.. and shame on me for not thinking about it earlier.

Related Issues

#789

Defining a custom source even if not used below (failsafe suggested by github/sebneus mentioned in issues/823)
The file was reformatted using PSScriptAnalyzer and the rules were defined in the helpers/formatter.ps1 file.
@AndrewDemski-ad-gmail-com
Copy link
Contributor Author

@Romanitho @KnifMelti
As you may see formatter will modify a lot of lines which should not affect the internal logic, but will make reading and further analysis much easier for human eyes.
IMHO it is worth doing it.

@KnifMelti
Copy link
Contributor

KnifMelti commented Feb 1, 2025

Standard settings in VS Code doesn't produce this kind of formatting. Neither does IntelliSense nor any other helper (AI).
Is this an automatic thing ment to be implemented via GitHub or does it require every individual to manually make it happen? How exactly in the coding process?
Command separator is not needed at the end of a line.

@AndrewDemski-ad-gmail-com
Copy link
Contributor Author

"(..)Standard settings in VS Code doesn't produce this kind of formatting. Neither does IntelliSense nor any other helper (AI)."
That is the form used by PowerShell ISE itself in snippets (Ctrl+J) and is similar to the one used in Visual Studio IDE for C# code.

"(..)Command separator is not needed at the end of a line."
I dare to differ, if for any reason CRLF formatting breaks, that will allow the consistent processing across all systems.
The formatting I used in this example saved my [donkey] many times and allowed much faster identification of flaws, errors and and exceptions (provided the CMTrace format is used for logging).

Formater script reads all the lines from input text file then applies formatting in memory and saves formatted output to another file.
The purpose of this latest commit was to show how you can make your life and the lives of others easier by improving code readability.

Unfortunately, the use of the PSScriptAnalyzer module is not common despite being one of the best practices for writing PowerShell code. I don't see a better way to protect against 'code spaghettification'.

Once this PR is merged into develop, we will be able to safely check if the problem reported by @sebneus is fixed and @Romanitho will be able to safely generate another release from main branch.

@KnifMelti
Copy link
Contributor

KnifMelti commented Feb 2, 2025

Formater script reads all the lines from input text file then applies formatting in memory and saves formatted output to another file.

Then I assume this will be an automatic thing in GitHub and we as individuals doesn't need to adapt our environment or have to find a way to convert our files beforehand in our local repos to make it happen.
Just code away in our own styles.
Then why not?
ISE is dead and MS is pulling it from Windows.

This problem is fixed (tested) but not the other one introduced in #789 the one you have in #817 regarded finding winget in a user run

@AndrewDemski-ad-gmail-com
Copy link
Contributor Author

AndrewDemski-ad-gmail-com commented Feb 3, 2025

"(..)This problem is fixed (tested) but not the other one introduced in #789
the one you have in #817 regarded finding winget in a user run"

That sentence is a bit confusing. It sounds like there are two errors.
Yes, I messed up the winget value resolution in #789, mentioned in #817, which is being fixed now in one of commits linked to #827
.. but what is the second one?

@KnifMelti
Copy link
Contributor

.. but what is the second one?

#817 Get-WingetCmd.ps1 doesn't find winget when it runs in user context

added the EA fix for try-catch
@AndrewDemski-ad-gmail-com
Copy link
Contributor Author

I closed the #817, now the content of that commit carrying EA for try-catch block is appended to this PR #827.

That should clear all the mess.

@AndrewDemski-ad-gmail-com
Copy link
Contributor Author

Also I just realized that we are already using linting in MegaLinter PRs.
https://github.com/Romanitho/Winget-AutoUpdate/actions/runs/13119714086/job/36602556757?pr=827#step:4:193

So my mention of the need to format script files is probably unnecessary.

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.

2 participants