Skip to content

Commit

Permalink
Showing 10 changed files with 915 additions and 87 deletions.
45 changes: 0 additions & 45 deletions .github/workflows/build.yml

This file was deleted.

120 changes: 120 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#
# https://docs.github.com/en/actions/migrating-to-github-actions/automated-migrations/migrating-from-azure-devops-with-github-actions-importer#environment-variable-mapping
#
# bare in mind that variable substitution is not supported in github at all so we cant do stuff like this
#
# env:
# Build_Artifacts_Folderpath: $build_repository_folderpath/Artifacts
#

name: '🏗 📦 Build, Pack & Deploy Nugets'

env:
BUILD_REPOSITORY_FOLDERPATH: ${{ github.workspace }}

LAERDAL_SOURCE_BRANCH: ${{ github.ref }}
LAERDAL_REPOSITORY_PATH: ${{ github.repository }}

SCL_GITHUB_ACCESS_TOKEN: ${{ secrets.SCL_GITHUB_ACCESS_TOKEN }}
SCL_NUGET_ORG_FEED_API_KEY: ${{ secrets.NUGET_ORG_FEED_API_KEY }}
SCL_AZURE_ARTIFACTS_API_KEY: ${{ secrets.SCL_AZURE_ARTIFACTS_API_KEY }}
SCL_GITHUB_NUGET_FEED_USERNAME: ${{ secrets.SCL_GITHUB_NUGET_FEED_USERNAME }}

on:
workflow_call: # so that other workflows can trigger this
workflow_dispatch: # allows to run this workflow manually from the actions tab

push:
branches:
- '**' # '*' matches zero or more characters but does not match the `/` character '**' matches zero or more of any character

pull_request:
branches:
- '**'


jobs:

build:

runs-on: 'windows-2022'
timeout-minutes: 5

steps:

- name: '🔽 Checkout'
uses: 'actions/checkout@v4'
with:
fetch-tags: true # https://github.com/actions/checkout/issues/1471#issuecomment-1771231294
fetch-depth: 0

- name: '🛠 Setup Build Environment'
shell: 'bash'
run: |
chmod +x "${{env.BUILD_REPOSITORY_FOLDERPATH}}/Laerdal.Scripts/Laerdal.SetupBuildEnvironment.sh" \
&& \
"${{env.BUILD_REPOSITORY_FOLDERPATH}}/Laerdal.Scripts/Laerdal.SetupBuildEnvironment.sh" \
"https://nuget.pkg.github.com/Laerdal/index.json" \
"${{ env.SCL_GITHUB_NUGET_FEED_USERNAME }}" \
"${{ env.SCL_GITHUB_ACCESS_TOKEN }}" \
"${{ env.BUILD_REPOSITORY_FOLDERPATH }}/Artifacts"
# we need to manually install java11 because it is needed by the latest windows vm-images that run on
# msbuild version 17.8.3 that started rolling out around 20 Nov 2023 https://stackoverflow.com/a/77519085/863651
- name: '🛠 Set Up JDK 11'
uses: 'actions/setup-java@v2'
with:
java-version: '11'
architecture: 'x64'
distribution: 'adopt'

- name: '🏗 📦 Build, Pack & Announce New Release (if appropriate)'
shell: 'bash'
run: |
cd "${{env.BUILD_REPOSITORY_FOLDERPATH}}/Laerdal.Scripts" \
&& \
dotnet \
msbuild \
"Laerdal.Builder.targets" \
\
-p:PackageOutputPath="${{ env.BUILD_REPOSITORY_FOLDERPATH }}/Artifacts" \
-p:Laerdal_Source_Branch="${{ env.LAERDAL_SOURCE_BRANCH }}" \
-p:Laerdal_Repository_Path="${{ env.LAERDAL_REPOSITORY_PATH }}" \
-p:Laerdal_Github_Access_Token="${{ env.SCL_GITHUB_ACCESS_TOKEN }}"
- name: '⬆️ Upload Artifacts' # to share with other workflows https://stackoverflow.com/a/77663335/863651
uses: 'actions/upload-artifact@v4'
with:
name: 'Artifacts'
path: '${{env.BUILD_REPOSITORY_FOLDERPATH}}/Artifacts/**/*'
if-no-files-found: error

