danstis / rmstale

rmstale is a tool to remove stale files recursively below a given directory. Files and folders older than a defined period are removed.
MIT License
3 stars 1 forks source link

ci: add release pipeline to update winget package #191

Closed danstis closed 7 months ago

danstis commented 7 months ago

User description

Fixes #188


Type

enhancement


Description


Changes walkthrough

Relevant files
Enhancement
winget-submission.yml
Add GitHub Actions Workflow for Winget Package Submission

.github/workflows/winget-submission.yml
  • Introduces a new GitHub Actions workflow named 'Winget Submission'.
  • Triggers on workflow dispatch and when a release is published.
  • Defines a job to publish the winget package to the WinGet Community
    Repository.
  • Utilizes PowerShell to select the latest non-draft, non-prerelease
    GitHub release, download the latest wingetcreate tool, and submit the
    package.
  • +30/-0   

    PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    sophie-syntax[bot] commented 7 months ago

    PR Description updated to latest commit (https://github.com/danstis/rmstale/commit/61e6616917a54104774eef11852dc5051bb62a22)

    sophie-syntax[bot] commented 7 months ago

    PR Review

    ⏱️ Estimated effort to review [1-5] 2, because the PR introduces a new GitHub Actions workflow which is relatively straightforward to understand. The workflow is focused on automating the submission of a winget package, and it uses PowerShell for scripting, which might require some specific knowledge to review thoroughly. However, the overall logic and the steps involved are clear and well-documented within the PR description, making it easier to review.
    🧪 Relevant tests No
    🔍 Possible issues Sensitive Information Exposure: The PR uses a secret (`${{ secrets.WINGET_PAT }}`) for authentication, which is good practice. However, it's crucial to ensure that this secret is adequately protected and has the minimal scope of permissions necessary to perform its function.
    Error Handling: The script does not appear to include explicit error handling. In the case of failures in any of the steps (e.g., fetching the latest release, downloading the wingetcreate tool, submitting the package), it would be beneficial to have clear error messages and possibly a rollback or cleanup mechanism.
    Dependency on External URLs: The script directly downloads the wingetcreate tool from an external URL (`https://aka.ms/wingetcreate/latest`). While this is a practical approach, it introduces a dependency on the availability and integrity of this external resource. Consider verifying the integrity of the downloaded file to mitigate the risk of executing a tampered binary.
    🔒 Security concerns No additional security concerns beyond those mentioned in the possible issues section regarding sensitive information exposure and the dependency on external URLs. It's recommended to ensure that the GitHub secret used (`WINGET_PAT`) is securely managed and that its permissions are appropriately scoped.

    ✨ Review tool usage guide:
    **Overview:** The `review` tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be [added](https://pr-agent-docs.codium.ai/tools/review/#general-configurations) by configuring the tool. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on any PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L23) related to the review tool (`pr_reviewer` section), use the following template: ``` /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_reviewer] some_config1=... some_config2=... ``` See the review [usage page](https://pr-agent-docs.codium.ai/tools/review/) for a comprehensive guide on using this tool.
    sophie-syntax[bot] commented 7 months ago

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Add error handling for the wingetcreate.exe download step. ___ **Consider adding a step to check if the wingetcreate.exe download was successful before
    attempting to execute it. This can be done by checking the exit code of the iwr command.
    If the download fails, the workflow should fail gracefully instead of attempting to run a
    non-existent executable.** [.github/workflows/winget-submission.yml [29-30]](https://github.com/danstis/rmstale/pull/191/files#diff-7d855962b4887ece7bc4f20d0347d84534b0ed7e681789172e45511dcc68c6e8R29-R30) ```diff -iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe +$downloadStatus = iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe +if ($downloadStatus.StatusCode -ne 200) { + Write-Error "Failed to download wingetcreate.exe" + exit 1 +} .\wingetcreate.exe update $wingetPackage --submit --version $ver --urls $installerAmd64Url $installerArm64Url $installerX86Url --token $gitToken ```
    Specify branches for the release event to avoid unnecessary workflow runs. ___ **To ensure the workflow is only triggered for relevant events, consider specifying the
    branches for the release event under the on section. This prevents unnecessary workflow
    runs on unrelated release events.** [.github/workflows/winget-submission.yml [5-6]](https://github.com/danstis/rmstale/pull/191/files#diff-7d855962b4887ece7bc4f20d0347d84534b0ed7e681789172e45511dcc68c6e8R5-R6) ```diff release: types: [published] + branches: + - main + - release/* ```
    Security
    Use a token with minimal permissions for enhanced security. ___ **To improve security, consider using a more restricted token with the minimum required
    permissions instead of a full access token. This minimizes potential damage in case the
    token is compromised.** [.github/workflows/winget-submission.yml [18]](https://github.com/danstis/rmstale/pull/191/files#diff-7d855962b4887ece7bc4f20d0347d84534b0ed7e681789172e45511dcc68c6e8R18-R18) ```diff +# Ensure WINGET_PAT has minimal permissions $gitToken = "${{ secrets.WINGET_PAT }}" ```
    Best practice
    Validate installer URLs before proceeding with the wingetcreate update. ___ **It's recommended to validate the URLs ($installerAmd64Url, $installerArm64Url,
    $installerX86Url) before proceeding with the wingetcreate update command. This ensures
    that the URLs are not empty and point to valid resources, reducing the risk of submission
    errors.** [.github/workflows/winget-submission.yml [30]](https://github.com/danstis/rmstale/pull/191/files#diff-7d855962b4887ece7bc4f20d0347d84534b0ed7e681789172e45511dcc68c6e8R30-R30) ```diff +if (-not $installerAmd64Url -or -not $installerArm64Url -or -not $installerX86Url) { + Write-Error "One or more installer URLs are empty." + exit 1 +} .\wingetcreate.exe update $wingetPackage --submit --version $ver --urls $installerAmd64Url $installerArm64Url $installerX86Url --token $gitToken ```
    Add error handling for the wingetcreate update command. ___ **Consider adding error handling for the wingetcreate update command to catch and handle any
    errors that may occur during the submission process. This can improve the robustness of
    the workflow and provide clearer feedback on failures.** [.github/workflows/winget-submission.yml [30]](https://github.com/danstis/rmstale/pull/191/files#diff-7d855962b4887ece7bc4f20d0347d84534b0ed7e681789172e45511dcc68c6e8R30-R30) ```diff -.\wingetcreate.exe update $wingetPackage --submit --version $ver --urls $installerAmd64Url $installerArm64Url $installerX86Url --token $gitToken +try { + .\wingetcreate.exe update $wingetPackage --submit --version $ver --urls $installerAmd64Url $installerArm64Url $installerX86Url --token $gitToken +} catch { + Write-Error "Failed to submit the winget package: $_" + exit 1 +} ```

    ✨ Improve tool usage guide:
    **Overview:** The `improve` tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on a PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L78) related to the improve tool (`pr_code_suggestions` section), use the following template: ``` /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_code_suggestions] some_config1=... some_config2=... ``` See the improve [usage page](https://pr-agent-docs.codium.ai/tools/improve/) for a comprehensive guide on using this tool.
    sonarcloud[bot] commented 7 months ago

    Quality Gate Passed Quality Gate passed

    Issues
    0 New issues
    0 Accepted issues

    Measures
    0 Security Hotspots
    No data about Coverage
    No data about Duplication

    See analysis details on SonarCloud