Remotely/.github/workflows/build.yml
2021-07-29 07:57:36 -07:00

134 lines
4.8 KiB
YAML

# IMPORTANT:
# 1. The Server URL must include the scheme (e.g. https://app.remotely.one).
# 2. The Server Runtime Identifier determines the target operating system
# for which to build the server. The default "linux-x64" will usually work
# for most Linux-based operating systems. You can see a full list at
# https://docs.microsoft.com/en-us/dotnet/core/rid-catalog.
# 2. You'll want to keep your fork updated so you can build the latest
# changes. On the GitHub page for your repo, you'll see a message that says,
# "This branch is ## commits behind lucent-sea:master."
#
# Click the "Pull request" link next to it.
#
# On the next page click the "switching the base" link. Now it's pulling from
# my repo into yours. Create and complete the pull request to update your repo.
#
# Once your branch has been updated, you can run this workflow again
# to build the latest version.
name: Build
on:
workflow_dispatch:
inputs:
serverUrl:
description: 'Server URL'
required: true
rid:
description: 'Server Runtime Identifier'
required: false
default: "linux-x64"
jobs:
build:
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
Configuration: Release
PfxBase64: ${{ secrets.BASE64_ENCODED_PFX }}
PfxKey: ${{ secrets.PFX_KEY }}
ServerUrl: ${{ github.event.inputs.serverUrl }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
# Comment out the below 'repository' line if you want to build fro
# your fork instead of the author's.
repository: lucent-sea/Remotely
fetch-depth: 0
# Test the Server URL to make sure it's valid
- name: Check Server URL Format
run: |
$Result = ""
if (![System.Uri]::TryCreate($env:ServerUrl, [System.UriKind]::Absolute, [ref] $Result)) {
throw "Server URL is not in the correct format. It should be fully qualified with scheme and host (e.g. https://app.remotely.one)."
}
# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v1.7.2
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1
# 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 "CurrentVersion=$CurrentVersion" >> $GITHUB_ENV
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:ServerUrl -CurrentVersion $env:CurrentVersion -RID linux-x64 -OutDir "$env:GITHUB_WORKSPACE\publish"
# Upload build artifact to be deployed from Ubuntu runner
- name: Upload build artifact
uses: actions/upload-artifact@v2
with:
path: ./publish/
# Remove the pfx
- name: Remove the pfx
run: |
if (Test-Path "$env:GITHUB_WORKSPACE\GitHubActionsWorkflow.pfx") {
Remove-Item -path "$env:GITHUB_WORKSPACE\GitHubActionsWorkflow.pfx"
}