Skip to content

Commit 4bc98a5

Browse files
committed
copy github workflow from @majkinetor
1 parent 60e59ae commit 4bc98a5

File tree

13 files changed

+582
-4
lines changed

13 files changed

+582
-4
lines changed

.github/EventLogs.ps1

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#require -version 3.0
2+
3+
<#
4+
.SYNOPSIS
5+
Clear all event logs
6+
#>
7+
function Clear-EventLogs {
8+
Get-EventLog * | ForEach-Object {
9+
try {
10+
Clear-EventLog $_.Log
11+
}
12+
catch {
13+
Write-Warning 'Error during clearing event logs'
14+
Write-Warning "$_"
15+
}
16+
}
17+
18+
#Clear this one again as it accumulates clearing events from previous step
19+
try {
20+
Clear-EventLog System
21+
}
22+
catch {
23+
Write-Warning 'Error during clearing event logs'
24+
Write-Warning "$_"
25+
}
26+
Get-EventLog *
27+
}
28+
29+
<#
30+
.SYNOPSIS
31+
Get latest event logs across all event logs
32+
.Example
33+
logs Error,Warning -Newest 5
34+
#>
35+
function Get-EventLogs {
36+
param(
37+
[ValidateSet('Error', 'Information', 'Warning', '*')]
38+
[string[]] $EntryType = 'Error',
39+
40+
[int] $Newest = 1000,
41+
42+
[switch] $Raw
43+
)
44+
$r = @()
45+
46+
if ($EntryType -eq '*') { $EntryType = 'Error', 'Information', 'Warning' }
47+
Get-EventLog * | ForEach-Object Log | ForEach-Object {
48+
$log = $_
49+
try {
50+
$r += Get-EventLog -Log $log -Newest $Newest -EntryType $EntryType -ea 0
51+
}
52+
catch { Write-Warning "$log - $_" }
53+
}
54+
$r = $r | Sort-Object TimeWritten -Descending
55+
if ($Raw) { $r } else { $r | Select-Object Source, TimeWritten, Message }
56+
}
57+
58+
Set-Alias logs Get-EventLogs
59+
Set-Alias clearlogs Clear-EventLogs
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Package Pusher
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
packages:
7+
description: "What is the packages you wish to push?"
8+
required: true
9+
10+
jobs:
11+
pusher:
12+
runs-on: windows-2019
13+
env:
14+
au_version: master
15+
github_user_repo: ${{ github.repository }}
16+
api_key: ${{ secrets.CHOCO_API_KEY }}
17+
18+
steps:
19+
- name: Install Dependencies
20+
run: |
21+
Set-Service wuauserv -StartupType Manual
22+
choco install wormies-au-helpers vt-cli -y
23+
Install-Module Pester -RequiredVersion 4.10.1 -Scope CurrentUser -Force -SkipPublisherCheck
24+
git clone -q https://github.com/chocolatey-community/chocolatey-au.git $Env:TEMP/au
25+
. "$Env:TEMP/au/scripts/Install-AU.ps1" $Env:au_version
26+
shell: powershell
27+
- name: System information
28+
run: |
29+
Get-CimInstance win32_operatingsystem -Property Caption, OSArchitecture, Version | fl Caption, OSArchitecture, Version
30+
$PSVersionTable
31+
git --version
32+
choco --version
33+
"Build info"
34+
' {0,-20} {1}' -f 'SCHEDULED BUILD:', ("${{ github.event_name }}" -eq 'schedule')
35+
' {0,-20} {1}' -f 'FORCED BUILD:' , ("${{ github.event_name }}" -eq 'workflow_dispatch')
36+
shell: powershell
37+
- uses: actions/checkout@v3.5.0
38+
with:
39+
fetch-depth: 0
40+
- name: Run package pushing
41+
env:
42+
PACKAGES_PUSHES: ${{ github.event.inputs.packages }}
43+
run: |
44+
$packages = $env:PACKAGES_PUSHES -split ' '
45+
Write-Host "PUSHING PACKAGES: $packages"
46+
foreach ($package in $packages) {
47+
Write-Host ("{0}`n{1}`n" -f ('-'*60), "PACKAGE: $package")
48+
$package_dir = ls -recurse | ? { $_.Name -eq "$package.nuspec" } | select -First 1 | % Directory
49+
50+
if (!$package_dir) { Write-Warning "Can't find package '$package'"; continue }
51+
pushd $package_dir
52+
if (Test-Path update.ps1 -ea 0) { ./update.ps1 }
53+
choco pack
54+
Push-Package
55+
popd
56+
}
57+
shell: powershell
58+
- name: Create diff file
59+
run: |
60+
git add automatic extension manual templates
61+
git diff --cached > unsaved_changes.patch
62+
shell: powershell
63+
- name: Upload artifacts
64+
if: always()
65+
uses: actions/upload-artifact@v3
66+
with:
67+
name: artifacts
68+
path: |
69+
unsaved_changes.patch
70+
eventlogs.txt
71+
**/*.nupkg
72+
retention-days: 5
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Package Updater
2+
3+
on:
4+
push:
5+
branches: [master]
6+
workflow_dispatch:
7+
inputs:
8+
packages:
9+
description: "What is the packages (optionally version) you wish to force update on?"
10+
required: false
11+
schedule:
12+
- cron: "0 3 * * *"
13+
14+
jobs:
15+
updater:
16+
runs-on: windows-2019
17+
env:
18+
au_version: master
19+
au_push: true
20+
github_user_repo: ${{ github.repository }}
21+
github_api_key: ${{ secrets.GIST_API_KEY }}
22+
gist_id: df9d4f7d314e08279d949ba08f1ec769
23+
nupkg_cache_path: C:\nupkg_cache
24+
mail_user: ${{ secrets.MAIL_USER }}
25+
mail_pass: ${{ secrets.MAIL_PASSWORD }}
26+
mail_server: smtp.gmail.com
27+
mail_port: 587
28+
mail_enablessl: true
29+
api_key: ${{ secrets.CHOCO_API_KEY }}
30+
nuget_artifacts: ${{ github.runner.temp }}/artifacts
31+
32+
steps:
33+
- name: Configure git client
34+
run: |
35+
git config --global user.email "riedel@teco.edu"
36+
git config --global user.name "till"
37+
git config --global core.safecrlf false
38+
- name: Install Dependencies
39+
run: |
40+
Set-Service wuauserv -StartupType Manual
41+
git clone -q https://github.com/majkinetor/au.git $Env:TEMP/au
42+
. "$Env:TEMP/au/scripts/Install-AU.ps1" $Env:au_version
43+
shell: powershell
44+
- name: System information
45+
run: |
46+
Get-CimInstance win32_operatingsystem -Property Caption, OSArchitecture, Version | fl Caption, OSArchitecture, Version
47+
$PSVersionTable
48+
git --version
49+
choco --version
50+
"Build info"
51+
' {0,-20} {1}' -f 'SCHEDULED BUILD:', ("${{ github.event_name }}" -eq 'schedule')
52+
' {0,-20} {1}' -f 'FORCED BUILD:' , ("${{ github.event_name }}" -eq 'workflow_dispatch')
53+
shell: powershell
54+
- uses: actions/checkout@v3.5.0
55+
with:
56+
fetch-depth: 0
57+
- name: Run package updater
58+
env:
59+
FORCED_PACKAGES: ${{ github.event.inputs.packages }}
60+
run: |
61+
. ./.github/EventLogs.ps1
62+
Clear-EventLogs
63+
Remove-Item "$Env:ChocolateyInstall\logs\*.log"
64+
65+
./update_all.ps1 -ForcedPackages $env:FORCED_PACKAGES
66+
Get-EventLogs * | ? Source -eq 'Schannel' | Format-List * | Out-File eventlogs.txt
67+
shell: powershell
68+
- name: Create diff file
69+
run: |
70+
git add automatic extension manual templates
71+
git diff --cached > unsaved_changes.patch
72+
- name: Create au temporary directory
73+
run: |
74+
if (Test-Path $Env:TEMP\chocolatey\au) { 7z a -mx9 au_temp.7z $Env:TEMP\chocolatey\au\* }
75+
shell: powershell
76+
- name: Upload artifacts
77+
if: always()
78+
uses: actions/upload-artifact@v4
79+
with:
80+
name: artifacts
81+
path: |
82+
unsaved_changes.patch
83+
au_temp.7z
84+
update_info.xml
85+
Update-AUPackages.md
86+
eventlogs.txt
87+
**/*.nupkg
88+
retention-days: 5

