Skip to content

Commit

Permalink
Merge branch 'ChrisTitusTech:main' into FixNameForceAutoHDR
Browse files Browse the repository at this point in the history
  • Loading branch information
MyDrift-user authored Jun 10, 2024
2 parents ab41e42 + 2b80e14 commit 275b78a
Show file tree
Hide file tree
Showing 14 changed files with 738 additions and 1,418 deletions.
89 changes: 9 additions & 80 deletions .github/workflows/close-old-issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,20 @@ on:
schedule:
- cron: '0 0 * * *' # Run daily
workflow_dispatch: # This line enables manual triggering

jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write # Ensure necessary permissions for issues

pull-requests: none
contents: none
steps:
- name: Close inactive issues
uses: actions/github-script@v7
uses: actions/stale@v9.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const octokit = github;
// Get the repository owner and name
const { owner, repo } = context.repo;
// Define the inactivity period (14 days)
const inactivityPeriod = new Date();
inactivityPeriod.setDate(inactivityPeriod.getDate() - 14);
const labelKeepIssue = 'Keep Issue Open';
try {
// Get all open issues with pagination
for await (const response of octokit.paginate.iterator(octokit.rest.issues.listForRepo, {
owner,
repo,
state: 'open',
})) {
const issues = response.data;
// Close issues inactive for more than the inactivity period
for (const issue of issues) {
let closeIssue = true;
// Get all Labels of issue, and compared each label with the labelKeepIssue const variable
try {
const respondIssueLabels = await octokit.request("GET /repos/{owner}/{repo}/issues/{issue_number}/labels", {
owner: owner,
repo: repo,
issue_number: issue.number
});
const labels = respondIssueLabels.data;
for (let i = 0; i < labels.length; i++) {
const label = labels[i]
if (label.name === labelKeepIssue) {
console.log(`Issue #${issue.number} will not be closed`);
closeIssue = false;
break; // Break from the loop, no need to check the remaining Labels.
}
}
} catch (error) {
console.error(`Error while Fetching Labels for Issue #${issue.number}, Error: ${error}`);
}
if (!closeIssue) {
continue; // Skip the next bit of code
}
const lastCommentDate = issue.updated_at;
if (new Date(lastCommentDate) < inactivityPeriod) {
try {
// Close the issue
await octokit.rest.issues.update({
owner,
repo,
issue_number: issue.number,
state: 'closed',
});
// Add a comment
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: 'Closed due to inactivity',
});
} catch (error) {
console.error(`Error updating or commenting on issue #${issue.number}: ${error}`);
}
}
}
}
} catch (error) {
console.error(`Error fetching issues: ${error}`);
}
exempt-issue-labels: "Keep Issue Open"
days-before-issue-close: 14
close-issue-message: "This issue was closed because it has been inactive for 14 days"
debug-only: false # Make this field equal true if you want to test your configuration if it works or not
repo-token: ${{ secrets.GITHUB_TOKEN }}
24 changes: 24 additions & 0 deletions .github/workflows/compile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Compile

on:
push:
branches:
- main
- test*

jobs:
build-runspace:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Compile project
shell: pwsh
run: |
Set-ExecutionPolicy Bypass -Scope Process -Force; ./Compile.ps1
continue-on-error: false # Directly fail the job on error, removing the need for a separate check
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Compile Winutil
if: success()
52 changes: 35 additions & 17 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
name: Update Branch
name: Release WinUtil

on:
push:
branches:
- main
- test*
workflow_run:
workflows: ["Compile WinUtil"] #Ensure Compile winget.ps1 is done
types:
- completed

jobs:
build-runspace:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Compile project
shell: pwsh
run: |
Set-ExecutionPolicy Bypass -Scope Process -Force; ./Compile.ps1
continue-on-error: false # Directly fail the job on error, removing the need for a separate check
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Compile Winutil
if: success()
- name: Checkout Repository
uses: actions/checkout@v4

- name: Extract Version from winutil.ps1
id: extract_version
run: |
$version = ''
Get-Content ./winutil.ps1 -TotalCount 30 | ForEach-Object {
if ($_ -match 'Version\s*:\s*(\d{2}\.\d{2}\.\d{2})') {
$version = $matches[1]
echo "version=$version" >> $GITHUB_ENV
break
}
}
if (-not $version) {
Write-Error "Version not found in winutil.ps1"
exit 1
}
shell: pwsh

- name: Create and Upload Release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.extract_version.outputs.version }}
name: Release ${{ steps.extract_version.outputs.version }}
body_path: path/to/release-notes.md
files: ./winutil.ps1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85 changes: 51 additions & 34 deletions Compile.ps1
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
param (
[switch]$Debug
)
$OFS = "`r`n"
$scriptname = "winutil.ps1"

