Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/scripts/inject-token.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ param(
)

if ([string]::IsNullOrEmpty($Token)) {
Write-Host "No UPLOADTHING_TOKEN provided. Skipping injection. Build will use empty/default token."
exit 0
Write-Error "No UPLOADTHING_TOKEN provided. Fails for Release builds."
exit 1
}

$constantsPath = "GenHub/GenHub.Core/Constants/ApiConstants.cs"
Expand All @@ -26,9 +26,16 @@ $dataStr = ($obfuscated | ForEach-Object { "0x{0:x2}" -f $_ }) -join ", "
$keyStr = ($key | ForEach-Object { "0x{0:x2}" -f $_ }) -join ", "

$content = Get-Content $constantsPath -Raw
# Replace the placeholders we put in the static property
$content = $content -replace 'byte\[\] data = \[\]; // \[PLACEHOLDER_DATA\]', "byte[] data = [$dataStr];"
$content = $content -replace 'byte\[\] key = \[\]; // \[PLACEHOLDER_KEY\]', "byte[] key = [$keyStr];"

# Use regex replace to be robust against whitespace
# Pattern: byte[] data = []; // [PLACEHOLDER_DATA]
$content = [System.Text.RegularExpressions.Regex]::Replace($content, 'byte\[\]\s+data\s*=\s*\[\];\s*//\s*\[PLACEHOLDER_DATA\]', "byte[] data = [$dataStr];")
$content = [System.Text.RegularExpressions.Regex]::Replace($content, 'byte\[\]\s+key\s*=\s*\[\];\s*//\s*\[PLACEHOLDER_KEY\]', "byte[] key = [$keyStr];")

if ($content -notmatch "0x") {
Write-Error "Token injection failed! Placeholders were not found or replaced."
exit 1
}

Set-Content $constantsPath $content
Write-Host "Successfully injected and obfuscated UPLOADTHING_TOKEN into ApiConstants.cs"
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ jobs:
echo "VERSION=$version" >> $env:GITHUB_OUTPUT
echo "CHANNEL=$channel" >> $env:GITHUB_OUTPUT

- name: Inject Secrets
shell: pwsh
run: |
./.github/scripts/inject-token.ps1 -Token "${{ secrets.UPLOADTHING_TOKEN }}"

- name: Build Projects
shell: pwsh
run: |
Expand All @@ -142,10 +147,6 @@ jobs:
Write-Host "Building Windows project"
dotnet build "${{ env.WINDOWS_PROJECT }}" -c ${{ env.BUILD_CONFIGURATION }} @buildProps

- name: Inject Secrets
shell: pwsh
run: |
./.github/scripts/inject-token.ps1 -Token "${{ secrets.UPLOADTHING_TOKEN }}"

- name: Publish Windows App
shell: pwsh
Expand Down Expand Up @@ -284,6 +285,11 @@ jobs:
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT

- name: Inject Secrets
shell: pwsh
run: |
./.github/scripts/inject-token.ps1 -Token "${{ secrets.UPLOADTHING_TOKEN }}"

- name: Build Projects
run: |
BUILD_PROPS="-p:Version=${{ steps.buildinfo.outputs.VERSION }} -p:GitShortHash=${{ steps.buildinfo.outputs.SHORT_HASH }} -p:PullRequestNumber=${{ steps.buildinfo.outputs.PR_NUMBER }} -p:BuildChannel=${{ steps.buildinfo.outputs.CHANNEL }}"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,6 @@ jobs:
${{ steps.info.outputs.CHANGELOG }}

### 🔧 Assets
- **Installer:** `GenHub-win-Setup.exe`
- **Portable:** `GenHub-${{ steps.info.outputs.VERSION }}-win-portable.zip`
- **Installer:** [GenHub-win-Setup.exe](https://github.com/${{ github.repository }}/releases/download/v${{ steps.info.outputs.VERSION }}/GenHub-win-Setup.exe)
- **Portable:** [GenHub-${{ steps.info.outputs.VERSION }}-win-portable.zip](https://github.com/${{ github.repository }}/releases/download/v${{ steps.info.outputs.VERSION }}/GenHub-${{ steps.info.outputs.VERSION }}-win-portable.zip)
files: final-assets/*
8 changes: 8 additions & 0 deletions GenHub/GenHub.Windows/GenHub.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
<EmbeddedResource Include="Resources\update_genhub.ps1" />
</ItemGroup>

<!-- Copy .env file to output directory for local debugging if it exists -->
<ItemGroup Condition="Exists('..\..\.env')">
<None Include="..\..\.env">
<Link>.env</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GenHub\GenHub.csproj" />
<ProjectReference Include="..\GenHub.Core\GenHub.Core.csproj" />
Expand Down
Loading