From 362cf03084728edb0a04c9e9b7d19243298064ef Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Mon, 6 Jan 2025 22:42:20 +0100 Subject: [PATCH] Add initial release github action (#133) --- .github/workflows/{ci.yml => prerelease.yml} | 4 +- .github/workflows/release.yml | 59 ++++++++++++++++++++ build/BuildInformation.fs | 25 +++++++-- build/CommandLine.fs | 2 + build/Targets.fs | 17 ++++++ build/build.fsproj | 1 + 6 files changed, 101 insertions(+), 7 deletions(-) rename .github/workflows/{ci.yml => prerelease.yml} (98%) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/prerelease.yml similarity index 98% rename from .github/workflows/ci.yml rename to .github/workflows/prerelease.yml index 0193648a..2168fd43 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/prerelease.yml @@ -1,11 +1,9 @@ -name: CI +name: Pre-release main branch on: push: branches: - main - tags: - - "*.*.*" permissions: contents: read diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..616ba16a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,59 @@ +name: Pre-release main branch + +on: + release: + types: [published] + +permissions: + contents: read + packages: write + +jobs: + containers: + runs-on: ubuntu-latest + outputs: + full-version: ${{ steps.bootstrap.outputs.full-version }} + major-version: ${{ steps.bootstrap.outputs.major-version }} + + steps: + - uses: actions/checkout@v4 + + - name: Bootstrap Action Workspace + id: bootstrap + uses: ./.github/actions/bootstrap + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + + - name: Publish Containers + run: ./build.sh publishcontainers + + release: + needs: [containers] + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + runs-on: ${{ matrix.os }} + outputs: + full-version: ${{ steps.bootstrap.outputs.full-version }} + major-version: ${{ steps.bootstrap.outputs.major-version }} + + steps: + - uses: actions/checkout@v4 + + - name: Bootstrap Action Workspace + id: bootstrap + uses: ./.github/actions/bootstrap + + - name: Publish Binaries + run: ./build.sh publishzip + + - name: Attach Distribution to release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release upload ${{ github.ref_name }} .artifacts/publish/docs-builder/release/*.zip diff --git a/build/BuildInformation.fs b/build/BuildInformation.fs index 6e61ff1b..d5b068b3 100644 --- a/build/BuildInformation.fs +++ b/build/BuildInformation.fs @@ -6,6 +6,7 @@ module BuildInformation open System open System.IO +open System.Runtime.InteropServices open System.Threading open System.Xml.Linq open System.Xml.XPath @@ -63,8 +64,24 @@ type OS = | OSX | Windows | Linux with static member Current = - match int Environment.OSVersion.Platform with - | 4 | 128 -> Linux - | 6 -> OSX - | _ -> Windows + match 1 with + | _ when RuntimeInformation.IsOSPlatform OSPlatform.OSX -> OSX + | _ when RuntimeInformation.IsOSPlatform OSPlatform.Windows -> Windows + | _ -> Linux + + static member Name = + match OS.Current with + | Linux -> "linux" + | OSX -> "mac" + | Windows -> "win" + + static member Arch = + match RuntimeInformation.ProcessArchitecture with + | Architecture.X86 -> "x86" + | Architecture.X64 -> "x64" + | Architecture.Arm -> "arm" + | Architecture.Arm64 -> "arm64" + | _ -> "unknown" + + diff --git a/build/CommandLine.fs b/build/CommandLine.fs index 7c74c1e4..faf15f82 100644 --- a/build/CommandLine.fs +++ b/build/CommandLine.fs @@ -25,6 +25,7 @@ type Build = | [] Publish | [] PublishBinaries | [] PublishContainers + | [] PublishZip | [] ReleaseNotes | [] Release @@ -51,6 +52,7 @@ with | PristineCheck | PublishBinaries | PublishContainers + | PublishZip | ValidateLicenses | ReleaseNotes | Compile diff --git a/build/Targets.fs b/build/Targets.fs index e3a733d4..4482d2ca 100644 --- a/build/Targets.fs +++ b/build/Targets.fs @@ -57,6 +57,22 @@ let private pristineCheck (arguments:ParseResults) = let private publishBinaries _ = exec { run "dotnet" "publish" "src/docs-builder/docs-builder.csproj" } exec { run "dotnet" "publish" "src/docs-generator/docs-generator.csproj" } + Zip.zip + ".artifacts/publish/docs-builder/release" + $"docs-builder-%s{OS.Name}-{OS.Arch}.zip" + [".artifacts/publish/docs-builder/release/docs-builder"] + +let private publishZip _ = + exec { run "dotnet" "publish" "src/docs-builder/docs-builder.csproj" } + let binary = match OS.Current with Windows -> "docs-builder.exe" | _ -> "docs-builder" + Zip.zip + ".artifacts/publish/docs-builder/release" + $".artifacts/publish/docs-builder/release/docs-builder-%s{OS.Name}-{OS.Arch}.zip" + [ + $".artifacts/publish/docs-builder/release/%s{binary}"; + ".artifacts/publish/docs-builder/release/LICENSE.txt"; + ".artifacts/publish/docs-builder/release/NOTICE.txt" + ] let private publishContainers _ = @@ -155,6 +171,7 @@ let Setup (parsed:ParseResults) = | PristineCheck -> Build.Step pristineCheck | PublishBinaries -> Build.Step publishBinaries | PublishContainers -> Build.Step publishContainers + | PublishZip -> Build.Step publishZip | ValidateLicenses -> Build.Step validateLicenses | ReleaseNotes -> Build.Step generateReleaseNotes diff --git a/build/build.fsproj b/build/build.fsproj index fe8bb1fc..e68967ac 100644 --- a/build/build.fsproj +++ b/build/build.fsproj @@ -11,6 +11,7 @@ +