# Variable to sync between runspaces
$sync = [Hashtable]::Synchronized(@{})
$sync.PSScriptRoot = $PSScriptRoot
$sync.configs = @{}

if (Test-Path -Path "$($scriptname)")
{
Remove-Item -Force "$($scriptname)"
}

Write-output '
$header = @"
################################################################################################################
### ###
### WARNING: This file is automatically generated DO NOT modify this file directly as it will be overwritten ###
### ###
################################################################################################################
' | Out-File ./$scriptname -Append -Encoding ascii
"@

(Get-Content .\scripts\start.ps1).replace('#{replaceme}',"$(Get-Date -Format yy.MM.dd)") | Out-File ./$scriptname -Append -Encoding ascii
# Create the script in memory.
$script_content = [System.Collections.Generic.List[string]]::new()

Get-ChildItem .\functions -Recurse -File | ForEach-Object {
Get-Content $psitem.FullName | Out-File ./$scriptname -Append -Encoding ascii
}
Write-Progress -Activity "Compiling" -Status "Adding: Header" -PercentComplete 5
$script_content.Add($header)

Write-Progress -Activity "Compiling" -Status "Adding: Version" -PercentComplete 10
$script_content.Add($(Get-Content .\scripts\start.ps1).replace('#{replaceme}',"$(Get-Date -Format yy.MM.dd)"))

