|
1 | | -name: Sync SamplesByPlatforms to Private Repo |
2 | | - |
| 1 | +name: Build and Publish to Public Repository |
3 | 2 | on: |
4 | 3 | push: |
5 | | - branches: [ main, master ] |
6 | | - paths: |
7 | | - - 'Src/SamplesByPlatforms/**' |
| 4 | + branches: [ "main" ] |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
8 | 8 |
|
9 | 9 | jobs: |
10 | | - sync: |
11 | | - runs-on: ubuntu-latest |
| 10 | + build: |
| 11 | + runs-on: windows-latest |
| 12 | + |
12 | 13 | steps: |
13 | | - - name: Checkout source repo |
14 | | - uses: actions/checkout@v3 |
15 | | - with: |
16 | | - path: source |
17 | | - |
18 | | - - name: Checkout target repo |
19 | | - uses: actions/checkout@v3 |
20 | | - with: |
21 | | - repository: xceedsoftware/xceed-words-samplesbyplatforms |
22 | | - token: ${{ secrets.PRIVATE_REPO_PAT }} |
23 | | - path: target |
| 14 | + - name: Checkout private repository |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Setup .NET |
| 18 | + uses: actions/setup-dotnet@v4 |
| 19 | + with: |
| 20 | + dotnet-version: 9.0.x |
| 21 | + |
| 22 | + # ===== WPF SAMPLE BUILD ===== |
| 23 | + - name: Restore dependencies (WPF) |
| 24 | + run: dotnet restore Xceed.Wpf.Words.Sample/Xceed.Wpf.Words.Sample.csproj |
| 25 | + |
| 26 | + - name: Replace License Key (WPF) |
| 27 | + run: | |
| 28 | + $content = Get-Content -Path .\Xceed.Wpf.Words.Sample\MainWindow.xaml.cs -Raw |
| 29 | + $content = $content -replace 'LICENSE_KEY_PLACEHOLDER', '${{ secrets.WORDS_LICENSE }}' |
| 30 | + Set-Content -Path .\Xceed.Wpf.Words.Sample\MainWindow.xaml.cs -Value $content |
| 31 | + shell: pwsh |
| 32 | + |
| 33 | + - name: Build (WPF) |
| 34 | + run: dotnet build Xceed.Wpf.Words.Sample/Xceed.Wpf.Words.Sample.csproj --configuration Release --no-restore |
| 35 | + |
| 36 | + - name: Publish (WPF) |
| 37 | + run: dotnet publish Xceed.Wpf.Words.Sample/Xceed.Wpf.Words.Sample.csproj -c Release -o publish-wpf --self-contained true -r win-x64 /p:PublishSingleFile=true |
| 38 | + |
| 39 | + - name: Zip the published files (WPF) |
| 40 | + run: | |
| 41 | + cd publish-wpf |
| 42 | + Compress-Archive -Path * -DestinationPath ../Xceed.Wpf.Words.Sample.zip |
| 43 | + shell: pwsh |
| 44 | + |
| 45 | + # ===== CONSOLE SAMPLE BUILD ===== |
| 46 | + - name: Restore dependencies (Console) |
| 47 | + run: dotnet restore Xceed.Console.Words.Sample/Xceed.Console.Words.Sample.csproj |
| 48 | + |
| 49 | + - name: Replace License Key (Console) |
| 50 | + run: | |
| 51 | + $content = Get-Content -Path .\Xceed.Console.Words.Sample\Program.cs -Raw |
| 52 | + $content = $content -replace 'LICENSE_KEY_PLACEHOLDER', '${{ secrets.WORDS_LICENSE }}' |
| 53 | + Set-Content -Path .\Xceed.Console.Words.Sample\Program.cs -Value $content |
| 54 | + shell: pwsh |
| 55 | + |
| 56 | + - name: Build (Console) |
| 57 | + run: dotnet build Xceed.Console.Words.Sample/Xceed.Console.Words.Sample.csproj --configuration Release --no-restore |
| 58 | + |
| 59 | + - name: Publish (Console) |
| 60 | + run: dotnet publish Xceed.Console.Words.Sample/Xceed.Console.Words.Sample.csproj -c Release -o publish-console --self-contained true -r win-x64 /p:PublishSingleFile=true |
| 61 | + |
| 62 | + - name: Zip the published files (Console) |
| 63 | + run: | |
| 64 | + cd publish-console |
| 65 | + Compress-Archive -Path * -DestinationPath ../Xceed.Console.Words.Sample.zip |
| 66 | + shell: pwsh |
| 67 | + |
| 68 | + # ===== WINFORMS SAMPLE BUILD ===== |
| 69 | + - name: Setup MSBuild |
| 70 | + |
| 71 | + with: |
| 72 | + vs-version: '16.0' # Opcional: especifica la versión de Visual Studio si es necesario |
24 | 73 |
|
25 | | - - name: Copy files |
26 | | - run: | |
27 | | - rm -rf target/* |
28 | | - cp -r source/Src/SamplesByPlatforms/* target/ |
| 74 | + - name: Restore dependencies (WinForms) |
| 75 | + run: nuget restore Xceed.WinForm.Words.Sample/Xceed.WinForm.Words.Sample.csproj |
| 76 | + |
| 77 | + - name: Replace License Key (WinForms) |
| 78 | + run: | |
| 79 | + $content = Get-Content -Path .\Xceed.WinForm.Words.Sample\Form1.cs -Raw |
| 80 | + $content = $content -replace 'LICENSE_KEY_PLACEHOLDER', '${{ secrets.WORDS_LICENSE }}' |
| 81 | + Set-Content -Path .\Xceed.WinForm.Words.Sample\Form1.cs -Value $content |
| 82 | + shell: pwsh |
| 83 | + |
| 84 | + - name: Build (WinForms) |
| 85 | + run: msbuild Xceed.WinForm.Words.Sample/Xceed.WinForm.Words.Sample.csproj /p:Configuration=Release |
| 86 | + |
| 87 | + - name: Zip the published files (WinForms) |
| 88 | + run: | |
| 89 | + Compress-Archive -Path Xceed.WinForm.Words.Sample\bin\Release\* -DestinationPath Xceed.WinForm.Words.Sample.zip |
| 90 | + shell: pwsh |
| 91 | + |
| 92 | + # ===== BLAZOR SAMPLE BUILD ===== |
| 93 | + - name: Restore dependencies (Blazor) |
| 94 | + run: dotnet restore Xceed.Blazor.Words.Sample/Xceed.Blazor.Words.Sample.csproj |
| 95 | + |
| 96 | + - name: Replace License Key (Blazor) |
| 97 | + run: | |
| 98 | + $content = Get-Content -Path .\Xceed.Blazor.Words.Sample\Program.cs -Raw |
| 99 | + $content = $content -replace 'LICENSE_KEY_PLACEHOLDER', '${{ secrets.WORDS_LICENSE }}' |
| 100 | + Set-Content -Path .\Xceed.Blazor.Words.Sample\Program.cs -Value $content |
| 101 | + shell: pwsh |
| 102 | + |
| 103 | + - name: Update base href in index.html (Blazor) |
| 104 | + run: | |
| 105 | + $indexPath = ".\Xceed.Blazor.Words.Sample\wwwroot\index.html" |
| 106 | + $content = Get-Content -Path $indexPath -Raw |
| 107 | + $content = $content -replace '<base href=".*" />', '<base href="/Xceed-Words-Samples/" />' |
| 108 | + Set-Content -Path $indexPath -Value $content |
| 109 | + shell: pwsh |
| 110 | + |
| 111 | + - name: Build (Blazor) |
| 112 | + run: dotnet build Xceed.Blazor.Words.Sample/Xceed.Blazor.Words.Sample.csproj --configuration Release --no-restore |
| 113 | + |
| 114 | + - name: Publish (Blazor) |
| 115 | + run: dotnet publish Xceed.Blazor.Words.Sample/Xceed.Blazor.Words.Sample.csproj -c Release -o publish-blazor |
| 116 | + |
| 117 | + - name: Zip the published files (Blazor) |
| 118 | + run: | |
| 119 | + cd publish-blazor |
| 120 | + Compress-Archive -Path * -DestinationPath ../Xceed.Blazor.Words.Sample.zip |
| 121 | + shell: pwsh |
| 122 | + |
| 123 | + # ===== VERSIONING AND PUBLIC REPO HANDLING ===== |
| 124 | + - name: Set version info |
| 125 | + id: version |
| 126 | + run: | |
| 127 | + if ($env:GITHUB_REF.StartsWith("refs/tags/")) { |
| 128 | + $VERSION = $env:GITHUB_REF.Substring(10) |
| 129 | + } else { |
| 130 | + $VERSION = "build-$(Get-Date -Format 'yyyy.MM.dd-HHmm')" |
| 131 | + } |
| 132 | + echo "VERSION=$VERSION" >> $env:GITHUB_OUTPUT |
| 133 | + shell: pwsh |
| 134 | + |
| 135 | + - name: Setup public repository |
| 136 | + id: setup-public-repo |
| 137 | + run: | |
| 138 | + mkdir -p public-repo |
| 139 | + cd public-repo |
| 140 | + |
| 141 | + git config --global user.name "GitHub Actions Bot" |
| 142 | + git config --global user.email "<>" |
| 143 | + |
| 144 | + echo "Cloning public repo..." |
| 145 | + if (git clone https://x-access-token:${{ secrets.DEPLOY_KEY }}@github.com/xceedsoftware/Xceed-Words-Samples.git . 2>&1) { |
| 146 | + echo "Repositorio clonado exitosamente" |
| 147 | + git checkout main 2>$null || git checkout -b main |
| 148 | + echo "repo_exists=true" >> $env:GITHUB_OUTPUT |
| 149 | + } else { |
| 150 | + echo "El repositorio no existe o no tiene ramas, inicializándolo..." |
| 151 | + git init |
| 152 | + echo "# Xceed Words Sample Applications" > README.md |
| 153 | + echo "Este repositorio contiene versiones compiladas de las aplicaciones de ejemplo de Xceed Words (WPF, Console, y WinForms)." >> README.md |
| 154 | + echo "" >> README.md |
| 155 | + echo "## Releases" >> README.md |
| 156 | + mkdir -p releases |
| 157 | + git add README.md |
| 158 | + git commit -m "Initial commit" |
| 159 | + git branch -M main |
| 160 | + git remote add origin https://x-access-token:${{ secrets.DEPLOY_KEY }}@github.com/xceedsoftware/Xceed-Words-Samples.git |
| 161 | + git push -u origin main |
| 162 | + echo "repo_exists=false" >> $env:GITHUB_OUTPUT |
| 163 | + } |
| 164 | + shell: pwsh |
| 165 | + |
| 166 | + - name: Copy release files to public repository |
| 167 | + run: | |
| 168 | + $VERSION = "${{ steps.version.outputs.VERSION }}" |
| 169 | + mkdir -p "public-repo/releases/$VERSION" |
| 170 | + |
| 171 | + # Copiar los cuatro archivos ZIP |
| 172 | + cp Xceed.Wpf.Words.Sample.zip "public-repo/releases/$VERSION/" |
| 173 | + cp Xceed.Console.Words.Sample.zip "public-repo/releases/$VERSION/" |
| 174 | + cp Xceed.WinForm.Words.Sample.zip "public-repo/releases/$VERSION/" |
| 175 | + cp Xceed.Blazor.Words.Sample.zip "public-repo/releases/$VERSION/" |
| 176 | + |
| 177 | + if ($env:GITHUB_REF.StartsWith("refs/tags/")) { |
| 178 | + $VERSION | Set-Content -Path "public-repo/latest.txt" -Force |
| 179 | + } |
| 180 | + shell: pwsh |
| 181 | + |
| 182 | + - name: Commit and push to public repository |
| 183 | + run: | |
| 184 | + cd public-repo |
| 185 | + git add . |
| 186 | + git commit -m "Release ${{ steps.version.outputs.VERSION }}" |
| 187 | + git push origin main |
| 188 | + shell: pwsh |
| 189 | + |
| 190 | + # ===== CREATE RELEASES WITH ALL THREE ASSETS ===== |
| 191 | + - name: Create Release in public repository |
| 192 | + env: |
| 193 | + GITHUB_TOKEN: ${{ secrets.DEPLOY_KEY }} |
| 194 | + run: | |
| 195 | + # Instalar jq si no está disponible |
| 196 | + apt-get update && apt-get install -y jq |
| 197 | + |
| 198 | + # Crear la release a través de la API de GitHub |
| 199 | + RESPONSE=$(curl -X POST \ |
| 200 | + -H "Authorization: token $GITHUB_TOKEN" \ |
| 201 | + -H "Accept: application/vnd.github.v3+json" \ |
| 202 | + https://api.github.com/repos/xceedsoftware/Xceed-Words-Samples/releases \ |
| 203 | + -d '{ |
| 204 | + "tag_name": "auto-${{ steps.version.outputs.VERSION }}", |
| 205 | + "name": "Xceed Words Samples Release ${{ steps.version.outputs.VERSION }}", |
| 206 | + "body": "Release for Xceed Words Samples version ${{ steps.version.outputs.VERSION }} (WPF, Console, WinForms, and Blazor)", |
| 207 | + "draft": false, |
| 208 | + "prerelease": false, |
| 209 | + "make_latest": "true" |
| 210 | + }') |
| 211 | + |
| 212 | + # Extraer el ID de la release creada |
| 213 | + RELEASE_ID=$(echo $RESPONSE | jq -r '.id') |
| 214 | + |
| 215 | + # Subir los archivos ZIP como assets |
| 216 | + # WPF Sample |
| 217 | + curl -X POST \ |
| 218 | + -H "Authorization: token $GITHUB_TOKEN" \ |
| 219 | + -H "Content-Type: application/zip" \ |
| 220 | + -H "Accept: application/vnd.github.v3+json" \ |
| 221 | + --data-binary @Xceed.Wpf.Words.Sample.zip \ |
| 222 | + "https://uploads.github.com/repos/xceedsoftware/Xceed-Words-Samples/releases/$RELEASE_ID/assets?name=Xceed.Wpf.Words.Sample.zip" |
| 223 | + |
| 224 | + # Console Sample |
| 225 | + curl -X POST \ |
| 226 | + -H "Authorization: token $GITHUB_TOKEN" \ |
| 227 | + -H "Content-Type: application/zip" \ |
| 228 | + -H "Accept: application/vnd.github.v3+json" \ |
| 229 | + --data-binary @Xceed.Console.Words.Sample.zip \ |
| 230 | + "https://uploads.github.com/repos/xceedsoftware/Xceed-Words-Samples/releases/$RELEASE_ID/assets?name=Xceed.Console.Words.Sample.zip" |
| 231 | + |
| 232 | + # WinForms Sample |
| 233 | + curl -X POST \ |
| 234 | + -H "Authorization: token $GITHUB_TOKEN" \ |
| 235 | + -H "Content-Type: application/zip" \ |
| 236 | + -H "Accept: application/vnd.github.v3+json" \ |
| 237 | + --data-binary @Xceed.WinForm.Words.Sample.zip \ |
| 238 | + "https://uploads.github.com/repos/xceedsoftware/Xceed-Words-Samples/releases/$RELEASE_ID/assets?name=Xceed.WinForm.Words.Sample.zip" |
29 | 239 | |
30 | | - - name: Commit and push changes |
31 | | - run: | |
32 | | - cd target |
33 | | - git config user.name "GitHub Action" |
34 | | - git config user.email "action@github.com" |
35 | | - git add . |
36 | | - git diff --quiet && git diff --staged --quiet || git commit -m "Sync from public repo: ${{ github.event.after }}" |
37 | | - git push |
| 240 | + # Blazor Sample |
| 241 | + curl -X POST \ |
| 242 | + -H "Authorization: token $GITHUB_TOKEN" \ |
| 243 | + -H "Content-Type: application/zip" \ |
| 244 | + -H "Accept: application/vnd.github.v3+json" \ |
| 245 | + --data-binary @Xceed.Blazor.Words.Sample.zip \ |
| 246 | + "https://uploads.github.com/repos/xceedsoftware/Xceed-Words-Samples/releases/$RELEASE_ID/assets?name=Xceed.Blazor.Words.Sample.zip" |
| 247 | + shell: bash |
0 commit comments