KopiaUI/update.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ param(
33
[switch]$force
44
)
55

6-
$global:force=( $true -or !(!($force)) )
6+
$global:force=!(!($force))
77

88
function global:au_GetLatest {
99
$github_repository = "kopia/kopia"
@@ -47,4 +47,4 @@ function global:au_BeforeUpdateHook($package) {
4747
$readme.substring(0, $readme.indexOf('When ready')) | Out-File -Encoding "UTF8" ($package.Path + "\README.md")
4848
}
4949

50-
. "$PSScriptRoot\..\update.ps1"
50+
. "$PSScriptRoot\..\update_include.ps1"

New-Package.ps1

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
param($Name, $Type)
2+
3+
<#
4+
.SYNOPSIS
5+
Create a new package from the template
6+
7+
.DESCRIPTION
8+
This function creates a new package by using the directory _template which contains desired package basic settings.
9+
#>
10+
function New-Package{
11+
[CmdletBinding()]
12+
param(
13+
#Package name
14+
[string] $Name,
15+
16+
#Type of the package
17+
[ValidateSet('Portable', 'Installer', 'EPortable', 'EInstaller')]
18+
[string] $Type,
19+
20+
#Github repository in the form username/repository
21+
[string] $GithubRepository
22+
)
23+
24+
if ($Name -eq $null) { throw "Name can't be empty" }
25+
if (Test-Path $Name) { throw "Package with that name already exists" }
26+
if (!(Test-Path _template)) { throw "Template for the packages not found" }
27+
cp _template $Name -Recurse
28+
29+
$nuspec = gc "$Name\template.nuspec"
30+
rm "$Name\template.nuspec"
31+
32+
Write-Verbose 'Fixing nuspec'
33+
$nuspec = $nuspec -replace '<id>.+', "<id>$Name</id>"
34+
$nuspec = $nuspec -replace '<iconUrl>.+', "<iconUrl>https://cdn.rawgit.com/$GithubRepository/master/$Name/icon.png</iconUrl>"
35+
$nuspec = $nuspec -replace '<packageSourceUrl>.+', "<packageSourceUrl>https://github.com/$GithubRepository/tree/master/$Name</packageSourceUrl>"
36+
$nuspec | Out-File -Encoding UTF8 "$Name\$Name.nuspec"
37+
38+
switch ($Type)
39+
{
40+
'Installer' {
41+
Write-Verbose 'Using installer template'
42+
mv "$Name\tools\chocolateyInstallExe.ps1" "$Name\tools\chocolateyInstall.ps1"
43+
}
44+
'Portable' {
45+
Write-Verbose 'Using portable template'
46+
mv "$Name\tools\chocolateyInstallZip.ps1" "$Name\tools\chocolateyInstall.ps1"
47+
}
48+
'EInstaller' {
49+
Write-Verbose 'Using embedded installer template'
50+
mv "$Name\tools\chocolateyInstallEmbeddedExe.ps1" "$Name\tools\chocolateyInstall.ps1"
51+
}
52+
'EPortable' {
53+
Write-Verbose 'Using embedded portable template'
54+
mv "$Name\tools\chocolateyInstallEmbeddedZip.ps1" "$Name\tools\chocolateyInstall.ps1"
55+
}
56+
57+
default { throw 'No template given' }
58+
}
59+
rm "$Name\tools\*.ps1" -Exclude chocolateyInstall.ps1, chocolateyUninstall.ps1
60+
61+
Write-Verbose 'Fixing chocolateyInstall.ps1'
62+
$installer = gc "$Name\tools\chocolateyInstall.ps1"
63+
$installer -replace "(^[$]packageName\s*=\s*)('.*')", "`$1'$($Name)'" | Set-Content "$Name\tools\chocolateyInstall.ps1"
64+
}
65+
66+
New-Package $Name $Type -GithubRepository majkinetor/chocolatey -Verbose

SMathStudioDesktop/update.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function global:au_GetLatest {
3636
$link.host="smath.com"
3737

3838

39-
$stable[0].firstChild().firstChild().innerText -match '[0-9]*\.[0-9]*\.[0-9]*'
39+
$stable[0].firstChild().firstChild().innerText -match '[0-9]*\.[0-9]*\.[0-9]*\.?[0-9]*'
4040
$version = $Matches[0]
4141

4242
$releaseNotes = $stable[0].nextSibling().innerHtml|pandoc -f html -t markdown | Out-String

Test-Sandbox.ps1

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
param( $ChocoParameters )
2+
3+
# Check if Windows Sandbox is enabled
4+
if (-Not (Test-Path "$env:windir\System32\WindowsSandbox.exe")) {
5+
Write-Error -Category NotInstalled -Message @'
6+
Windows Sandbox does not seem to be available. Check the following URL for prerequisites and further details:
7+
https://docs.microsoft.com/en-us/windows/security/threat-protection/windows-sandbox/windows-sandbox-overview
8+
9+
You can run the following command in an elevated PowerShell for enabling Windows Sandbox:
10+
Enable-WindowsOptionalFeature -Online -FeatureName 'Containers-DisposableClientVM'
11+
'@ -ErrorAction Stop
12+
}
13+
14+
# Initialize Temp Folder
15+
16+
$tempFolder = Join-Path -Path $PSScriptRoot -ChildPath 'Test-Sandbox_Temp'
17+
New-Item $tempFolder -ItemType Directory -ea 0 | Out-Null
18+
19+
$packageName = Split-Path -Leaf $pwd
20+
$version = ([xml] (Get-Content "$packageName.nuspec")).package.metadata.version
21+
22+
# Create Bootstrap script
23+
$bootstrapPs1Content = @"
24+
cd ~\Desktop\$packageName
25+
Write-Host 'Installing Chocolatey'
26+
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
27+
choco feature enable -n=allowGlobalConfirmation
28+
29+
choco install -vd $packageName --version $version --source ".;chocolatey" $ChocoParameters
30+
"@
31+
32+
$bootstrapPs1FileName = 'Bootstrap.ps1'
33+
$bootstrapPs1Content | Out-File (Join-Path -Path $tempFolder -ChildPath $bootstrapPs1FileName)
34+
35+
# Create wsb file
36+
$tempFolderInSandbox = Join-Path -Path 'C:\Users\WDAGUtilityAccount\Desktop' -ChildPath (Split-Path $tempFolder -Leaf)
37+
$sandboxTestWsbContent = @"
38+
<Configuration>
39+
<MappedFolders>
40+
<MappedFolder><HostFolder>$tempFolder</HostFolder></MappedFolder>
41+
<MappedFolder><HostFolder>$pwd</HostFolder></MappedFolder>
42+
</MappedFolders>
43+
<LogonCommand>
44+
<Command>PowerShell Start-Process PowerShell -WorkingDirectory '$tempFolderInSandbox' -ArgumentList '-ExecutionPolicy Bypass -NoExit -File $bootstrapPs1FileName'</Command>
45+
</LogonCommand>
46+
</Configuration>
47+
"@
48+
$sandboxTestWsbFileName = 'SandboxTest.wsb'
49+
$sandboxTestWsbFile = Join-Path -Path $tempFolder -ChildPath $sandboxTestWsbFileName
50+
$sandboxTestWsbContent | Out-File $sandboxTestWsbFile
51+
52+
Write-Host 'Starting Windows Sandbox'
53+
WindowsSandbox $SandboxTestWsbFile

cinst-gh.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<# Installs package directly from Github repository
2+
To use with your own repo:
3+
- Set the path to your packages root in $Repo
4+
- Create short link to this raw github script via for example goo.gl
5+
- Commit nupkg files in the repository along with the package source code
6+
7+
Usage:
8+
- Pass repository package name as a first argument
9+
- Pass any cinst option after that (some may not work ofc. such as `version`)
10+
11+
Example:
12+
iwr https://goo.gl/SZ9c3m | iex; cinst-gh furmark --force
13+
#>
14+
function cinst-gh {
15+
$Repo = "https://github.com/riedel/chocolatey-packages/tree/master"
16+
17+
$name = $args[0]
18+
$download_page = iwr $Repo/$name -UseBasicParsing
19+
$url = $download_page.Links.href -like '*.nupkg'
20+
$p = $url -split '/' | select -last 1
21+
22+
$raw = $Repo -replace 'github.com', 'rawgit.com' -replace 'tree/'
23+
iwr "$raw/$(($p -split '\.')[0])/$p" -Out $p
24+
$a = $args | select -Skip 1
25+
$cmd = "cinst $p $a"
26+
Write-Host $cmd; iex $cmd
27+
rm $p
28+
}

0 commit comments

Comments
 (0)