Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 84 additions & 23 deletions .github/workflows/exp-json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,29 @@ env:
POWERSHELL_TELEMETRY_OPTOUT: 1

jobs:
create-expjson-windows:
name: Update experimental features json
create-expjson:
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
timeout-minutes: 15
runs-on: windows-latest
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@v2
with:
fetch-depth: '0'
- name: Create experimental features file
run: |
Import-Module ./build.psm1 -Force
Import-Module ./.github/workflows/GHWorkflowHelper -Force
Start-PSBootstrap
Start-PSBuild -Clean -SkipExperimentalFeatureGeneration
$pwsh = Get-PSOutput
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
Expand All @@ -48,35 +56,88 @@ jobs:
ConvertTo-Json $expFeatures
'@

$expFeaturesJson = & pwsh -c $getExpFeatureJsonScript
$expFeaturesJson | Out-File ./experimental-feature-windows-new.json -Force
$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

if (Test-Path ./experimental-feature-windows.json) {
$currentExpFeatures = Get-Content ./experimental-feature-windows.json -Raw | ConvertFrom-Json
$newExpFeatures = Get-Content ./experimental-feature-windows-new.json -Raw | ConvertFrom-Json
- name: Upload experimental features windows
uses: actions/upload-artifact@v2
with:
name: experimentalJson
path: experimental-feature-*-new.json

if (-not (Compare-Object $currentExpFeatures $newExpFeatures)) {
Write-Verbose -Verbose "No changes to experimental features json file"
Set-GWVariable -Name CREATE_EXP_JSON_PR -Value 'false'
exit 0
compare-expjson-files:
runs-on: ubuntu-latest
name: Compare experimental json files and create PR
needs: create-expjson
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: Download artifacts
uses: actions/download-artifact@v2
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
}

Move-Item ./experimental-feature-windows-new.json ./experimental-feature-windows.json -Verbose
Set-GWVariable -Name CREATE_EXP_JSON_PR -Value 'true'
$currentWinFile = "experimental-feature-windows.json"
$currentLinuxFile = "experimental-feature-linux.json"
$newWinFile = "experimental-feature-windows-new.json"
$newLinuxFile = "experimental-feature-linux-new.json"

- name: Upload experimental features windows
uses: actions/upload-artifact@v2
with:
name: experimental-feature-windows-new.json
path: experimental-feature-windows-new.json
$createPrWin = ShouldCreatePR $currentWinFile $newWinFile
Write-Verbose -Verbose "Create PR Windows == $createPrWin"

$createPrLinux = ShouldCreatePR $currentLinuxFile $newLinuxFile
Write-Verbose -Verbose "Create PR Windows == $createPrLinux"

$createPr = $createPrWin -or $createPrLinux
Write-Verbose -Verbose "Create PR == $createPr"

if ($createPrWin) {
Move-Item $newWinFile $currentWinFile -Verbose
}
else {
Remove-Item $newWinFile -Verbose
}

if ($createPrLinux) {
Move-Item $newLinuxFile $currentLinuxFile -Verbose
}
else {
Remove-Item $newLinuxFile -Verbose
}

Set-GWVariable -Name CREATE_EXP_JSON_PR -Value $createPR

- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
id: cpr
if: env.CREATE_EXP_JSON_PR == 'true'
with:
commit-message: "Update experimental-feature-windows.json"
title: "Update experimental-feature-windows.json"
title: "Update experimental-feature json files"
base: master
branch: expjson_update_windows