forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (120 loc) · 4.65 KB
/
exp-json.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# 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