Write-Progress -Activity "Compiling" -Status "Adding: Functions" -PercentComplete 20
Get-ChildItem .\functions -Recurse -File | ForEach-Object {
$script_content.Add($(Get-Content $psitem.FullName))
}
Write-Progress -Activity "Compiling" -Status "Adding: Config *.json" -PercentComplete 40
Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object {

$json = (Get-Content $psitem.FullName).replace("'","''")

# Replace every XML Special Character so it'll render correctly in final build
# Only do so if json files has content to be displayed (for example the applications, tweaks, features json files)
# Some Type Convertion using Casting and Cleaning Up of the convertion result using 'Replace' Method
# Some Type Convertion using Casting and Cleaning Up of the convertion result using 'Replace' Method
$jsonAsObject = $json | convertfrom-json
$firstLevelJsonList = ([System.String]$jsonAsObject).split('=;') | ForEach-Object {
$_.Replace('=}','').Replace('@{','').Replace(' ','')
Expand All @@ -38,7 +46,7 @@ Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-
for ($i = 0; $i -lt $firstLevelJsonList.Count; $i += 1) {
$firstLevelName = $firstLevelJsonList[$i]
# Note: Avoid using HTML Entity Codes (for example '&rdquo;' (stands for "Right Double Quotation Mark")), and use HTML decimal/hex codes instead.
# as using HTML Entity Codes will result in XML parse Error when running the compiled script.
# as using HTML Entity Codes will result in XML parse Error when running the compiled script.
if ($jsonAsObject.$firstLevelName.content -ne $null) {
$jsonAsObject.$firstLevelName.content = $jsonAsObject.$firstLevelName.content.replace('&','&#38;').replace('','&#8220;').replace('','&#8221;').replace("'",'&#39;').replace('<','&#60;').replace('>','&#62;')
$jsonAsObject.$firstLevelName.content = $jsonAsObject.$firstLevelName.content.replace('&#39;&#39;',"&#39;") # resolves the Double Apostrophe caused by the first replace function in the main loop
Expand All @@ -49,44 +57,53 @@ Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-
}
}
# The replace at the end is required, as without it the output of converto-json will be somewhat weird for Multiline String
# Most Notably is the scripts in json files, make=ing it harder for users who want to review these scripts that are found in the final compiled script
# Most Notably is the scripts in json files, making it harder for users who want to review these scripts that are found in the final compiled script
$json = ($jsonAsObject | convertto-json -Depth 3).replace('\r\n',"`r`n")

$sync.configs.$($psitem.BaseName) = $json | convertfrom-json
Write-output "`$sync.configs.$($psitem.BaseName) = '$json' `| convertfrom-json" | Out-File ./$scriptname -Append -Encoding ascii
$script_content.Add($(Write-output "`$sync.configs.$($psitem.BaseName) = '$json' `| convertfrom-json" ))
}
Write-Progress -Activity "Compiling" -Status "Adding: Config *.cfg" -PercentComplete 45
Get-ChildItem .\config | Where-Object {$PSItem.Extension -eq ".cfg"} | ForEach-Object {
Write-output "`$sync.configs.$($psitem.BaseName) = '$(Get-Content $PSItem.FullName)'" | Out-File ./$scriptname -Append -Encoding ascii
$script_content.Add($(Write-output "`$sync.configs.$($psitem.BaseName) = '$(Get-Content $PSItem.FullName)'"))
}
Get-ChildItem .\config | Where-Object {$PSItem.Extension -eq ".cfg"} | ForEach-Object {
$script_content.Add($(Write-output "`$sync.configs.$($psitem.BaseName) = '$(Get-Content $PSItem.FullName)'"))
}

$xaml = (Get-Content .\xaml\inputXML.xaml).replace("'","''")

# Dot-source the Get-TabXaml function
. .\functions\private\Get-TabXaml.ps1

## Xaml Manipulation
$tabColumns = Get-TabXaml "applications" 5
$tabColumns | Out-File -FilePath ".\xaml\inputApp.xaml" -Encoding ascii
$tabColumns = Get-TabXaml "tweaks"
$tabColumns | Out-File -FilePath ".\xaml\inputTweaks.xaml" -Encoding ascii
$tabColumns = Get-TabXaml "feature"
$tabColumns | Out-File -FilePath ".\xaml\inputFeatures.xaml" -Encoding ascii
Write-Progress -Activity "Compiling" -Status "Building: Xaml " -PercentComplete 75
$appXamlContent = Get-TabXaml "applications" 5
$tweaksXamlContent = Get-TabXaml "tweaks"
$featuresXamlContent = Get-TabXaml "feature"

# Assuming inputApp.xaml is in the same directory as main.ps1
$appXamlPath = Join-Path -Path $PSScriptRoot -ChildPath "xaml/inputApp.xaml"
$tweaksXamlPath = Join-Path -Path $PSScriptRoot -ChildPath "xaml/inputTweaks.xaml"
$featuresXamlPath = Join-Path -Path $PSScriptRoot -ChildPath "xaml/inputFeatures.xaml"

# Load the XAML content from inputApp.xaml
$appXamlContent = Get-Content -Path $appXamlPath -Raw
$tweaksXamlContent = Get-Content -Path $tweaksXamlPath -Raw
$featuresXamlContent = Get-Content -Path $featuresXamlPath -Raw

Write-Progress -Activity "Compiling" -Status "Adding: Xaml " -PercentComplete 90
# Replace the placeholder in $inputXML with the content of inputApp.xaml
$xaml = $xaml -replace "{{InstallPanel_applications}}", $appXamlContent
$xaml = $xaml -replace "{{InstallPanel_tweaks}}", $tweaksXamlContent
$xaml = $xaml -replace "{{InstallPanel_features}}", $featuresXamlContent

Write-output "`$inputXML = '$xaml'" | Out-File ./$scriptname -Append -Encoding ascii
$script_content.Add($(Write-output "`$inputXML = '$xaml'"))

$script_content.Add($(Get-Content .\scripts\main.ps1))

if ($Debug){
Write-Progress -Activity "Compiling" -Status "Writing debug files" -PercentComplete 95
$appXamlContent | Out-File -FilePath ".\xaml\inputApp.xaml" -Encoding ascii
$tweaksXamlContent | Out-File -FilePath ".\xaml\inputTweaks.xaml" -Encoding ascii
$featuresXamlContent | Out-File -FilePath ".\xaml\inputFeatures.xaml" -Encoding ascii
}
else {
Write-Progress -Activity "Compiling" -Status "Removing temporary files" -PercentComplete 99
Remove-Item ".\xaml\inputApp.xaml" -ErrorAction SilentlyContinue
Remove-Item ".\xaml\inputTweaks.xaml" -ErrorAction SilentlyContinue
Remove-Item ".\xaml\inputFeatures.xaml" -ErrorAction SilentlyContinue
}

Get-Content .\scripts\main.ps1 | Out-File ./$scriptname -Append -Encoding ascii
Set-Content -Path $scriptname -Value ($script_content -join "`r`n") -Encoding ascii
Write-Progress -Activity "Compiling" -Completed
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ or by executing:
iwr -useb https://christitus.com/win | iex
```

if for some reason this site is not reachable from your country please try running it directly from github

if for some reason this site is not reachable from your country please try running it directly from github (replace 24.06.07 with current release that you are interested in)
```
irm https://raw.githubusercontent.com/ChrisTitusTech/winutil/main/winutil.ps1 | iex
irm "https://raw.githubusercontent.com/ChrisTitusTech/winutil/24.06.07/winutil.ps1" | iex
```

#### Automation
Expand Down
Loading

0 comments on commit 275b78a

Please sign in to comment.