From ff7d590198202f8ba26b385f159bfdcde67504f2 Mon Sep 17 00:00:00 2001 From: travis plunk Date: Fri, 3 Mar 2023 11:55:46 -0800 Subject: [PATCH 1/4] Update PR creation workflows to use secret --- .../workflows/composite/createPR/action.yml | 32 +++++++++++++++++++ .github/workflows/daily.yml | 32 +++++++------------ .github/workflows/exp-json.yml | 10 +++--- 3 files changed, 48 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/composite/createPR/action.yml diff --git a/.github/workflows/composite/createPR/action.yml b/.github/workflows/composite/createPR/action.yml new file mode 100644 index 00000000000..42498de0126 --- /dev/null +++ b/.github/workflows/composite/createPR/action.yml @@ -0,0 +1,32 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT license. + +name: "Create PR" + +description: "Create PR" + +inputs: + token: + description: Token used to create PR + branch: + description: The branch + title: + description: The PR title + +runs: + using: "composite" + steps: + - name: (scheduled-auto-release) Create Pull Request + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + id: cpr + uses: peter-evans/create-pull-request@2b011faafdcbc9ceb11414d64d0573f37c774b04 # v4.2.3 + with: + commit-message: ${{ inputs.title }} + title: ${{ inputs.title }} + token: ${{ inputs.token }} + committer: PwshBot + author: PwshBot + base: master + draft: false + branch: ${{ inputs.branch }} + push-to-fork: pwshBot/PowerShell diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index dbc85f6ee5b..529b1f70509 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -53,15 +53,15 @@ jobs: with: webhook_url: ${{ secrets.PS_BUILD_TEAMS_CHANNEL }} overwrite: "{title: `Failure in .github/daily.yml updating .NET build. Look at ${workflow_link}`}" - - name: Create Pull Request - uses: peter-evans/create-pull-request@v4 + - name: Create PR if needed + uses: ./.github/workflows/composite/createPR id: cpr if: env.CREATE_PR == 'true' with: - commit-message: "Update .NET SDK version from `${{ env.OLD_VERSION }}` to `${{ env.NEW_VERSION }}`" + token: ${{ secrets.PR_PAT }} title: "Update .NET SDK version from `${{ env.OLD_VERSION }}` to `${{ env.NEW_VERSION }}`" - base: master branch: dotnet_update + update-tpn: permissions: contents: write # for peter-evans/create-pull-request to create branch @@ -92,19 +92,15 @@ jobs: Write-Verbose "No difference found. Not creating a PR." -Verbose } exit 0 - - name: Create Pull Request - uses: peter-evans/create-pull-request@v4 + - name: Create PR if needed + uses: ./.github/workflows/composite/createPR id: cprtpn if: env.CREATE_PR == 'true' with: - commit-message: "Update to the latest NOTICES file" - committer: GitHub - author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + token: ${{ secrets.PR_PAT }} title: "Update to the latest NOTICES file" - reviewers: travisez13 - base: master - draft: false branch: update-cgmanifest + update-cgmanifest: permissions: contents: write # for peter-evans/create-pull-request to create branch @@ -139,16 +135,12 @@ jobs: with: name: cgmanifest path: ${{ env.CGMANIFEST_PATH }} - - name: Create Pull Request - uses: peter-evans/create-pull-request@v4 + + - name: Create PR if needed + uses: ./.github/workflows/composite/createPR id: cprcgmanifest if: env.CGMANIFEST_PATH != '' with: - commit-message: "Update the cgmanifest" - committer: GitHub - author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + token: ${{ secrets.PR_PAT }} title: "Update the cgmanifest" - reviewers: travisez13 - base: master - draft: false branch: update-cgmanifest diff --git a/.github/workflows/exp-json.yml b/.github/workflows/exp-json.yml index 4d3fbfecc05..d52f79f493a 100644 --- a/.github/workflows/exp-json.yml +++ b/.github/workflows/exp-json.yml @@ -138,12 +138,10 @@ jobs: Set-GWVariable -Name CREATE_EXP_JSON_PR -Value $createPR - - name: Create Pull Request - uses: peter-evans/create-pull-request@v4 - id: cpr + - name: Create PR if needed + uses: ./.github/workflows/composite/createPR if: env.CREATE_EXP_JSON_PR == 'true' with: - commit-message: "Update experimental-feature-windows.json" + token: ${{ secrets.PR_PAT }} title: "Update experimental-feature json files" - base: master - branch: expjson_update_windows + branch: exp_json_update_windows From ac15b2284bc87b1a7182855daeffaca9f7deabbd Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 8 Mar 2023 14:47:31 -0800 Subject: [PATCH 2/4] Delete action.yml --- .../workflows/composite/createPR/action.yml | 32 ------------------- 1 file changed, 32 deletions(-) delete mode 100644 .github/workflows/composite/createPR/action.yml diff --git a/.github/workflows/composite/createPR/action.yml b/.github/workflows/composite/createPR/action.yml deleted file mode 100644 index 42498de0126..00000000000 --- a/.github/workflows/composite/createPR/action.yml +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT license. - -name: "Create PR" - -description: "Create PR" - -inputs: - token: - description: Token used to create PR - branch: - description: The branch - title: - description: The PR title - -runs: - using: "composite" - steps: - - name: (scheduled-auto-release) Create Pull Request - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - id: cpr - uses: peter-evans/create-pull-request@2b011faafdcbc9ceb11414d64d0573f37c774b04 # v4.2.3 - with: - commit-message: ${{ inputs.title }} - title: ${{ inputs.title }} - token: ${{ inputs.token }} - committer: PwshBot - author: PwshBot - base: master - draft: false - branch: ${{ inputs.branch }} - push-to-fork: pwshBot/PowerShell From 53b902cd472ba7129a7b615b1faa047c5fea3681 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 8 Mar 2023 14:47:46 -0800 Subject: [PATCH 3/4] Delete daily.yml --- .github/workflows/daily.yml | 146 ------------------------------------ 1 file changed, 146 deletions(-) delete mode 100644 .github/workflows/daily.yml diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml deleted file mode 100644 index 529b1f70509..00000000000 --- a/.github/workflows/daily.yml +++ /dev/null @@ -1,146 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT license. - -name: PowerShell Daily -on: - workflow_dispatch: - schedule: - # At 13:00 UTC every day. - - cron: '0 13 * * *' - -defaults: - run: - shell: pwsh - -env: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - POWERSHELL_TELEMETRY_OPTOUT: 1 - -permissions: - contents: read - -jobs: - update-dotnet-preview: - permissions: - contents: write # for peter-evans/create-pull-request to create branch - pull-requests: write # for peter-evans/create-pull-request to create a PR - name: Update .NET preview - timeout-minutes: 15 - runs-on: windows-latest - if: github.repository == 'PowerShell/PowerShell' - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Sync tags - run: | - git fetch --prune --unshallow --tags - - name: Execute Update .NET script - run: | - Import-Module ./.github/workflows/GHWorkflowHelper - $currentVersion = (Get-Content .\global.json | ConvertFrom-Json).sdk.version - Set-GWVariable -Name OLD_VERSION -Value $currentVersion - - ./tools/UpdateDotnetRuntime.ps1 -UpdateMSIPackaging - $newVersion = (Get-Content .\global.json | ConvertFrom-Json).sdk.version - Set-GWVariable -Name NEW_VERSION -Value $newVersion - - if ($currentVersion -ne $newVersion) { - Set-GWVariable -Name CREATE_PR -Value 'true' - } - - name: Microsoft Teams Notifier - uses: skitionek/notify-microsoft-teams@master - if: failure() - with: - webhook_url: ${{ secrets.PS_BUILD_TEAMS_CHANNEL }} - overwrite: "{title: `Failure in .github/daily.yml updating .NET build. Look at ${workflow_link}`}" - - name: Create PR if needed - uses: ./.github/workflows/composite/createPR - id: cpr - if: env.CREATE_PR == 'true' - with: - token: ${{ secrets.PR_PAT }} - title: "Update .NET SDK version from `${{ env.OLD_VERSION }}` to `${{ env.NEW_VERSION }}`" - branch: dotnet_update - - update-tpn: - permissions: - contents: write # for peter-evans/create-pull-request to create branch - pull-requests: write # for peter-evans/create-pull-request to create a PR - name: Update Notices File - timeout-minutes: 15 - runs-on: windows-latest - if: github.repository == 'PowerShell/PowerShell' - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Update Notices file - run: | - Invoke-WebRequest -Uri https://aka.ms/pwsh-daily-tpn -OutFile ./ThirdPartyNotices.txt - - name: Capture Git Status - run: | - git status --short - - name: Check if we need to create a PR - run: | - $ErrorActionPreference = 'continue' - git diff --quiet ThirdPartyNotices.txt - $exitCode = $LASTEXITCODE - Write-Verbose -Message "Exit code: $exitCode" -Verbose - if ($LASTEXITCODE -ne 0) { - Import-Module ./.github/workflows/GHWorkflowHelper - Set-GWVariable -Name CREATE_PR -Value 'true' - } else { - Write-Verbose "No difference found. Not creating a PR." -Verbose - } - exit 0 - - name: Create PR if needed - uses: ./.github/workflows/composite/createPR - id: cprtpn - if: env.CREATE_PR == 'true' - with: - token: ${{ secrets.PR_PAT }} - title: "Update to the latest NOTICES file" - branch: update-cgmanifest - - update-cgmanifest: - permissions: - contents: write # for peter-evans/create-pull-request to create branch - pull-requests: write # for peter-evans/create-pull-request to create a PR - name: Update cgmanifest - timeout-minutes: 15 - runs-on: windows-latest - if: github.repository == 'PowerShell/PowerShell' - env: - CGMANIFEST_PATH: '' - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Sync tags - run: | - git fetch --prune --unshallow --tags - - name: Install Ships provider to deal with project.assets.json - run: | - Install-Module -Name dotnet.project.assets -force - - name: Bootstrap - run: | - Import-Module ./build.psm1 - Start-PSBootStrap - - name: Verify cgmanifest is up to date - run: | - Import-Module ./build.psm1 - Find-Dotnet - ./tools/findMissingNotices.ps1 -Fix - - name: Upload cgmanifest - uses: actions/upload-artifact@v3 - if: always() && env.CGMANIFEST_PATH != '' - with: - name: cgmanifest - path: ${{ env.CGMANIFEST_PATH }} - - - name: Create PR if needed - uses: ./.github/workflows/composite/createPR - id: cprcgmanifest - if: env.CGMANIFEST_PATH != '' - with: - token: ${{ secrets.PR_PAT }} - title: "Update the cgmanifest" - branch: update-cgmanifest From 67ac36e815f538f67f91fe3a4239b0279a89f7e3 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 8 Mar 2023 14:48:21 -0800 Subject: [PATCH 4/4] Delete exp-json.yml --- .github/workflows/exp-json.yml | 147 --------------------------------- 1 file changed, 147 deletions(-) delete mode 100644 .github/workflows/exp-json.yml diff --git a/.github/workflows/exp-json.yml b/.github/workflows/exp-json.yml deleted file mode 100644 index d52f79f493a..00000000000 --- a/.github/workflows/exp-json.yml +++ /dev/null @@ -1,147 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT license. - -name: PowerShell Experimental Features Json Update -on: - workflow_dispatch: - schedule: - # At 13:00 UTC every day. - - cron: '0 13 * * *' - -defaults: - run: - shell: pwsh - -env: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - POWERSHELL_TELEMETRY_OPTOUT: 1 - -permissions: - contents: read - -jobs: - create-expjson: - strategy: - matrix: - os: [windows-latest, ubuntu-latest] - timeout-minutes: 15 - runs-on: ${{ matrix.os }} - env: - OS_TITLE: ${{ matrix.os }} - if: github.repository == 'PowerShell/PowerShell' - name: Update experimental features json - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: '0' - - name: Create experimental features file - run: | - Import-Module ./build.psm1 -Force - Start-PSBootstrap - Start-PSBuild -Clean -PSModuleRestore - $builtPwsh = Get-PSOutput - - Write-Verbose -Verbose "PWSH path: $builtPwsh" - - $getExpFeatureJsonScript = @' - [System.Collections.ArrayList] $expFeatures = Get-ExperimentalFeature | Where-Object Name -NE PS7DscSupport | ForEach-Object -MemberName Name - - # Make sure ExperimentalFeatures from modules in PSHome are added - # https://github.com/PowerShell/PowerShell/issues/10550 - $ExperimentalFeaturesFromGalleryModulesInPSHome = @() - $ExperimentalFeaturesFromGalleryModulesInPSHome | ForEach-Object { - if (!$expFeatures.Contains($_)) { - $null = $expFeatures.Add($_) - } - } - - ConvertTo-Json $expFeatures - '@ - - $expFeaturesJson = & $builtPwsh -c $getExpFeatureJsonScript - $osname = $env:OS_TITLE -like 'windows*' ? 'windows' : 'linux' - $fileNamePrefix = "experimental-feature-$osname" - $newFileName = "${fileNamePrefix}-new.json" - - Write-Verbose -Verbose 'Experimental features found' - $expFeaturesJson | Out-String | Write-Verbose -Verbose - $expFeaturesJson | Out-File $newFileName -Force - - - name: Upload experimental features windows - uses: actions/upload-artifact@v3 - with: - name: experimentalJson - path: experimental-feature-*-new.json - - compare-expjson-files: - permissions: - contents: write # for peter-evans/create-pull-request to create branch - pull-requests: write # for peter-evans/create-pull-request to create a PR - runs-on: ubuntu-latest - name: Compare experimental json files and create PR - needs: create-expjson - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: '0' - - name: Download artifacts - uses: actions/download-artifact@v3 - with: - name: experimentalJson - - name: Compare json files - run: | - Import-Module ./.github/workflows/GHWorkflowHelper -Force - - function ShouldCreatePR($currentFile, $newFile) { - if (Test-Path $currentFile) { - $currentExpFeatures = Get-Content $currentFile -Raw | ConvertFrom-Json - $newExpFeatures = Get-Content $newFile -Raw | ConvertFrom-Json - - if (-not (Compare-Object $currentExpFeatures $newExpFeatures)) { - Write-Verbose -Verbose "No changes to experimental features json file" - return $false - } - } - - return $true - } - - $currentWinFile = "experimental-feature-windows.json" - $currentLinuxFile = "experimental-feature-linux.json" - $newWinFile = "experimental-feature-windows-new.json" - $newLinuxFile = "experimental-feature-linux-new.json" - - $createPrWin = ShouldCreatePR $currentWinFile $newWinFile - Write-Verbose -Verbose "Create PR Windows == $createPrWin" - - $createPrLinux = ShouldCreatePR $currentLinuxFile $newLinuxFile - Write-Verbose -Verbose "Create PR Linux == $createPrLinux" - - $createPr = $createPrWin -or $createPrLinux - Write-Verbose -Verbose "Create PR == $createPr" - - if ($createPrWin) { - Move-Item $newWinFile $currentWinFile -Verbose -Force - } - else { - Remove-Item $newWinFile -Verbose - } - - if ($createPrLinux) { - Move-Item $newLinuxFile $currentLinuxFile -Verbose -Force - } - else { - Remove-Item $newLinuxFile -Verbose - } - - Set-GWVariable -Name CREATE_EXP_JSON_PR -Value $createPR - - - name: Create PR if needed - uses: ./.github/workflows/composite/createPR - if: env.CREATE_EXP_JSON_PR == 'true' - with: - token: ${{ secrets.PR_PAT }} - title: "Update experimental-feature json files" - branch: exp_json_update_windows