From 8a10ebc780eac6a128ddd5e0fab22694c81f2259 Mon Sep 17 00:00:00 2001 From: Zefek <32429493+Zefek@users.noreply.github.com> Date: Thu, 9 Jul 2026 11:28:20 +0200 Subject: [PATCH 1/4] Enhance deploy workflow with repository variable Add repository variable and update deployment steps. --- .github/workflows/deploy.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 43a5259..43a4b18 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -33,6 +33,7 @@ jobs: ARTIFACT_NAME: ${{ github.event.inputs.artifact_name || inputs.artifact_name || 'IoTDeployer' }} SERVICE_NAME: ${{ vars.SERVICE_NAME }} TARGET_PATH: ${{ vars.TARGET_PATH }} + REPO: ${{ vars.REPO }} steps: - name: Kontrola vstupů @@ -41,6 +42,7 @@ jobs: if (-not $env:ARTIFACT_RUN_ID) { throw 'Chybí artifact_run_id v payloadu deploymentu.' } if (-not $env:SERVICE_NAME) { throw 'Chybí proměnná prostředí SERVICE_NAME (vars.SERVICE_NAME).' } if (-not $env:TARGET_PATH) { throw 'Chybí proměnná prostředí TARGET_PATH (vars.TARGET_PATH).' } + if (-not $env:REPO) { throw 'Chybí proměnná prostředí REPO (vars.REPO).' } - name: Stažení artefaktu uses: actions/download-artifact@v8 @@ -102,6 +104,14 @@ jobs: } } + - uses: zefek/GithubActions/Actions/deployConfig@main + with: + repo: ${{ vars.REPO }} + auth: ${{ secrets.REPO_TOKEN }} + dest: ${{ runner.temp }}\secrets + device: ArduinoSerialReader + outdir: ${{ env.TARGET_PATH }} + - name: Generate configs from secrets repo shell: powershell env: From c47f1cb6579e3cd4a41aa7a8813127b388eb1159 Mon Sep 17 00:00:00 2001 From: Zefek <32429493+Zefek@users.noreply.github.com> Date: Thu, 9 Jul 2026 11:32:23 +0200 Subject: [PATCH 2/4] Refactor deploy.yml to use env variable and clean up Updated the deployment workflow to use environment variable for repo and removed the secrets generation step. --- .github/workflows/deploy.yml | 46 +----------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 43a4b18..d89cc46 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -106,55 +106,11 @@ jobs: - uses: zefek/GithubActions/Actions/deployConfig@main with: - repo: ${{ vars.REPO }} + repo: ${{ env.REPO }} auth: ${{ secrets.REPO_TOKEN }} dest: ${{ runner.temp }}\secrets device: ArduinoSerialReader outdir: ${{ env.TARGET_PATH }} - - - name: Generate configs from secrets repo - shell: powershell - env: - SECRETS_SHARE_PATH: ${{ secrets.SECRETS_SHARE_PATH }} - SECRETS_SHARE_USER: ${{ secrets.SECRETS_SHARE_USER }} - SECRETS_SHARE_PASS: ${{ secrets.SECRETS_SHARE_PASS }} - SECRETS_REPO_NAME: ${{ secrets.SECRETS_REPO_NAME }} - DEVICE_NAME: ArduinoSerialReader - run: | - $ErrorActionPreference = 'Stop' - $secretsDir = Join-Path $env:RUNNER_TEMP 'secrets' - $mounted = $false - - try { - # Mount SMB share with read-only credentials - & net.exe use 'Z:' $env:SECRETS_SHARE_PATH /user:$env:SECRETS_SHARE_USER $env:SECRETS_SHARE_PASS | Out-Null - if ($LASTEXITCODE -ne 0) { throw "Failed to mount SMB share (exit $LASTEXITCODE)" } - $mounted = $true - - # Clone Configuration repo from the share - if (Test-Path $secretsDir) { Remove-Item $secretsDir -Recurse -Force } - $repoSource = if ($env:SECRETS_REPO_NAME) { "Z:\$env:SECRETS_REPO_NAME" } else { 'Z:\' } - git clone --depth=1 $repoSource $secretsDir - if ($LASTEXITCODE -ne 0) { throw "git clone failed (exit $LASTEXITCODE)" } - - # Run per-device deploy script - $deployScript = Join-Path $secretsDir "$env:DEVICE_NAME\deploy.ps1" - if (-not (Test-Path $deployScript)) { throw "deploy.ps1 not found at $deployScript" } - - & $deployScript -OutputDir $env:TARGET_PATH - if ($LASTEXITCODE -ne 0) { throw "deploy.ps1 failed (exit $LASTEXITCODE)" } - } - finally { - # Always clean up - whether the try block succeeded, threw, or was interrupted - if (Test-Path $secretsDir) { - Remove-Item $secretsDir -Recurse -Force -ErrorAction SilentlyContinue - } - if ($mounted) { - & net.exe use 'Z:' /delete /yes | Out-Null - } - # cleanup is best-effort; do not fail the step on a stale exit code - $global:LASTEXITCODE = 0 - } - name: Spuštění služby if: always() From 492328db25aacf23397d207d5a848b55329521ec Mon Sep 17 00:00:00 2001 From: Zefek Date: Fri, 10 Jul 2026 08:18:51 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Vol=C3=A1n=C3=AD=20sd=C3=ADlen=C3=A9ho=20wi?= =?UTF-8?q?ndows-service-deploy=20reusable=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 100 +++-------------------------------- 1 file changed, 7 insertions(+), 93 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d89cc46..5a2ae47 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,96 +25,10 @@ permissions: jobs: deploy: - runs-on: [self-hosted, dotnet] - environment: ${{ github.event.inputs.environment || 'manual' }} - - env: - ARTIFACT_RUN_ID: ${{ github.event.inputs.artifact_run_id || inputs.artifact_run_id }} - ARTIFACT_NAME: ${{ github.event.inputs.artifact_name || inputs.artifact_name || 'IoTDeployer' }} - SERVICE_NAME: ${{ vars.SERVICE_NAME }} - TARGET_PATH: ${{ vars.TARGET_PATH }} - REPO: ${{ vars.REPO }} - - steps: - - name: Kontrola vstupů - shell: powershell - run: | - if (-not $env:ARTIFACT_RUN_ID) { throw 'Chybí artifact_run_id v payloadu deploymentu.' } - if (-not $env:SERVICE_NAME) { throw 'Chybí proměnná prostředí SERVICE_NAME (vars.SERVICE_NAME).' } - if (-not $env:TARGET_PATH) { throw 'Chybí proměnná prostředí TARGET_PATH (vars.TARGET_PATH).' } - if (-not $env:REPO) { throw 'Chybí proměnná prostředí REPO (vars.REPO).' } - - - name: Stažení artefaktu - uses: actions/download-artifact@v8 - with: - name: ${{ env.ARTIFACT_NAME }} - path: ${{ runner.temp }}\deploy_payload - run-id: ${{ env.ARTIFACT_RUN_ID }} - github-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Zastavení služby - shell: powershell - run: | - $ErrorActionPreference = 'Stop' - $svc = Get-Service -Name $env:SERVICE_NAME - $servicePid = (Get-CimInstance Win32_Service -Filter "Name='$($svc.Name)'").ProcessId - - if ($svc.Status -ne 'Stopped') { - Write-Host "Zastavuji službu $($svc.Name) (PID $servicePid, stav: $($svc.Status))" - try { - $svc.Stop() - $svc.WaitForStatus('Stopped', [TimeSpan]::FromSeconds(60)) - } catch [System.ServiceProcess.TimeoutException] { - Write-Warning "Služba se nezastavila do 60s, killuji strom procesů." - if ($servicePid -gt 0) { - & taskkill /PID $servicePid /T /F | Out-Null - $svc.WaitForStatus('Stopped', [TimeSpan]::FromSeconds(15)) - } else { throw } - } - } - - if ($servicePid -gt 0) { - Wait-Process -Id $servicePid -Timeout 30 -ErrorAction SilentlyContinue - } - - Get-CimInstance Win32_Process -Filter "ParentProcessId=$servicePid" -ErrorAction SilentlyContinue | - ForEach-Object { - Write-Warning "Killuji osiřelý child proces $($_.Name) (PID $($_.ProcessId))" - Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue - } - - - name: Kopírování souborů - shell: powershell - run: | - $ErrorActionPreference = 'Stop' - if (-not (Test-Path $env:TARGET_PATH)) { - New-Item -ItemType Directory -Path $env:TARGET_PATH -Force | Out-Null - } - - $attempts = 5 - for ($i = 1; $i -le $attempts; $i++) { - try { - Copy-Item -Path "$env:RUNNER_TEMP\deploy_payload\*" -Destination $env:TARGET_PATH -Recurse -Force - break - } catch { - if ($i -eq $attempts) { throw } - $delay = 2 * $i - Write-Warning "Pokus $i/$attempts selhal: $($_.Exception.Message). Retry za $delay s." - Start-Sleep -Seconds $delay - } - } - - - uses: zefek/GithubActions/Actions/deployConfig@main - with: - repo: ${{ env.REPO }} - auth: ${{ secrets.REPO_TOKEN }} - dest: ${{ runner.temp }}\secrets - device: ArduinoSerialReader - outdir: ${{ env.TARGET_PATH }} - - - name: Spuštění služby - if: always() - shell: powershell - run: | - Start-Service -Name $env:SERVICE_NAME - (Get-Service -Name $env:SERVICE_NAME).WaitForStatus('Running', '00:01:00') + uses: Zefek/GithubActions/.github/workflows/windows-service-deploy.yml@main + with: + environment: ${{ inputs.environment }} + artifact_run_id: ${{ inputs.artifact_run_id }} + artifact_name: ${{ inputs.artifact_name }} + device_name: ArduinoSerialReader + secrets: inherit From 732a1c4add86ea99b6734c203e3e519076fb5490 Mon Sep 17 00:00:00 2001 From: Zefek Date: Fri, 10 Jul 2026 08:35:00 +0200 Subject: [PATCH 4/4] =?UTF-8?q?Odkaz=20na=20sd=C3=ADlen=C3=A9=20GithubActi?= =?UTF-8?q?ons=20p=C5=99es=20@v1=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5a2ae47..9058040 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,7 +25,7 @@ permissions: jobs: deploy: - uses: Zefek/GithubActions/.github/workflows/windows-service-deploy.yml@main + uses: Zefek/GithubActions/.github/workflows/windows-service-deploy.yml@v1 with: environment: ${{ inputs.environment }} artifact_run_id: ${{ inputs.artifact_run_id }}