- name: '🚀 Publish to the Laerdal Nuget Server on Github' # https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry
shell: 'bash'
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
run: |
cd "${{env.BUILD_REPOSITORY_FOLDERPATH}}/Artifacts/" \
&& \
ls . \
&& \
dotnet \
nuget \
push \
--source "https://nuget.pkg.github.com/Laerdal/index.json" \
--api-key "${{env.SCL_GITHUB_ACCESS_TOKEN}}" \
*nupkg
- name: '🚀 Publish to the Nuget.org'
shell: 'bash'
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
run: |
cd "${{env.BUILD_REPOSITORY_FOLDERPATH}}/Artifacts/" \
&& \
ls . \
&& \
dotnet \
nuget \
push \
--source "https://api.nuget.org/v3/index.json" \
--api-key "${{env.SCL_NUGET_ORG_FEED_API_KEY}}" \
*nupkg
30 changes: 18 additions & 12 deletions Laerdal.Dfu.sln
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Laerdal.Dfu", "Laerdal.Dfu\Laerdal.Dfu.csproj", "{A837B5B9-0B0C-48F6-A342-4060EC71E2C9}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Laerdal.Dfu", "Laerdal.Dfu\Laerdal.Dfu.csproj", "{0A938850-09F9-44A5-825F-84C932074A29}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Misc", "_Misc", "{37EBD209-B465-4483-B6A9-46EAC9FE20EF}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
LICENSE = LICENSE
Laerdal.Scripts\Laerdal.Version.sh = Laerdal.Scripts\Laerdal.Version.sh
Laerdal.Scripts\Laerdal.Builder.targets = Laerdal.Scripts\Laerdal.Builder.targets
Laerdal.Scripts\Laerdal.Changelog.sh = Laerdal.Scripts\Laerdal.Changelog.sh
Laerdal.Scripts\Laerdal.CreateNewReleaseInGithub.sh = Laerdal.Scripts\Laerdal.CreateNewReleaseInGithub.sh
Laerdal.Scripts\Laerdal.SetupBuildEnvironment.sh = Laerdal.Scripts\Laerdal.SetupBuildEnvironment.sh
.github\workflows\github-actions.yml = .github\workflows\github-actions.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A837B5B9-0B0C-48F6-A342-4060EC71E2C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A837B5B9-0B0C-48F6-A342-4060EC71E2C9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5DFF87D5-25C1-4291-A72E-EAD4129E1981}
{0A938850-09F9-44A5-825F-84C932074A29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A938850-09F9-44A5-825F-84C932074A29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A938850-09F9-44A5-825F-84C932074A29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A938850-09F9-44A5-825F-84C932074A29}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
53 changes: 25 additions & 28 deletions Laerdal.Dfu/Laerdal.Dfu.csproj
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0-ios;net7.0-android</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net7.0-ios;net7.0-android</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>

<PropertyGroup>
<Laerdal_Package_Name>Laerdal.Dfu</Laerdal_Package_Name>
<Laerdal_Package_Tags>Ble;Tools;Dfu;Bluetooth;Nordic;Semiconductor</Laerdal_Package_Tags>
<Laerdal_Package_Copyright>Laerdal Medical, Francois Raminosona</Laerdal_Package_Copyright>
<Laerdal_Package_Description>Wrapper around Nordic.Dfu</Laerdal_Package_Description>
</PropertyGroup>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
</PropertyGroup>

<!-- ==================== VERSION ==================== -->
<PropertyGroup>
<Laerdal_Version_Major>1</Laerdal_Version_Major>
<Laerdal_Version_Minor>27</Laerdal_Version_Minor>
<Laerdal_Version_Build Condition="'$(BUILD_BUILDID)' != ''">$(BUILD_BUILDID)</Laerdal_Version_Build> <!-- Azure DevOps, Last build was 43857 -->
<Laerdal_Version_Build Condition="'$(GITHUB_RUN_NUMBER)' != ''">$([MSBuild]::Add(8, $(GITHUB_RUN_NUMBER)))</Laerdal_Version_Build> <!-- GitHub Actions, auto-increment from 0 -->
<Laerdal_Version_Build Condition="'$(CI_PIPELINE_IID)' != ''">$([MSBuild]::Add(8, $(CI_PIPELINE_IID)))</Laerdal_Version_Build> <!-- GitLab, auto-increment from 0 -->
<Laerdal_Version_Build Condition="'$(Laerdal_Version_Build)' == ''">0</Laerdal_Version_Build> <!-- Fallback value -->
<PropertyGroup>
<Laerdal_Package_Name>Laerdal.Dfu</Laerdal_Package_Name>
<Laerdal_Package_Tags>Ble;Tools;Dfu;Bluetooth;Nordic;Semiconductor</Laerdal_Package_Tags>
<Laerdal_Package_Copyright>Laerdal Medical, Francois Raminosona</Laerdal_Package_Copyright>
<Laerdal_Package_Description>Wrapper around Nordic.Dfu</Laerdal_Package_Description>
</PropertyGroup>

<Laerdal_Version Condition="'$(Laerdal_Version)' == ''">$(Laerdal_Version_Major).$(Laerdal_Version_Minor).$(Laerdal_Version_Build)</Laerdal_Version>
</PropertyGroup>
<!-- ==================== VERSION ==================== -->
<PropertyGroup>
<Laerdal_Version_Major Condition=" '$(Laerdal_Version_Major)' == '' ">1</Laerdal_Version_Major>
<Laerdal_Version_Minor Condition=" '$(Laerdal_Version_Minor)' == '' ">27</Laerdal_Version_Minor>
<Laerdal_Version_Build Condition=" '$(Laerdal_Version_Build)' == '' ">0</Laerdal_Version_Build>

<Import Project="Laerdal.targets" />
<Laerdal_Version Condition=" '$(Laerdal_Version)' == '' ">$(Laerdal_Version_Major).$(Laerdal_Version_Minor).$(Laerdal_Version_Build)</Laerdal_Version>
</PropertyGroup>

