Skip to content

Commit 0328af1

Browse files
authored
update v1.0.0-beta.1 (#1)
* work save. * update.
1 parent 54f2b54 commit 0328af1

42 files changed

Lines changed: 2489 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/docker-build.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Docker JobAgent
2+
3+
on:
4+
push:
5+
# branches:
6+
# - "**"
7+
tags:
8+
- "v*"
9+
workflow_dispatch:
10+
11+
env:
12+
# 两个镜像前缀
13+
DOCKERHUB_REPO: aicrosoft/jobagent
14+
GHCR_REPO: ghcr.io/${{ github.repository_owner }}/jobagent
15+
16+
jobs:
17+
build-and-push:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
packages: write # ③ 允许写包
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v3
26+
27+
- name: Set Version
28+
id: set_version
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
run: |
32+
BASE_VERSION="0.0.1" # default version, can be modified as needed
33+
REF="${GITHUB_REF}"
34+
35+
# Use tag version
36+
if [[ "$REF" == refs/tags/* ]]; then
37+
TAG_NAME="${REF#refs/tags/}"
38+
TAG_VERSION="${TAG_NAME#[vV]}" # 去掉 v/V 前缀
39+
VERSION="$TAG_VERSION"
40+
echo "Detected tag: $TAG_NAME -> VERSION=$VERSION"
41+
fi
42+
43+
# set outputs for version
44+
echo "version=$VERSION" >> $GITHUB_OUTPUT
45+
46+
- name: Docker Tag Version
47+
run: |
48+
echo "Docker Tag: ${{ steps.set_version.outputs.version }} "
49+
50+
- name: set lowercase image name
51+
run: |
52+
echo "GHCR_REPO_LC=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/jobagent" >> $GITHUB_ENV
53+
54+
# 1. 登录 DockerHub
55+
- name: Log in to Docker Hub
56+
uses: docker/login-action@v2
57+
with:
58+
username: ${{ secrets.DOCKERHUB_USERNAME }}
59+
password: ${{ secrets.DOCKERHUB_TOKEN }}
60+
61+
# 2. 登录 GitHub Packages
62+
- name: Log in to GHCR
63+
uses: docker/login-action@v2
64+
with:
65+
registry: ghcr.io
66+
username: ${{ github.actor }}
67+
password: ${{ secrets.GITHUB_TOKEN }}
68+
69+
# 3. 一次构建 + 同时推两个库
70+
- name: Build and push (multi-registry)
71+
uses: docker/build-push-action@v4
72+
with:
73+
context: .
74+
file: build/dockerfiles/Dockerfile.jobagent
75+
push: true
76+
# 同一份镜像层,两个仓库、两个 tag
77+
tags: |
78+
${{ env.DOCKERHUB_REPO }}:latest
79+
${{ env.DOCKERHUB_REPO }}:${{ steps.set_version.outputs.version }}
80+
${{ env.GHCR_REPO_LC }}:latest
81+
${{ env.GHCR_REPO_LC }}:${{ steps.set_version.outputs.version }}
82+
83+

.github/workflows/dotnet-build.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Build JobAgent
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
#- "**"
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
name: Build ${{ matrix.os }} / ${{ matrix.runtime }}
13+
runs-on: ${{ matrix.os }}
14+
outputs:
15+
version: ${{ steps.set_version.outputs.version }} # 🚀 expouse version
16+
phase: ${{steps.set_version.outputs.phase }} # 🚀 expouse phase
17+
strategy:
18+
matrix:
19+
include:
20+
- os: ubuntu-latest
21+
runtime: linux-x64
22+
- os: ubuntu-latest
23+
runtime: linux-arm64
24+
- os: windows-latest
25+
runtime: win-x64
26+
- os: macos-latest
27+
runtime: osx-x64
28+
steps:
29+
- name: Set Version
30+
id: set_version
31+
shell: bash
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
run: |
35+
BASE_VERSION="0.0.1" # 默认基础版本,可以根据需要修改
36+
REF="${GITHUB_REF}"
37+
BRANCH_NAME="${GITHUB_REF##*/}"
38+
DATE_SUFFIX=$(date +'%y%m%d%H') # 取得时间版本25110315
39+
COUNTER=$(date +'%H%M')
40+
41+
# Tag版本 替代 BASE_VERSION
42+
if [[ "$REF" == refs/tags/* ]]; then
43+
TAG_NAME="${REF#refs/tags/}"
44+
TAG_VERSION="${TAG_NAME#[vV]}" # 去掉 v/V 前缀
45+
BASE_VERSION="$TAG_VERSION"
46+
echo "Detected tag: $TAG_NAME -> BASE_VERSION=$BASE_VERSION"
47+
fi
48+
49+
# 根据分支生成版本号
50+
case "$BRANCH_NAME" in
51+
main)
52+
VERSION="${BASE_VERSION}"
53+
PHASE="Release"
54+
;;
55+
rc/*)
56+
VERSION="${BASE_VERSION}-rc${DATE_SUFFIX}"
57+
PHASE="RC"
58+
;;
59+
beta/*)
60+
VERSION="${BASE_VERSION}-beta${DATE_SUFFIX}"
61+
PHASE="Beta"
62+
;;
63+
dev/*|*)
64+
VERSION="${BASE_VERSION}-dev${DATE_SUFFIX}"
65+
PHASE="Alpha"
66+
;;
67+
esac
68+
69+
# 输出到 workflow 输出变量
70+
echo "version=$VERSION" >> $GITHUB_OUTPUT
71+
echo "phase=$PHASE" >> $GITHUB_OUTPUT
72+
73+
- name: Log Version
74+
run: |
75+
echo "Current Version: ${{ steps.set_version.outputs.version }} "
76+
77+
- uses: actions/checkout@v3
78+
- uses: actions/setup-dotnet@v4
79+
with:
80+
dotnet-version: "8.0.x"
81+
- run: dotnet restore JobAgent.sln
82+
- run: dotnet build JobSamples/JobSamples.csproj -c Release -r ${{ matrix.runtime }} --self-contained false -o ./publish/JobSamples
83+
- run: dotnet publish JobAgent.Console/JobAgent.Console.csproj -c Release -r ${{ matrix.runtime }} --self-contained true -p:PublishSingleFile=true -o ./publish/JobAgent
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Release JobAgent
2+
3+
on:
4+
push:
5+
# branches:
6+
# - "**"
7+
tags:
8+
- "v*"
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
build:
17+
name: Build ${{ matrix.os }} / ${{ matrix.runtime }}
18+
runs-on: ${{ matrix.os }}
19+
outputs:
20+
version: ${{ steps.set_version.outputs.version }} # 🚀 expouse version
21+
strategy:
22+
matrix:
23+
include:
24+
- os: ubuntu-latest
25+
runtime: linux-x64
26+
- os: ubuntu-latest
27+
runtime: linux-arm64
28+
- os: windows-latest
29+
runtime: win-x64
30+
- os: macos-latest
31+
runtime: osx-x64
32+
steps:
33+
- name: Set Version
34+
id: set_version
35+
shell: bash
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
run: |
39+
BASE_VERSION="0.0.1" # default version, can be modified as needed
40+
REF="${GITHUB_REF}"
41+
42+
# Use tag version
43+
if [[ "$REF" == refs/tags/* ]]; then
44+
TAG_NAME="${REF#refs/tags/}"
45+
TAG_VERSION="${TAG_NAME#[vV]}" # 去掉 v/V 前缀
46+
VERSION="$TAG_VERSION"
47+
echo "Detected tag: $TAG_NAME -> VERSION=$VERSION"
48+
fi
49+
50+
# set outputs for version
51+
echo "version=$VERSION" >> $GITHUB_OUTPUT
52+
53+
- name: Log Version
54+
run: |
55+
echo "Current Version: ${{ steps.set_version.outputs.version }} "
56+
57+
- uses: actions/checkout@v3
58+
- uses: actions/setup-dotnet@v4
59+
with:
60+
dotnet-version: "8.0.x"
61+
- run: dotnet restore JobAgent.sln
62+
- run: dotnet build JobSamples/JobSamples.csproj -c Release -r ${{ matrix.runtime }} --self-contained false -o ./publish/JobSamples
63+
- run: dotnet publish JobAgent.Console/JobAgent.Console.csproj -c Release -r ${{ matrix.runtime }} --self-contained true -p:PublishSingleFile=true -o ./publish/JobAgent
64+
- name: Copy plugin to Console
65+
shell: bash
66+
run: |
67+
mkdir -p ./publish/JobAgent/Plugins/JobSamples
68+
cp -r ./publish/JobSamples/* ./publish/JobAgent/Plugins/JobSamples/
69+
rm -rf ./publish/JobSamples
70+
#- run: zip -r ./publish/JobAgent-${{ matrix.runtime }}.zip ./publish/JobAgent
71+
# note: Use PowerShell to create zip for better cross-platform support
72+
- name: Zip release
73+
shell: pwsh
74+
run: |
75+
if ($env:RUNNER_OS -eq "Windows") {
76+
$source = Resolve-Path ./publish/JobAgent
77+
$zip = "./publish/JobAgent_${{ steps.set_version.outputs.version }}_${{ matrix.runtime }}.zip"
78+
Copy-Item -Path ./build/scripts/install.bat -Destination $source -Force
79+
Compress-Archive -Path "$source\*" -DestinationPath $zip -Force
80+
} else {
81+
& zip -r ./publish/JobAgent_${{ steps.set_version.outputs.version }}_${{ matrix.runtime }}.zip ./publish/JobAgent
82+
}
83+
84+
- uses: actions/upload-artifact@v4
85+
with:
86+
name: JobAgent_${{ steps.set_version.outputs.version }}_${{ matrix.runtime }}
87+
path: ./publish/JobAgent_${{ steps.set_version.outputs.version }}_${{ matrix.runtime }}.zip
88+
89+
release:
90+
name: Create Release
91+
needs: build
92+
runs-on: ubuntu-latest
93+
# 👇 only has a tag then run.
94+
if: startsWith(github.ref, 'refs/tags/')
95+
steps:
96+
- name: Log version
97+
shell: bash
98+
run: |
99+
echo "Version from build: ${{ needs.build.outputs.version }}"
100+
- uses: actions/checkout@v3
101+
- name: Download artifacts
102+
uses: actions/download-artifact@v4
103+
with:
104+
path: ./publish
105+
106+
- name: Create Release & Upload assets
107+
id: create_release
108+
uses: softprops/action-gh-release@v2
109+
env:
110+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111+
with:
112+
name: v${{ needs.build.outputs.version }}
113+
#tag_name: v${{ needs.build.outputs.version }} # It is necessary to have a TAG. When OrTag is triggered, this is not used, otherwise it will modify the original TAG.
114+
files: ./publish/**/*.zip
115+
draft: false
116+
#prerelease: ${{ needs.build.outputs.phase != 'Release' }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
##
44
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
55

6+
[Bb]ackup/
7+
[Pp]ublish/
8+
9+
610
# User-specific files
711
*.rsuser
812
*.suo
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Microsoft.Extensions.Hosting;
3+
4+
namespace Aicrosoft.Extensions;
5+
6+
public static class ConfigureExtensions
7+
{
8+
9+
10+
public static IHostBuilder AddCurrentAssemblyService(this IHostBuilder hostBuilder)
11+
{
12+
hostBuilder.ConfigureServices((hostContext, services) =>
13+
{
14+
services.AddService(typeof(ConfigureExtensions).Assembly);
15+
});
16+
return hostBuilder;
17+
}
18+
19+
20+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<AssemblyName>JobAgent</AssemblyName>
9+
<RootNamespace />
10+
<ApplicationIcon>logo.ico</ApplicationIcon>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<Content Include="logo.ico" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Aicrosoft.Extensions.Hosting" Version="8.0.0-beta.251110.1" />
19+
<PackageReference Include="Aicrosoft.Extensions.NLog" Version="8.0.0-beta.251110.1" />
20+
<PackageReference Include="Aicrosoft.Scheduling" Version="8.0.0-beta.251110.1" />
21+
<PackageReference Include="NLog.MailKit" Version="6.0.3" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<None Update="appsettings.Development.json">
26+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
27+
</None>
28+
<None Update="appsettings.json">
29+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
30+
</None>
31+
<None Update="appsettings.Production.json">
32+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
33+
</None>
34+
<None Update="nlog.config">
35+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
36+
</None>
37+
</ItemGroup>
38+
39+
</Project>

JobAgent.Console/Program.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Aicrosoft.Logging.NLog;
2+
using Aicrosoft.Services;
3+
using Microsoft.Extensions.Hosting;
4+
using Microsoft.Extensions.Logging;
5+
6+
var start = Environment.TickCount64;
7+
var logger = NLogHelper.GetLogger();
8+
logger.DelegateDiag();
9+
logger.CaptureGlobalException();
10+
logger.LogTrace($"Loggger was created TimeElapsed:{Environment.TickCount64 - start} ms");
11+
try
12+
{
13+
NLogHelper.SetConfigurationVariableWhenRelease("logLevel", "Info");
14+
start = Environment.TickCount64;
15+
logger.LogTrace($"Begin Build Host Envirment ...");
16+
//normal flow.
17+
using IHost host = Host.CreateDefaultBuilder(args)
18+
.AddServices() //add entry assembly to DI
19+
.AddJobsFactory() //use jobsfactory component.
20+
.AddPluginsService() //enable plugins support.
21+
.AddAsWindowsService("JobAgent")
22+
.AddNLog()
23+
//.UseAop()
24+
.AddServiceDIDebug() //show DI table.
25+
.Build()
26+
;
27+
ServiceLocator.ServiceProvider = host.Services; //DI Service hook.
28+
logger.LogTrace($"End Build. TimeElapsed:{Environment.TickCount64 - start} ms");
29+
await host.RunAsync();
30+
return 0;
31+
}
32+
catch (Exception ex)
33+
{
34+
logger.LogError(ex, "Build and run IHost has a exception");
35+
return -9;
36+
}
37+
finally
38+
{
39+
NLogHelper.Shutdown();
40+
}

0 commit comments

Comments
 (0)