Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: 2
updates:
- package-ecosystem: nuget
directories:
- /DiscoveryMessageTests
- /LegoInfrared
- /LegoTrain
- /SignalSwitch
- /TrainDetect
schedule:
interval: weekly
labels:
- dependency update
groups:
nuget-dependencies:
patterns:
- "*"
Comment thread
Ellerbach marked this conversation as resolved.

- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
labels:
- dependency update
groups:
github-actions:
patterns:
- "*"

- package-ecosystem: docker
directory: /LegoTrain
schedule:
interval: weekly
labels:
- dependency update
groups:
docker-images:
patterns:
- "*"
74 changes: 74 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI

on:
push:
branches:
- main
pull_request:

permissions:
contents: read

jobs:
dotnet:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
10.0.x
- name: Test discovery messages
run: dotnet test DiscoveryMessageTests/DiscoveryMessageTests.csproj --configuration Release
- name: Build LegoTrain
run: dotnet build LegoTrain/LegoTrain.csproj --configuration Release

firmware:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: NuGet/setup-nuget@v2
- uses: nanoframework/nanobuild@v1
with:
gitHubAuth: ${{ github.token }}
- name: Restore nanoFramework packages
run: nuget restore LegoTrain.sln -NonInteractive
- name: Build nanoFramework projects
shell: pwsh
run: |
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$msbuild = & $vswhere -latest -requires Microsoft.Component.MSBuild -find 'MSBuild\**\Bin\MSBuild.exe' | Select-Object -First 1
if (-not $msbuild) { throw 'MSBuild was not found.' }
$projects = 'LegoInfrared', 'SignalSwitch', 'TrainDetect'
foreach ($project in $projects) {
& $msbuild "$project/$project.nfproj" /t:Rebuild /p:Configuration=Release /p:Platform=AnyCPU /m
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}

docker:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- architecture: amd64
platform: linux/amd64
dockerfile: LegoTrain/Dockerfile
- architecture: arm32
platform: linux/arm/v7
dockerfile: LegoTrain/Dockerfile.arm32
- architecture: arm64
platform: linux/arm64
dockerfile: LegoTrain/Dockerfile.arm64
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Build ${{ matrix.architecture }} Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.dockerfile }}
platforms: ${{ matrix.platform }}
push: false
82 changes: 82 additions & 0 deletions .github/workflows/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Labels

on:
push:
branches:
- main
pull_request_target:
types:
- opened
- reopened
- synchronize
workflow_dispatch:

permissions:
contents: read
issues: write
pull-requests: read

jobs:
labels:
runs-on: ubuntu-latest
steps:
- name: Create labels and label pull request
uses: actions/github-script@v7
with:
script: |
const definitions = {
LegoTrain: ['LegoTrain/', 'nanoDiscovery/', 'LegoDiscoveryCommon/'],
LegoInfrared: ['LegoInfrared/', 'SharedServices/', 'nanoDiscovery/', 'LegoDiscoveryCommon/'],
SignalSwitch: ['SignalSwitch/', 'SharedServices/', 'nanoDiscovery/', 'LegoDiscoveryCommon/'],
TrainDetect: ['TrainDetect/', 'SharedServices/', 'nanoDiscovery/', 'LegoDiscoveryCommon/'],
DiscoveryMessageTests: ['DiscoveryMessageTests/', 'nanoDiscovery/'],
documentation: ['README.md', 'Lego_api_doc.md', 'LICENSE'],
cicd: ['.github/', 'build-docker.ps1', 'build-docker.sh'],
};
const colors = {
LegoTrain: '1f6feb',
LegoInfrared: 'd73a4a',
SignalSwitch: 'fbca04',
TrainDetect: '0e8a16',
DiscoveryMessageTests: '5319e7',
documentation: '0075ca',
cicd: '6f42c1',
'dependency update': '0366d6',
};

for (const [name, color] of Object.entries(colors)) {
try {
await github.rest.issues.getLabel({ ...context.repo, name });
} catch (error) {
if (error.status !== 404) throw error;
await github.rest.issues.createLabel({ ...context.repo, name, color });
}
}

if (!context.payload.pull_request) return;