<Import Project="Laerdal.targets"/>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0-android'">
<PackageReference Include="Laerdal.Dfu.Bindings.Android" Version="2.3.0.43685" />
<PackageReference Include="Laerdal.Dfu.Bindings.Android" Version="2.3.0.43685"/>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0-ios'">
<PackageReference Include="Laerdal.Dfu.Bindings.iOS" Version="4.13.0.43870" />
<PackageReference Include="Laerdal.Dfu.Bindings.iOS" Version="4.13.0.43870"/>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Laerdal.Dfu/Laerdal.targets
Original file line number Diff line number Diff line change
@@ -25,10 +25,10 @@
<!-- ==================== PACKAGING ==================== -->
<PropertyGroup>
<!-- Laerdal_Package_Name -->
<RootNamespace>$(Laerdal_Package_Name)</RootNamespace>
<Title>$(Laerdal_Package_Name)</Title>
<PackageId>$(Laerdal_Package_Name)</PackageId>
<AssemblyName>$(Laerdal_Package_Name)</AssemblyName>
<Title>$(Laerdal_Package_Name)</Title>
<RootNamespace>$(Laerdal_Package_Name)</RootNamespace>

<!-- Laerdal_Package_Copyright -->
<Authors>$(Laerdal_Package_Copyright)</Authors>
92 changes: 92 additions & 0 deletions Laerdal.Scripts/Laerdal.Builder.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- -->
<!-- # on macos -->
<!-- dotnet msbuild "Laerdal.Scripts/Laerdal.Builder.targets" -->
<!-- -->
<!-- # on windows powershell -->
<!-- dotnet msbuild "Laerdal.Scripts\Laerdal.Builder.targets" -->
<!-- -->
<Project DefaultTargets="BuildProjects">

<PropertyGroup>
<Newline>%0A</Newline>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>

<PackageOutputPath Condition=" '$(PackageOutputPath)' == '' ">$(BUILD_ARTIFACTSTAGINGDIRECTORY)</PackageOutputPath>
<PackageOutputPath Condition=" '$(PackageOutputPath)' == '' ">$([System.IO.Path]::Combine($(MSBuildThisFileDirectory), `..`, `Artifacts/`))</PackageOutputPath>

<Laerdal_Source_Branch Condition=" '$(Laerdal_Source_Branch)' == '' ">$(BUILD_SOURCEBRANCH)</Laerdal_Source_Branch>
<Laerdal_Repository_Path Condition=" '$(Laerdal_Repository_Path)' == '' ">$(BUILD_REPOSITORY_NAME)</Laerdal_Repository_Path>
<Laerdal_Should_Tag_And_Release Condition=" '$(Laerdal_Should_Tag_And_Release)' == '' AND ( '$(Laerdal_Source_Branch)' == 'refs/heads/main' OR '$(Laerdal_Source_Branch)' == 'refs/heads/master' OR '$(Laerdal_Source_Branch)' == 'refs/heads/develop' ) ">True</Laerdal_Should_Tag_And_Release>

<Laerdal_Project>$([System.IO.Path]::Combine($(MSBuildThisFileDirectory), `..`, `Laerdal.Dfu`, `Laerdal.Dfu.csproj`))</Laerdal_Project>

<!-- version -->
<Laerdal_Version_Major Condition=" '$(Laerdal_Version_Major)' == '' ">1</Laerdal_Version_Major>
<Laerdal_Version_Minor Condition=" '$(Laerdal_Version_Minor)' == '' ">27</Laerdal_Version_Minor>

<Laerdal_Version_Build Condition=" '$(Laerdal_Version_Build)' == '' and '$(BUILD_BUILDID)' != '' ">$(BUILD_BUILDID)</Laerdal_Version_Build> <!-- Azure DevOps, Last build was 43857 -->
<Laerdal_Version_Build Condition=" '$(Laerdal_Version_Build)' == '' and '$(GITHUB_RUN_NUMBER)' != '' ">$([MSBuild]::Add(8, $(GITHUB_RUN_NUMBER)))</Laerdal_Version_Build> <!-- GitHub Actions, auto-increment from 0 -->
<Laerdal_Version_Build Condition=" '$(Laerdal_Version_Build)' == '' and '$(CI_PIPELINE_IID)' != '' ">$([MSBuild]::Add(8, $(CI_PIPELINE_IID)))</Laerdal_Version_Build> <!-- GitLab, auto-increment from 0 -->
<Laerdal_Version_Build Condition=" '$(Laerdal_Version_Build)' == '' ">0</Laerdal_Version_Build> <!-- Fallback value -->

<Laerdal_Version_Base Condition=" '$(Laerdal_Version_Base)' == '' ">$(Laerdal_Version_Major).$(Laerdal_Version_Minor).$(Laerdal_Version_Build)</Laerdal_Version_Base>
</PropertyGroup>

<Target Name="PrintConfiguration">
<Message Importance="High" Text="** Configuration = '$(Configuration)'"/>
<Message Importance="High" Text="** PackageOutputPath = '$(PackageOutputPath)'"/>

