Skip to content

PowerShell Experimental Features Json Update #509

PowerShell Experimental Features Json Update

PowerShell Experimental Features Json Update #509

Workflow file for this run

# 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
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@v2
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@v2
with:
name: experimentalJson
path: experimental-feature-*-new.json
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
}
$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 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 json files"
base: master
branch: expjson_update_windows