Remotely/.github/workflows/deploy-via-ssh.yml
2021-07-29 07:56:42 -07:00

153 lines
5.5 KiB
YAML

# To use this workflow to deploy Remotely:
#
# 2. Create the below Secrets in GitHub.
# - BASE64_ENCODED_PFX
# - See below section to get this string.
# - PFX_KEY
# - The password for the certificate.
# - SSH_USERNAME
# - Username to use for SSH connection.
# - SSH_PASSWORD
# - The password for the above user.
# - SSH_HOSTNAME
# - The hostname or IP to use for the SSH connection.
# - SITE_URL
# - The public URL of the website (e.g. https://app.remotely.one).
#
# Secrets are created in GitHub under the repository (your forked repository,
# not the lucent-sea/Remotely repository). They are only usable by you and
# collaborators that you've allowed on your repo. After being set, they are
# not visible or displayed anywhere, even to yourself.
#
# If you don't want to sign your EXEs, skip creating the BASE64_ENCODED_PFX
# and PFX_KEY secrets. They won't be used.
#
#
# 3. Getting the Base64-Encoded PFX
# To get the base64-encoded certificate, use the below PowerShell snippet,
# using your PFX file name.
#
# $Pfx_Cert = Get-Content '.\Remotely_Cert.pfx' -Encoding Byte
# [System.Convert]::ToBase64String($Pfx_Cert) | clip
#
# The base64-encoded string is now in your clipboard. You can paste
# it into GitHub when creating the Secret.
#
# 4. Deploying via SSH
#
#
# 5. Keeping Your Fork Updated
# You'll want to keep your fork updated so you can deploy the latest
# changes. There are a few ways to do it, and they're easy to find
# with a little Googling.
#
# Once your release branch has been updated, you can run the
# workflow again manually in GitHub to re-deploy.
name: Deploy via SSH
on:
# Uncomment these for automatic deployment.
# push:
# branches: [ master ]
# pull_request:
# branches: [ master ]
workflow_dispatch:
jobs:
build:
strategy:
matrix:
configuration: [Release]
runs-on: windows-latest # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
env:
Solution_Name: Remotely.sln # Replace with your solution name, i.e. MyWpfApp.sln.
Configuration: ${{ matrix.configuration }}
Test_Project_Path: Tests\Tests.csproj # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.
PfxBase64: ${{ secrets.BASE64_ENCODED_PFX }}
PfxKey: ${{ secrets.PFX_KEY }}
SshUsername: ${{ secrets.SSH_USERNAME }}
SshPassword: ${{ secrets.SSH_PASSWORD }}
SshHostname: ${{ secrets.SSH_HOSTNAME }}
SiteUrl: ${{ secrets.SITE_URL }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@2008f912f56e61277eefaac6d1888b750582aa16
# Execute all unit tests in the solution
- name: Execute unit tests
run: dotnet test
# Restore the application to populate the obj folder with RuntimeIdentifiers
- name: Restore the application
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
# Decode the base 64 encoded pfx and save the Signing_Certificate
- name: Decode the pfx
run: |
if (!($env:PfxBase64)) {
echo "Skipping cert signing because Base64_Encoded_Pfx secret is missing."
return
}
echo "Creating Pfx for signing assemblies."
$pfx_cert_byte = [System.Convert]::FromBase64String($env:PfxBase64)
$certificatePath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath GitHubActionsWorkflow.pfx
echo "Writing file to $certificatePath."
[IO.File]::WriteAllBytes($certificatePath, $pfx_cert_byte)
# Store the assembly version in an environment variable
- name: Set current version
shell: powershell
run: |
$VersionString = git show -s --format=%ci
$VersionDate = [DateTimeOffset]::Parse($VersionString)
$Year = $VersionDate.Year.ToString()
$Month = $VersionDate.Month.ToString().PadLeft(2, "0")
$Day = $VersionDate.Day.ToString().PadLeft(2, "0")
$Hour = $VersionDate.Hour.ToString().PadLeft(2, "0")
$Minute = $VersionDate.Minute.ToString().PadLeft(2, "0")
$CurrentVersion = "$Year.$Month.$Day.$Hour$Minute"
echo "::set-env name=CurrentVersion::$CurrentVersion"
# This was needed in Azure Pipelines.
#[System.Console]::WriteLine("##vso[task.setvariable variable=CurrentVersion]$CurrentVersion")
Write-Host "Setting current version to $CurrentVersion."
# Run the Publish script to build clients and server.
- name: Run Publish script
shell: powershell
run: .\Utilities\Publish.ps1 -CertificatePath "$env:GITHUB_WORKSPACE\GitHubActionsWorkflow.pfx" -CertificatePassword $env:PfxKey -Hostname $env:SiteUrl -CurrentVersion $env:CurrentVersion -RID linux-x64 -OutDir ".\publish"
# Uncomment the below to enable deployment to the server.
# Publish server via SSH
#- name: Publish
# run: |
# echo "Publishing with configuration $env:Configuration."
#
# Remove the pfx
- name: Remove the pfx
run: Remove-Item -path $env:GITHUB_WORKSPACE\GitHubActionsWorkflow.pfx