<Message Importance="High" Text="** Laerdal_Version_Base = '$(Laerdal_Version_Base)'"/>
<Message Importance="High" Text="** Laerdal_Source_Branch = '$(Laerdal_Source_Branch)'"/>
<Message Importance="High" Text="** Laerdal_Repository_Path = '$(Laerdal_Repository_Path)'"/>
<!-- <Message Importance="High" Text="** Laerdal_Github_Access_Token ='$(Laerdal_Github_Access_Token)'"/> dont -->
</Target>

<!-- BUILD -->
<Target Name="BuildProjects">
<!-- REQUIRED PARAMETERS -->
<Error Condition=" '$(Configuration)' == '' " Text="'Configuration' has to be set. Please call this script again with the argument '/p:Configuration=...'" />
<Error Condition=" '$(PackageOutputPath)' == '' " Text="'PackageOutputPath' has to be set. Please call this script again with the argument '/p:PackageOutputPath=...'" />
<Error Condition=" '$(Laerdal_Version_Base)' == '' " Text="'Laerdal_Version_Base' has to be set. Please call this script again with the argument '/p:Laerdal_Version_Base=...'" />

<!-- PARAMETERS -->
<PropertyGroup>
<_Laerdal_Build_Parameters>$(_Laerdal_Build_Parameters);Configuration=$(Configuration)</_Laerdal_Build_Parameters>
<_Laerdal_Build_Parameters>$(_Laerdal_Build_Parameters);Laerdal_Version=$(Laerdal_Version_Base)</_Laerdal_Build_Parameters>
<_Laerdal_Build_Parameters>$(_Laerdal_Build_Parameters);PackageOutputPath=$(PackageOutputPath)</_Laerdal_Build_Parameters>
</PropertyGroup>

<!-- RUN -->
<MSBuild Projects="$(Laerdal_Project)" Properties="$(_Laerdal_Build_Parameters)" Targets="Restore;Build"/>
</Target>

<!-- GITHUB RELEASE -->
<Target Name="CreateGithubReleaseWithTag"
Condition=" '$(Laerdal_Should_Tag_And_Release)' == 'True' "
AfterTargets="BuildProjects">

<Error Condition=" '$(Laerdal_Version_Base)' == '' " Text="'Laerdal_Version_Base' has to be set. Please call this script again with the argument '/p:Laerdal_Version_Base=...'" />
<Error Condition=" '$(Laerdal_Source_Branch)' == '' " Text="'Laerdal_Source_Branch' has to be set. Please call this script again with the argument '/p:Laerdal_Source_Branch=...'" />
<Error Condition=" '$(Laerdal_Repository_Path)' == '' " Text="'Laerdal_Repository_Path' has to be set. Please call this script again with the argument '/p:Laerdal_Repository_Path=...'" />
<Error Condition=" '$(Laerdal_Github_Access_Token)' == '' " Text="'Laerdal_Github_Access_Token' has to be set. Please call this script again with the argument '/p:Laerdal_Github_Access_Token=...'" />

<PropertyGroup>
<Laerdal_Create_Github_Release_Script_Filepath Condition=" '$(Laerdal_Create_Github_Release_Script_Filepath)' == '' ">$([System.IO.Path]::Combine($(MSBuildThisFileDirectory), `Laerdal.CreateNewReleaseInGithub.sh`))</Laerdal_Create_Github_Release_Script_Filepath>

<_Laerdal_Create_Github_Release_Script_Parameters>$(_Laerdal_Create_Github_Release_Script_Parameters) --git-branch '$(Laerdal_Source_Branch)'</_Laerdal_Create_Github_Release_Script_Parameters>
<_Laerdal_Create_Github_Release_Script_Parameters>$(_Laerdal_Create_Github_Release_Script_Parameters) --tag-version '$(Laerdal_Version_Base)'</_Laerdal_Create_Github_Release_Script_Parameters>
<_Laerdal_Create_Github_Release_Script_Parameters>$(_Laerdal_Create_Github_Release_Script_Parameters) --access-token '$(Laerdal_Github_Access_Token)'</_Laerdal_Create_Github_Release_Script_Parameters>
<_Laerdal_Create_Github_Release_Script_Parameters>$(_Laerdal_Create_Github_Release_Script_Parameters) --repository-path '$(Laerdal_Repository_Path)'</_Laerdal_Create_Github_Release_Script_Parameters>
</PropertyGroup>

<Message Importance="High" Text=" bash '$(Laerdal_Create_Github_Release_Script_Filepath)' $(_Laerdal_Create_Github_Release_Script_Parameters) "/>

<Exec Command=" bash '$(Laerdal_Create_Github_Release_Script_Filepath)' $(_Laerdal_Create_Github_Release_Script_Parameters) "
EchoOff="true"
ConsoleToMSBuild="true"
WorkingDirectory="$(MSBuildThisFileDirectory)/.."/>
</Target>

</Project>
102 changes: 102 additions & 0 deletions Laerdal.Scripts/Laerdal.Changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash

