Skip to content

Commit 5d214e6

Browse files
committed
add test mode
1 parent 9f1bdee commit 5d214e6

File tree

2 files changed

+130
-38
lines changed

2 files changed

+130
-38
lines changed

.github/workflows/publish-create-branch.yaml

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ on:
4242
required: false
4343
type: boolean
4444
default: true
45+
test_mode:
46+
description: 'Enable test mode (creates mock packages instead of real builds)'
47+
required: false
48+
type: boolean
49+
default: false
4550

4651
env:
4752
GO_VERSION: 1.19.10
@@ -144,10 +149,10 @@ jobs:
144149
include:
145150
- arch: amd64
146151
runner: ubuntu-latest
147-
should_build: ${{ github.event.inputs.build_linux_amd64 != 'true' }}
152+
should_build: ${{ github.event.inputs.build_linux_amd64 == 'true' }}
148153
- arch: arm64
149154
runner: ubuntu-24.04-arm
150-
should_build: ${{ github.event.inputs.build_linux_arm64 != 'true' }}
155+
should_build: ${{ github.event.inputs.build_linux_arm64 == 'true' }}
151156
steps:
152157
- name: Check out code
153158
if: matrix.should_build
@@ -175,7 +180,28 @@ jobs:
175180
if: matrix.should_build
176181
run: |
177182
VERSION="${{ github.event.inputs.version }}"
178-
make dist
183+
184+
# 快速测试模式:创建模拟的构建产物
185+
if [[ "${{ github.event.inputs.test_mode }}" == "true" ]]; then
186+
echo "Running in test mode - creating mock packages..."
187+
mkdir -p dist/
188+
189+
# 创建模拟的 loongcollector 目录结构
190+
mkdir -p mock_loongcollector/loongcollector-$VERSION
191+
echo "Mock loongcollector binary for ${{ matrix.arch }}" > mock_loongcollector/loongcollector-$VERSION/loongcollector
192+
echo "Mock config" > mock_loongcollector/loongcollector-$VERSION/ilogtail_config.json
193+
echo "Mock script" > mock_loongcollector/loongcollector-$VERSION/loongcollector_control.sh
194+
chmod +x mock_loongcollector/loongcollector-$VERSION/loongcollector
195+
chmod +x mock_loongcollector/loongcollector-$VERSION/loongcollector_control.sh
196+
197+
# 创建 tar.gz 包
198+
tar -czf dist/loongcollector-$VERSION.linux-${{ matrix.arch }}.tar.gz -C mock_loongcollector loongcollector-$VERSION
199+
echo "Created mock package: dist/loongcollector-$VERSION.linux-${{ matrix.arch }}.tar.gz"
200+
else
201+
# 正常构建模式
202+
make dist
203+
fi
204+
179205
ls -la dist/
180206
181207
- name: Upload Linux ${{ matrix.arch }} artifacts
@@ -203,8 +229,30 @@ jobs:
203229