const files = await github.paginate(github.rest.pulls.listFiles, {
...context.repo,
pull_number: context.issue.number,
per_page: 100,
});
const paths = files.map(file => file.filename);
const labels = Object.entries(definitions)
.filter(([, prefixes]) => prefixes.some(prefix =>
paths.some(path => prefix.endsWith('/') ? path.startsWith(prefix) : path === prefix)))
.map(([name]) => name);

const dependencyFiles = paths.some(path =>
/(^|\/)(packages\.config|dependabot\.yml)$/.test(path) ||
/\.(csproj|nfproj)$/.test(path));
if (context.payload.pull_request.user.login === 'dependabot[bot]' || dependencyFiles) {
labels.push('dependency update');
}

if (labels.length > 0) {
await github.rest.issues.addLabels({
...context.repo,
issue_number: context.issue.number,
labels,
});
}
126 changes: 126 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Release

on:
push:
tags:
- publish
- publish-*
release:
types:
- published

permissions: {}

jobs:
firmware:
runs-on: windows-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: NuGet/setup-nuget@v2
- uses: nanoframework/nanobuild@v1
with:
gitHubAuth: ${{ github.token }}
- name: Restore nanoFramework packages
run: nuget restore LegoTrain.sln -NonInteractive
- name: Build firmware
shell: pwsh
run: |
New-Item -ItemType Directory -Path firmware
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$msbuild = & $vswhere -latest -requires Microsoft.Component.MSBuild -find 'MSBuild\**\Bin\MSBuild.exe' | Select-Object -First 1
if (-not $msbuild) { throw 'MSBuild was not found.' }
$projects = 'LegoInfrared', 'SignalSwitch', 'TrainDetect'
foreach ($project in $projects) {
& $msbuild "$project/$project.nfproj" /t:Rebuild /p:Configuration=Release /p:Platform=AnyCPU /m
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Copy-Item "$project/bin/Release/$project.bin" "firmware/$project.bin"
}
- uses: actions/upload-artifact@v4
with:
name: firmware
path: firmware/*.bin
if-no-files-found: error

docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- architecture: amd64
platform: linux/amd64
dockerfile: LegoTrain/Dockerfile
- architecture: arm32
platform: linux/arm/v7
dockerfile: LegoTrain/Dockerfile.arm32
- architecture: arm64
platform: linux/arm64
dockerfile: LegoTrain/Dockerfile.arm64
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Resolve image metadata
id: metadata
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
if [[ "$EVENT_NAME" == "release" ]]; then
version="$RELEASE_TAG"
else
version="${GITHUB_REF_NAME}"
fi
echo "image=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Build and push ${{ matrix.architecture }} image
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.dockerfile }}
platforms: ${{ matrix.platform }}
push: true
tags: ${{ steps.metadata.outputs.image }}:${{ matrix.architecture }}-${{ steps.metadata.outputs.version }}

github-release:
needs:
- firmware
- docker
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
name: firmware
path: firmware
- name: Resolve release tag
id: release
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
if [[ "$EVENT_NAME" == "release" ]]; then
echo "tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
else
echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
fi
- name: Create or update GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release.outputs.tag }}
generate_release_notes: true
files: firmware/*.bin
2 changes: 1 addition & 1 deletion LegoTrain/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ EXPOSE 80
EXPOSE 443
EXPOSE 2024/udp

FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY ["LegoTrain/LegoTrain.csproj", "LegoTrain/"]
RUN dotnet restore "LegoTrain/LegoTrain.csproj"
Expand Down
2 changes: 1 addition & 1 deletion LegoTrain/Dockerfile.arm32
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ EXPOSE 443
EXPOSE 2024/udp


FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY ["LegoTrain/LegoTrain.csproj", "LegoTrain/"]
RUN dotnet restore "LegoTrain/LegoTrain.csproj"
Expand Down
2 changes: 1 addition & 1 deletion LegoTrain/Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ EXPOSE 80
EXPOSE 443
EXPOSE 2024/udp

FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY ["LegoTrain/LegoTrain.csproj", "LegoTrain/"]
RUN dotnet restore "LegoTrain/LegoTrain.csproj"
Expand Down
Loading
Loading