usage(){
echo "usage: ./Laerdal.Changelog.sh [-nv | --new-version X.Y.Z] [-o | --output version.txt] [-h | --help]"
echo "parameters:"
echo " -nv | --new-version [version] New major.minor.patch version (default is 0.0.0)"
echo " -o | --output [filename] Name of the output file"
echo " -h | --help Prints this message"
echo " -v | --verbose Verbose mode"
}

function log () {
if [[ $verbose -eq 1 ]]; then
echo "$@"
fi
}

filename="CHANGELOG.md"

while [ "$1" != "" ]; do
case $1 in
-nv | --new-version ) shift
newversion="$1"
;;
-o | --output ) shift
filename="$1"
;;
-h | --help ) usage
exit
;;
-v | --verbose ) verbose=1
;;
* ) echo
echo "### Wrong parameter: $1 ###"
echo
usage
exit 1
esac
shift
done


if [ ! -z "$newversion" ]; then
if [[ "$newversion" =~ .*"-".* ]]; then
log "New version contains a dash, skipping changelog generation"
else
currenthash=$(git show --format=%h --no-patch)
echo "$currenthash $newversion" > tags.txt
log "New version: $newversion"
fi
else
echo "" > tags.txt
fi

# Get all tags on develop and Filter out tags that are not in the format "HASH 1.2.3"
git tag --format='%(objectname:short) %(refname:short)' --sort=-version:refname --merged | grep -o '[a-z0-9]* [a-z0-9]*[.][a-z0-9]*[.][a-z0-9]*$' >> tags.txt

# Create changelog file
echo "# CHANGELOG" > "$filename"
echo "" >> "$filename"
log "Created changelog file: $filename"


# Loop through all tags and create changelog
lastline=''
while read line; do
if [ -z "$lastline" ]; then
lastline=$line
else
# Split the line into hash and version
lasthash=`echo $lastline | cut -d' ' -f1`
lastversion=`echo $lastline | cut -d' ' -f2`
hash=`echo $line | cut -d' ' -f1`

echo "## **$lastversion**" >> "$filename"
log "Added version: $lastversion"
# Get the commit message and author of the tag
git log -n 1 --pretty=tformat:"%b" $lasthash >> "$filename"

echo "" >> "$filename"

# Get all commits between the current tag and the previous tag
git log $hash..$lasthash --pretty=format:"- %s [%cn]" --no-merges >> "$filename"

echo "" >> "$filename"
echo "" >> "$filename"

# Get the commit message and author of the tag
git log -n 1 --pretty=tformat:"> by _%cn_ on _%cd_" --date=format:'%Y-%m-%d %H:%M:%S' $lasthash >> "$filename"

echo "" >> "$filename"
echo "---" >> "$filename"
echo "" >> "$filename"
lastline=$line
fi
done < tags.txt

rm -r -f tags.txt

log "Done"

exit 0
167 changes: 167 additions & 0 deletions Laerdal.Scripts/Laerdal.CreateNewReleaseInGithub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#!/bin/bash

declare VERBOSE=0
declare TAG_VERSION=""

declare GIT_BRANCH=""
declare GITHUB_ACCESS_TOKEN=""
declare GITHUB_REPOSITORY_PATH=""

function parse_arguments() {
while [[ $# -gt 0 ]]; do
case $1 in

-v | --log)
VERBOSE=1
shift
;;

-r | --repository-path)
GITHUB_REPOSITORY_PATH="$2"
shift
;;

-t | --tag-version)
TAG_VERSION="$2"
shift
;;

-b | --git-branch)
GIT_BRANCH="$2"
shift
;;

-a | --access-token)
GITHUB_ACCESS_TOKEN="$2"
shift
;;

*)
echo "Unknown option: $1"
usage
exit 1
;;

esac
shift
done

if [[ -z $GIT_BRANCH ]]; then
echo "Missing git-branch."
usage
exit 1
fi

if [[ -z $GITHUB_REPOSITORY_PATH ]]; then
echo "Missing github-repository."
usage
exit 1
fi

if [[ -z $GITHUB_ACCESS_TOKEN ]]; then
echo "Missing github-access-token."
usage
exit 1
fi

validate_tag_format "$TAG_VERSION"
}

function validate_tag_format() {
local -r tag="$1"
local -r pattern='^[0-9]+\.[0-9]+(\.[0-9]+)?$'

if ! [[ $tag =~ $pattern ]]; then
exit_with_error "Tag format is invalid: '$tag'"
fi
}

function usage() {
local -r script_name=$(basename "$0")

echo "Usage: $script_name [--verbose|-v] [--repository-path|-r]=<repository_path> [--git-branch|-b]=<branch> [--access-token|-a]=<token> [--tag-version|-t]=<version>"
}