204230
- name: Build Windows package
205231
run: |
206-
Write-Host "Starting Windows build..."
207-
.\scripts\windows64_build.bat $env:LOONCOLLECTOR_VERSION
232+
$VERSION = "${{ github.event.inputs.version }}"
233+
234+
# 快速测试模式:创建模拟的构建产物
235+
if ("${{ github.event.inputs.test_mode }}" -eq "true") {
236+
Write-Host "Running in test mode - creating mock Windows package..."
237+
238+
# 创建模拟的 output 目录结构
239+
New-Item -ItemType Directory -Path "output" -Force | Out-Null
240+
"Mock loongcollector.exe for Windows" | Out-File -FilePath "output\loongcollector.exe" -Encoding UTF8
241+
"Mock GoPluginAdapter.dll" | Out-File -FilePath "output\GoPluginAdapter.dll" -Encoding UTF8
242+
"Mock GoPluginBase.dll" | Out-File -FilePath "output\GoPluginBase.dll" -Encoding UTF8
243+
"{}" | Out-File -FilePath "output\ilogtail_config.json" -Encoding UTF8
244+
245+
# 创建 dist 目录
246+
New-Item -ItemType Directory -Path "dist" -Force | Out-Null
247+
248+
# 创建 zip 包
249+
Compress-Archive -Path "output\*" -DestinationPath "dist\loongcollector-$VERSION.windows-amd64.zip" -Force
250+
Write-Host "Created mock Windows package: dist\loongcollector-$VERSION.windows-amd64.zip"
251+
} else {
252+
# 正常构建模式
253+
Write-Host "Starting Windows build..."
254+
.\scripts\windows64_build.bat $env:LOONCOLLECTOR_VERSION
255+
}
208256
209257
# 检查构建结果
210258
if (Test-Path "output") {
@@ -303,7 +351,7 @@ jobs:
303351
echo "Generated SHA256 for $file"
304352
fi
305353
done
306-
ls -la dist/
354+
ls -la .
307355
308356
- name: Set up Docker Buildx
309357
uses: docker/setup-buildx-action@v3

.github/workflows/publish-release.yaml

Lines changed: 76 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ This release includes Docker images for multiple architectures:
120120

121121
### GitHub Container Registry (ghcr.io)
122122

123-
\`\`\`bash
123+
\`bash
124124
# Pull the latest version
125125
docker pull ghcr.io/\$REPO_OWNER/loongcollector:latest
126126

@@ -129,18 +129,18 @@ docker pull ghcr.io/\$REPO_OWNER/loongcollector:\$VERSION
129129

130130
# Run the container
131131
docker run -d --name loongcollector ghcr.io/\$REPO_OWNER/loongcollector:\$VERSION
132-
\`\`\`
132+
\`
133133

134134
**Supported architectures:**
135135
- linux/amd64
136136
- linux/arm64
137137

138138
### Alibaba Cloud Container Registry
139139

140-
\`\`\`bash
140+
\`bash
141141
# Pull from Alibaba Cloud Container Registry
142142
docker pull sls-opensource-registry.cn-shanghai.cr.aliyuncs.com/ilogtail/loongcollector:\$VERSION
143-
\`\`\`
143+
\`
144144

145145
**Supported architectures:**
146146
- linux/amd64
@@ -150,37 +150,81 @@ docker pull sls-opensource-registry.cn-shanghai.cr.aliyuncs.com/ilogtail/loongco
150150
echo "$RELEASE_NOTES" > release_notes.md
151151
echo "Release notes generated successfully"
152152

153-
- name: Download build artifacts from create-branch workflow
154-
uses: actions/download-artifact@v4
155-
with:
156-
name: loongcollector-${{ github.event.inputs.version }}.linux-amd64.tar.gz
157-
path: dist/
158-
159-
- name: Download Linux ARM64 artifacts
160-
uses: actions/download-artifact@v4
161-
with:
162-
name: loongcollector-${{ github.event.inputs.version }}.linux-arm64.tar.gz
163-
path: dist/
153+
- name: Download build artifacts from OSS
154+
run: |
155+
VERSION="${{ github.event.inputs.version }}"
156+
mkdir -p dist/
157+
158+
# 尝试从 OSS 下载构建产物
159+
echo "Downloading build artifacts from OSS..."
160+
161+
# 下载 Linux AMD64
162+
LINUX_AMD64_URL="https://loongcollector-community-edition.oss-cn-shanghai.aliyuncs.com/${VERSION}/loongcollector-${VERSION}.linux-amd64.tar.gz"
163+
if curl -f -s -o "dist/loongcollector-${VERSION}.linux-amd64.tar.gz" "$LINUX_AMD64_URL"; then
164+
echo "✓ Downloaded Linux AMD64 package"
165+
# 下载对应的 SHA256 文件
166+
curl -f -s -o "dist/loongcollector-${VERSION}.linux-amd64.tar.gz.sha256" "${LINUX_AMD64_URL}.sha256" || echo "SHA256 file not found"
167+
else
168+
echo "✗ Failed to download Linux AMD64 package"
169+
fi
170+
171+
# 下载 Linux ARM64
172+
LINUX_ARM64_URL="https://loongcollector-community-edition.oss-cn-shanghai.aliyuncs.com/${VERSION}/loongcollector-${VERSION}.linux-arm64.tar.gz"
173+
if curl -f -s -o "dist/loongcollector-${VERSION}.linux-arm64.tar.gz" "$LINUX_ARM64_URL"; then
174+
echo "✓ Downloaded Linux ARM64 package"
175+
# 下载对应的 SHA256 文件
176+
curl -f -s -o "dist/loongcollector-${VERSION}.linux-arm64.tar.gz.sha256" "${LINUX_ARM64_URL}.sha256" || echo "SHA256 file not found"
177+
else
178+
echo "✗ Failed to download Linux ARM64 package"
179+
fi
180+
181+
# 下载 Windows
182+
WINDOWS_URL="https://loongcollector-community-edition.oss-cn-shanghai.aliyuncs.com/${VERSION}/loongcollector-${VERSION}.windows-amd64.zip"
183+
if curl -f -s -o "dist/loongcollector-${VERSION}.windows-amd64.zip" "$WINDOWS_URL"; then
184+
echo "✓ Downloaded Windows package"
185+
# 下载对应的 SHA256 文件
186+
curl -f -s -o "dist/loongcollector-${VERSION}.windows-amd64.zip.sha256" "${WINDOWS_URL}.sha256" || echo "SHA256 file not found"
187+
else
188+
echo "✗ Failed to download Windows package"
189+
fi
190+
191+
echo "Downloaded artifacts:"
192+
ls -la dist/ || echo "No artifacts downloaded"
164193
165-
- name: Download Windows artifacts
166-
uses: actions/download-artifact@v4
167-
with:
168-
name: loongcollector-${{ github.event.inputs.version }}.windows-amd64.zip
169-
path: dist/
194+
- name: Check available artifacts
195+
run: |
196+
echo "Checking available artifacts in dist/ directory:"
197+
ls -la dist/ || echo "No artifacts found in dist/ directory"
198+
199+
if [ ! "$(ls -A dist/ 2>/dev/null)" ]; then
200+
echo "No artifacts found. The release will be created without files."
201+
echo "Make sure the build artifacts have been uploaded to OSS by running publish-create-branch.yaml first."
202+
else
203+
echo "Found artifacts:"
204+
ls -la dist/
205+
fi
170206
171207
- name: Create GitHub Release
172-
uses: softprops/action-gh-release@v1
173-
with:
174-
tag_name: v${{ env.VERSION }}
175-
name: Release v${{ env.VERSION }}
176-
body_path: release_notes.md
177-
draft: false
178-
prerelease: false
179-
files: |
180-
dist/loongcollector-${{ env.VERSION }}.linux-amd64.tar.gz
181-
dist/loongcollector-${{ env.VERSION }}.linux-arm64.tar.gz
182-
dist/loongcollector-${{ env.VERSION }}.windows-amd64.zip
183-
token: ${{ secrets.GITHUB_TOKEN }}
208+
run: |
209+
VERSION="${{ env.VERSION }}"
210+
211+
# 检查是否有可用的 artifacts
212+
if [ "$(ls -A dist/ 2>/dev/null)" ]; then
213+
echo "Found artifacts, creating release with files..."
214+
gh release create "v$VERSION" \
215+
--title "Release v$VERSION" \
216+
--notes-file release_notes.md \
217+
--draft false \
218+
--prerelease false \
219+
dist/*.tar.gz dist/*.zip dist/*.sha256 2>/dev/null || true
220+
else
221+
echo "No artifacts found, creating release without files..."
222+
gh release create "v$VERSION" \
223+
--title "Release v$VERSION" \
224+
--notes-file release_notes.md \
225+
--draft false \
226+
--prerelease false
227+
fi
184228
185229
- name: Output release info
186230
run: |

0 commit comments

Comments
 (0)