Merge pull request #9 from Baipyrus/cicd-release-install

Adding All Installation Contents To Release
This commit is contained in:
Baipyrus 2024-09-06 12:54:25 +02:00 committed by GitHub
commit 4f6016e373
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 36 deletions

View File

@ -5,7 +5,9 @@ name: Publish
on:
push:
tags: 'v*'
tags:
- 'v*'
- 'pre*'
jobs:
build:
@ -33,11 +35,19 @@ jobs:
- name: Build project
run: go build -o build/ -v ./...
- name: Copying skripts and assets
run: |
cp run.ps1 build/
cp install.ps1 build/
cp configs.json build/
mkdir -p build/assets/
cp -r assets/*.ico build/assets/
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ProxySwitcher
path: build/*
path: build/
release:
runs-on: ubuntu-latest
@ -53,10 +63,26 @@ jobs:
name: ProxySwitcher
path: artifacts/
- name: Zip artifacts for release
run: |
cd artifacts/
zip -r ../ProxySwitcher.zip *
- name: Create release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: ${{ github.ref_name }}
run: |
gh release create "${{ github.ref_name }}" \
--title "Release ${{ github.ref_name }}" \
artifacts/*
# If the release name starts with "pre", draft release
FLAGS=()
TITLE="Release $RELEASE_NAME"
if [[ "$RELEASE_NAME" == pre* ]]; then
FLAGS+=(--prerelease --draft)
TITLE="Prerelease $RELEASE_NAME"
fi
# Create the release with the appropriate flags
gh release create "$RELEASE_NAME" \
--title "$TITLE" \
"${FLAGS[@]}" \
ProxySwitcher.zip

View File

@ -17,12 +17,16 @@ save configurations, or exit the application.
## Installation
- Simply run the following command in a Windows PowerShell:
You should download the [latest release](https://github.com/Baipyrus/ProxySwitcher/releases)
archive, **extract all contents** to a dedicated directory and then simply execute
the [`.\install.ps1`](.\install.ps1) script within a Windows Powershell.
```powershell
# Using 'Invoke-RestMethod' and 'Invoke-Expression'
irm 'https://raw.githubusercontent.com/Baipyrus/ProxySwitcher/main/install.ps1' | iex
```
Alternatively, you could simply run the following command in a Windows PowerShell:
```powershell
# Using 'Invoke-RestMethod' and 'Invoke-Expression'
irm 'https://raw.githubusercontent.com/Baipyrus/ProxySwitcher/main/install.ps1' | iex
```
## Usage

View File

@ -16,6 +16,10 @@ if (Test-Path "$powershellPath\pwsh.exe")
{ $powershellPath = "$powershellPath\powershell.exe"
}
# Detect if current dir is release asset
$isRelease = Test-Path ".\ProxySwitcher.exe"
$releaseDir = (Get-Location).Path
# Create program directory and relocate
Write-Host "Creating program directory in Userprofile..." -ForegroundColor Cyan
$programDir = "ProxySwitcher"
@ -29,33 +33,23 @@ if ($startupDir -ne $destinationDir)
Set-Location $programDir
$programPath = "$destinationDir\$programDir"
# Download functional files from github as-is
Write-Host "Downloading program into local directory..." -ForegroundColor Cyan
function DownloadFile
if ($isRelease)
{
param (
[string]$url
)
# Copy release assets to program dir
Write-Host "Copying program into local directory..." -ForegroundColor Cyan
Copy-Item -Path "$releaseDir\*" -Destination $programPath -Recurse -Force
} else
{
# Specify temporary output Path
$tmpPRSWzip = "$env:TMP\ProxySwitcher.zip"
$fileName = $url.Split("/")[-1]
Invoke-RestMethod $url -OutFile $fileName
# Download release files from github as-is
Write-Host "Downloading program into local directory..." -ForegroundColor Cyan
Invoke-RestMethod "https://github.com/Baipyrus/ProxySwitcher/releases/latest/download/ProxySwitcher.zip" -OutFile $tmpPRSWzip
# Expand Archive to program directory
Expand-Archive $tmpPRSWzip -DestinationPath $programPath -Force
}
DownloadFile -url https://github.com/Baipyrus/ProxySwitcher/releases/latest/download/ProxySwitcher.exe
DownloadFile -url https://raw.githubusercontent.com/Baipyrus/ProxySwitcher/main/configs.json
DownloadFile -url https://raw.githubusercontent.com/Baipyrus/ProxySwitcher/main/run.ps1
# Create assets directory and relocate
Write-Host "Downloading assets into local directory..." -ForegroundColor Cyan
$assetsDir = "assets"
if (-not (Test-Path $assetsDir))
{ New-Item -ItemType Directory -Path $assetsDir | Out-Null
}
Set-Location $assetsDir
$assetPath = "$programPath\assets\ICON_Enabled.ico"
# Download asset files from github
DownloadFile -url https://raw.githubusercontent.com/Baipyrus/ProxySwitcher/main/assets/ICON_Disabled.ico
DownloadFile -url https://raw.githubusercontent.com/Baipyrus/ProxySwitcher/main/assets/ICON_Enabled.ico
# Add program to PATH for cli application
$userpath = [System.Environment]::GetEnvironmentVariable("PATH", "User")
@ -64,14 +58,13 @@ $userpath = $userpath + ";$programDir"
# Create Startmenu Shortcut
Write-Host "Creating shortcuts for easy access..." -ForegroundColor Cyan
$assetsDir = "assets"
$shell = New-Object -comObject WScript.Shell
$shortcutPath = "$startmenuDir\Proxy Switcher.lnk"
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = $powershellPath
$shortcut.WorkingDirectory = $programPath
$shortcut.Arguments = "-ExecutionPolicy Bypass -NonInteractive -NoProfile -WindowStyle Hidden -File ""$programPath\run.ps1"""
$shortcut.IconLocation = $assetPath
$shortcut.IconLocation = "$programPath\assets\ICON_Enabled.ico"
$shortcut.WindowStyle = 7
$shortcut.Save()