function create_release_on_github() {
# https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release

local eventual_tag_name=""
local eventual_singleline_summary=""
if [[ $GIT_BRANCH == "refs/heads/main" || $GIT_BRANCH == "refs/heads/master" ]]; then
eventual_tag_name="v$TAG_VERSION" # builds targeting main have this simple and straightforward tag name
eventual_singleline_summary="Release $eventual_tag_name"

elif [[ $GIT_BRANCH == "refs/heads/develop" ]]; then # all builds that target develop are beta builds
eventual_tag_name="v$TAG_VERSION-beta"
eventual_singleline_summary="Beta $eventual_tag_name"

else # all other builds that dont target main are alpha builds should rarely happen in practice but just in case
eventual_tag_name="v$TAG_VERSION-alpha"
eventual_singleline_summary="Alpha $eventual_tag_name"
fi

local -r payload=$(
cat <<EOF
{
"tag_name": "$eventual_tag_name",
"target_commitish": "$GIT_BRANCH",
"name": "$eventual_singleline_summary",
"generate_release_notes": true,
"draft": false,
"prerelease": false
}
EOF
)

local -r api_url="https://api.github.com/repos/$GITHUB_REPOSITORY_PATH/releases"

echo "** Creating release on GitHub ..."

local -r response=$(
curl \
-i \
-sS \
-X "POST" \
-o /dev/null \
-d "$payload" \
-w "%{http_code}" \
-H "Content-Type:application/json" \
-H "Accept:application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" \
"$api_url"
)
local -r curl_exit_code=$?

log "** api_url=$api_url"
log "** payload=$payload"
log "** response=$response"
log "** curl_exit_code=$curl_exit_code"
if [[ $curl_exit_code -ne 0 ]]; then
exit_with_error "curl failed with exit code $?"
fi

local -r http_status_code="${response}"
if [[ $http_status_code -ge 300 ]]; then
exit_with_error "API returned HTTP status $http_status_code"
fi
}

function log() {
if [[ $VERBOSE -ne 0 ]]; then
echo "$@"
fi
}

function exit_with_error() {
echo "Error: $1"
exit 1
}

function main() {
parse_arguments "$@"
create_release_on_github
}

main "$@"
113 changes: 113 additions & 0 deletions Laerdal.Scripts/Laerdal.SetupBuildEnvironment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/bash

# set -x

# this script is meant to be used only in our azure pipelines to setup the
# build environment for the xamarin bindings its not meant to be used on localdev

# windows-2022 vmimages in azure have dotnet 8.0.100 preinstalled so we should be fine


declare -r NUGET_FEED_URL="$1"
declare -r NUGET_FEED_USERNAME="$2"
declare -r NUGET_FEED_ACCESSTOKEN="$3"

declare -r ARTIFACTS_FOLDER_PATH="$4"

if [ -z "${NUGET_FEED_URL}" ]; then
echo "##vso[task.logissue type=error]Missing 'NUGET_FEED_URL' which was expected to be parameter #1."
exit 3
fi

if [ -z "${NUGET_FEED_USERNAME}" ]; then
echo "##vso[task.logissue type=error]Missing 'NUGET_FEED_USERNAME' which was expected to be parameter #2."
exit 5
fi

if [ -z "${NUGET_FEED_ACCESSTOKEN}" ]; then
echo "##vso[task.logissue type=error]Missing 'NUGET_FEED_ACCESSTOKEN' which was expected to be parameter #3."
exit 6
fi

if [ -z "${ARTIFACTS_FOLDER_PATH}" ]; then
echo "##vso[task.logissue type=error]Missing 'ARTIFACTS_FOLDER_PATH' which was expected to be parameter #4."
exit 7
fi


echo
echo "** Dotnet SDKs:"
dotnet --list-sdks
declare exitCode=$?
if [ $exitCode != 0 ]; then
echo "##vso[task.logissue type=error]Failed to list sdks."
exit 15
fi

echo
echo "** Dotnet CLI:"
which dotnet && dotnet --version
declare exitCode=$?
if [ $exitCode != 0 ]; then
echo "##vso[task.logissue type=error]Something's wrong with 'dotnet' cli."
exit 20
fi

#
# we do our best to explicitly version-pin our workloads so as to preemptively avoid problems that
# would be bound to crop up sooner or later by blindly auto-upgrading to bleeding-edge workloads
#
cd "Laerdal.Dfu"
declare exitCode=$?
if [ $exitCode != 0 ]; then
echo "##vso[task.logissue type=error]Failed to cd to Laerdal.Dfu."
exit 30
fi

# declare dotnet_8_workload_version="8.0.3"
dotnet \
workload \
install \
maui \
ios \
android
# --from-rollback-file=https://maui.blob.core.windows.net/metadata/rollbacks/${dotnet_8_workload_version}.json # we need to install additional packages manually
declare exitCode=$?
if [ $exitCode != 0 ]; then
echo "##vso[task.logissue type=error]Failed to restore dotnet workloads."
exit 40
fi

cd -
declare exitCode=$?
if [ $exitCode != 0 ]; then
echo "##vso[task.logissue type=error]Failed to cd back to the root folder."
exit 50
fi

echo
echo "** Adding 'Artifacts' Folder as a Nuget Source (dotnet):"
mkdir -p "${ARTIFACTS_FOLDER_PATH}" && dotnet nuget add source "${ARTIFACTS_FOLDER_PATH}" --name "LocalArtifacts"
declare exitCode=$?
if [ $exitCode != 0 ]; then
echo "##vso[task.logissue type=error]Failed to add 'Artifacts' folder as a nuget source."
exit 60
fi

