Skip to content

Commit

Permalink
ci: add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Dissectum committed Sep 14, 2023
1 parent cbb8cb0 commit e64c8ac
Show file tree
Hide file tree
Showing 13 changed files with 461 additions and 16 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: ci

on:
workflow_dispatch:
push:
branches:
- "**"
paths:
- ".github/workflows/ci.yml"
- "src/**"
- "*.sln"
- "*.props"
tags:
- "v*"

pull_request:
branches:
- "**"
paths:
- ".github/workflows/ci.yml"
- "src/**"
- "*.sln"
- "*.props"

jobs:
meta:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- id: meta
run: |
is_release=${{ startsWith(github.ref, 'refs/tags/v') }}
tag=$(git describe --tags --match "v*" ${{ github.ref }} || true)
if [[ $tag != v* ]]; then
tag=$(date "+v0.0.0-%y%m%d-$(git rev-parse --short HEAD)")
fi
if ! $($is_release) ; then
prefix=${tag%-*-*}
suffix=${tag#$prefix-}
next=${prefix##*.}
((++next))
prefix=${prefix%.*}
tag="$prefix.$next-Preview.$suffix"
fi
echo tag=$tag | tee -a $GITHUB_OUTPUT
echo version=${tag#v} | tee -a $GITHUB_OUTPUT
echo is_release=$is_release | tee -a $GITHUB_OUTPUT
outputs:
tag: ${{ steps.meta.outputs.tag }}
version: ${{ steps.meta.outputs.version }}
is_release: ${{ steps.meta.outputs.is_release }}

publish:
needs: [meta]
strategy:
matrix:
project: [MBA.Cli]
os: [win, linux, osx]
arch: [x64, arm64]
suffix: [-single-cut]
dotnet: [ '7.0' ]
fail-fast: false
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
PUBLISH_NAME: ${{ matrix.project }}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.suffix }}-${{ needs.meta.outputs.tag }}
PUBLISH_PATH: ./Publish #./Publish/${{ matrix.project }}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.suffix }}/
CSPROJ_PATH: ./src/${{ matrix.project }}/${{ matrix.project }}.csproj
PUBXML_PATH: ./src/${{ matrix.project }}/Properties/PublishProfiles/${{ matrix.os }}-${{ matrix.arch }}${{ matrix.suffix }}.pubxml

runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet }}
cache: true
cache-dependency-path: '**/packages.lock.json'
- run: dotnet restore --locked-mode

- run: dotnet publish ${{ env.CSPROJ_PATH }} --no-restore -p:Version=${{ needs.meta.outputs.version }} -p:PublishProfile=${{ env.PUBXML_PATH }}

- uses: actions/upload-artifact@v3
if: always()
with:
name: ${{ env.PUBLISH_NAME }}
path: ${{ env.PUBLISH_PATH }}

- name: Pack
if: ${{ needs.meta.outputs.is_release == 'true' }}
working-directory: ${{ env.PUBLISH_PATH }}
run: 7z a -r ../${{ env.PUBLISH_NAME }}.zip ./*

- uses: softprops/action-gh-release@v1
if: ${{ needs.meta.outputs.is_release == 'true' }}
with:
body_path: CHANGELOG.md
prerelease: true
files: ${{ env.PUBLISH_NAME }}.zip
tag_name: ${{ needs.meta.outputs.tag }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ publish/
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
# *.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
Expand Down
18 changes: 18 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<Project>
<!-- General Properties -->
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<RuntimeIdentifiers>linux-arm64;linux-x64;osx-arm64;osx-x64;win-arm64;win-x64</RuntimeIdentifiers>
<DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -11,4 +15,18 @@
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="Serilog.Sinks.File" />
</ItemGroup>

<!-- Metadata Variable -->
<PropertyGroup>
<CurrentYear>$([System.DateTime]::Now.Year)</CurrentYear>
</PropertyGroup>

<!-- Assembly Metadata-->
<PropertyGroup>
<Version Condition="'$(Version)' == ''">1.0.0-dev</Version>
<Authors>MAA Team</Authors>
<Owners>MAA Team</Owners>
<Company>MAA Assistant Arknights</Company>
<Copyright>Copyright © 2021-$(CurrentYear) MAA Team and Contributers. All rights reserved.</Copyright>
</PropertyGroup>
</Project>
27 changes: 14 additions & 13 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Maa.AgentBinary" Version="1.0.0" />
<PackageVersion Include="Maa.Framework.Runtimes" Version="0.3.7" />
<PackageVersion Include="Maa.ToolKit.Extensions" Version="0.6.0-beta.1.1" />
<PackageVersion Include="Serilog" Version="3.0.1" />
<PackageVersion Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
</Project>
<PropertyGroup>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Maa.AgentBinary" Version="1.0.0" />
<PackageVersion Include="Maa.Framework.Runtimes" Version="0.3.7" />
<PackageVersion Include="Maa.ToolKit.Extensions" Version="0.3.7.2" />
<PackageVersion Include="Serilog" Version="3.0.1" />
<PackageVersion Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
</Project>
2 changes: 0 additions & 2 deletions src/MBA.Cli/MBA.Cli.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<ApplicationIcon>..\..\assets\logo.ico</ApplicationIcon>
Expand All @@ -8,5 +7,4 @@
<ItemGroup>
<ProjectReference Include="..\MBA.Core\MBA.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Platform>ARM64</Platform>
<RuntimeIdentifier>linux-arm64</RuntimeIdentifier>
<PublishDir>..\..\Publish\MBA.Cli-linux-arm64-single-cut\</PublishDir>

<Configuration>Release</Configuration>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions src/MBA.Cli/Properties/PublishProfiles/linux-x64-single-cut.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Platform>x64</Platform>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<PublishDir>..\..\Publish\MBA.Cli-linux-x64-single-cut\</PublishDir>

<Configuration>Release</Configuration>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions src/MBA.Cli/Properties/PublishProfiles/osx-arm64-single-cut.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Platform>ARM64</Platform>
<RuntimeIdentifier>osx-arm64</RuntimeIdentifier>
<PublishDir>..\..\Publish\MBA.Cli-osx-arm64-single-cut\</PublishDir>

<Configuration>Release</Configuration>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions src/MBA.Cli/Properties/PublishProfiles/osx-x64-single-cut.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Platform>x64</Platform>
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
<PublishDir>..\..\Publish\MBA.Cli-osx-x64-single-cut\</PublishDir>

<Configuration>Release</Configuration>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions src/MBA.Cli/Properties/PublishProfiles/win-arm64-single-cut.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Platform>ARM64</Platform>
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
<PublishDir>..\..\Publish\MBA.Cli-win-arm64-single-cut\</PublishDir>

<Configuration>Release</Configuration>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions src/MBA.Cli/Properties/PublishProfiles/win-x64-single-cut.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Platform>x64</Platform>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishDir>..\..\Publish\MBA.Cli-win-x64-single-cut\</PublishDir>

<Configuration>Release</Configuration>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
</Project>
Loading

0 comments on commit e64c8ac

Please sign in to comment.