echo
echo "** Adding 'Laerdal Nuget Feed' as a Nuget Source:"
# keep this after workload-restoration otherwise we will run into problems note that the 'store-password-in-clear-text'
# is necessary for azure pipelines once we move fully over to github actions we can remove this parameter completely
dotnet nuget add \
source "${NUGET_FEED_URL}" \
--name "LaerdalMedical" \
--username "${NUGET_FEED_USERNAME}" \
--password "${NUGET_FEED_ACCESSTOKEN}" \
--store-password-in-clear-text
declare exitCode=$?
if [ $exitCode != 0 ]; then
echo "##vso[task.logissue type=error]Failed to add 'Laerdal Nuget Feed' as a nuget source."
exit 65
fi

dotnet nuget list source
276 changes: 276 additions & 0 deletions Laerdal.Scripts/Laerdal.Version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
#!/bin/bash

# set -x # for debugging

function usage(){
echo "usage: ./Laerdal.Version.sh [--master-branch master] [--develop-branch develop] [--major 1] [--minor 0] [--patch 0] [--revision 0] [--build-id 0] [--commit HEAD] [--branch branchname] [-o | --output version.txt] [-h | --help]"
echo "parameters:"
echo " --master-branch [branch] Name of the master branch (default is master)"
echo " --develop-branch [branch] Name of the develop branch (default is develop)"
echo " --major [number] Major version override (default is 1)"
echo " --minor [number] Minor version override (default is 0)"
echo " --patch [number] Patch version override (default is 0)"
echo " --revision [number] Revision version override (default is 0)"
echo " --build-id [number] Build id override (default is 0)"
echo " --commit [hash] Commit hash override (default is HEAD)"
echo " -o | --output [filename] Name of the output file"
echo " -h | --help Prints this message"
echo " -v | --verbose Verbose mode"
}

master_branch="master"
develop_branch="develop"
major=1
minor=0
patch=0
revision=0
build_id=0
commit="HEAD"
output="version.txt"
version_core=$major.$minor.$patch
version_extension=
version_full=$version_core$version_extension

while [ "$1" != "" ]; do
case $1 in
--master-branch ) shift
master_branch="$1"
;;
--develop-branch ) shift
develop_branch="$1"
;;
--major ) shift
major="$1"
major_override=true
;;
--minor ) shift
minor="$1"
minor_override=true
;;
--patch ) shift
patch="$1"
patch_override=true
;;
--revision ) shift
revision="$1"
revision_override=true
;;
--build-id ) shift
build_id="$1"
build_id_override=true
;;
--commit ) shift
commit="$1"
commit_override=true
;;
-h | --help ) usage
exit
;;
-v | --verbose ) verbose=1
;;
-o | --output ) shift
output="$1"
;;
* ) echo
echo "### Wrong parameter: $1 ###"
echo
usage
exit 1
esac
shift
done

function log () {
if [[ $verbose -eq 1 ]]; then
echo "$@"
fi
}

function warn () {
if [ "${TF_BUILD:=}" != "" ]; then
echo "##vso[task.logissue type=warning]$*"
else
echo "WARNING : $*"
fi
}

# Azure DevOps build
if [ "${TF_BUILD:=}" != "" ]; then
log "TF_BUILD is set, assuming Azure DevOps build"
azure_dev_ops_build=1
else
log "TF_BUILD is not set, assuming local build"
azure_dev_ops_build=0
fi

# Branch prefix
if [[ $azure_dev_ops_build -eq 1 ]]; then
branch_prefix="origin/"
else
branch_prefix=""
fi

# Build id
if [[ $azure_dev_ops_build -eq 1 ]]; then
build_id=${BUILD_BUILDID}
else
build_id=`git rev-list --count $commit`
fi
log "build_id=$build_id"

# Branch name
if [[ $azure_dev_ops_build -eq 1 ]]; then
if [[ "${BUILD_REASON}" != "PullRequest" ]]; then
branch_name=`echo ${BUILD_SOURCEBRANCH} | sed 's/refs\/heads\///g'`
else
branch_name=`echo ${SYSTEM_PULLREQUEST_SOURCEBRANCH} | sed 's/refs\/heads\///g'`
fi
else
branch_name=`git rev-parse --abbrev-ref $commit | sed 's/refs\/heads\///g'`
fi
log "branch_name=$branch_name"

# First commit
first_commit=`git rev-list --max-parents=0 $commit`
log "first_commit=$first_commit"

# Suffix
suffix=`echo $branch_name | sed 's/\//-/'`
log "suffix=$suffix"

git fetch origin "$master_branch:$master_branch" >/dev/null 2>&1 # its vital to do this silently otherwise the
git fetch origin "$develop_branch:$develop_branch" >/dev/null 2>&1 # output of this entire script will be malformed

if [ "$branch_name" == "$develop_branch" ]; then
develop_master_point=`git rev-list $branch_prefix$master_branch --merges --before=\`git show -s --format=%ct $commit\` --first-parent --max-count=1`
if [ -z $develop_master_point ]; then # has never been merged
develop_master_point=`git merge-base $branch_prefix$master_branch $commit --fork-point`
fi
log "develop_master_point=$develop_master_point"

elif [ "$branch_name" != "$master_branch" ]; then
head_develop_point=`git rev-list $branch_prefix$develop_branch --merges --before=\`git show -s --format=%ct $commit\` --first-parent --max-count=1`
if [ -z $head_develop_point ]; then # has never been merged
head_develop_point=$(git merge-base $branch_prefix$develop_branch $commit --fork-point)
fi

log "head_develop_point=$head_develop_point"
develop_master_point=`git rev-list $branch_prefix$master_branch --merges --before=\`git show -s --format=%ct $head_develop_point\` --first-parent --max-count=1`
if [ -z $develop_master_point ]; then # has never been merged
develop_master_point=`git merge-base $branch_prefix$master_branch $head_develop_point --fork-point`
fi
log "develop_master_point=$develop_master_point"
fi


# Minor
if [ "$minor_override" != "true" ]; then
if [ "$branch_name" == "$master_branch" ]; then
minor=$( git rev-list "$first_commit..$commit" --count --first-parent --ancestry-path )

elif [ "$branch_name" == "$develop_branch" ]; then
minor=$( git rev-list "$first_commit..$develop_master_point" --count --first-parent --ancestry-path )

else
minor=$( git rev-list "$first_commit..$develop_master_point" --count --first-parent --ancestry-path )
fi

else
log "Minor version override: $minor"
fi

# Patch
if [ "$patch_override" != "true" ]; then
if [ "$branch_name" == "$master_branch" ]; then
patch=0

elif [ "$branch_name" == "$develop_branch" ]; then
declare -r before=$( git show -s --format=%ct "$develop_master_point" --first-parent --ancestry-path )
declare -r not=$( git rev-list "$first_commit..$commit" --before=$before | head -n 750 ) # its vital to trim the number of parameters to around 750 otherwise we will get an error below

patch=$( \
git \
rev-list \
"$first_commit..$commit" \
--count \
--first-parent \
--ancestry-path \
--not $not ) # do not doublequote $not as this will break the script

else
declare -r before=$( git show -s --format=%ct "$develop_master_point" --first-parent --ancestry-path )
declare -r not=$( git rev-list "$first_commit..$head_develop_point" --before="$before" | head -n 750 ) # its vital to trim the number of parameters to around 750 otherwise we will get an error below

patch=$( \
git rev-list \
"$first_commit..$head_develop_point" \
--count \
--first-parent \
--ancestry-path \
--not $not ) # do not doublequote $not as this will break the script
fi

else
log "Patch version override: $patch"
fi

# Revision
if [ "$revision_override" != "true" ]; then
if [ "$branch_name" == "$master_branch" ]; then
revision=0
elif [ "$branch_name" == "$develop_branch" ]; then
revision=0
else
revision=`git rev-list $head_develop_point..$commit --count`
fi
else
log "Revision version override: $revision"
fi

# Version extension
if [ "$branch_name" == "" ]; then
version_extension=
elif [ "$branch_name" == "$master_branch" ]; then
version_extension=
elif [ "$branch_name" == "$develop_branch" ]; then
version_extension=
else
version_extension="-$suffix-$revision.$build_id"
fi

version_core=$major.$minor.$patch
version_full=$version_core$version_extension
version_assembly=$version_core.$revision


log "Laerdal_Version_Major:$major"
log "Laerdal_Version_Minor:$minor"
log "Laerdal_Version_Patch:$patch"
log "Laerdal_Version_Suffix:$suffix"
log "Laerdal_Version_Revision:$revision"
log "Laerdal_Version_BuildId:$build_id"
log "Laerdal_Version_Core:$version_core"
log "Laerdal_Version_Extension:$version_extension"
log "Laerdal_Version_Full:$version_full"
log "Laerdal_Version_Assembly:$version_assembly"
log "Laerdal_Version_BranchName:$branch_name"
log "Laerdal_Version_ScriptCalled:true"

if [ "$output" != "" ]; then
mkdir -p "$(dirname "$output")" && touch "$output" ;
echo "Laerdal_Version_Major=$major" > $output
echo "Laerdal_Version_Minor=$minor" >> $output
echo "Laerdal_Version_Patch=$patch" >> $output
echo "Laerdal_Version_Suffix=$suffix" >> $output
echo "Laerdal_Version_Revision=$revision" >> $output
echo "Laerdal_Version_BuildId=$build_id" >> $output
echo "Laerdal_Version_Core=$version_core" >> $output
echo "Laerdal_Version_Extension=$version_extension" >> $output
echo "Laerdal_Version_Full=$version_full" >> $output
echo "Laerdal_Version_Assembly=$version_assembly" >> $output
echo "Laerdal_Version_BranchName=$branch_name" >> $output
fi

echo $version_full

exit 0

0 comments on commit d555b8c

Please sign in to comment.