test workflow_dispatch

This commit is contained in:
A13501350
2025-09-19 04:01:10 +08:00
parent 84425206e8
commit 0e2b4b9254

View File

@@ -1,62 +1,68 @@
name: CI/CD for IIS Module name: File Generation and Reading Test
on: on:
push: workflow_dispatch: # 允许手动触发
branches:
- v2/test-ci-windows
pull_request:
branches:
- v2/test-ci-windows
jobs: jobs:
build: file-test:
runs-on: windows-latest runs-on: windows-latest # 使用 Windows 运行器
steps:
- name: Create test files (MSYS2)
uses: msys2/setup-msys2@v2
shell: msys2 {0}
run: |
# 创建测试目录和文件
mkdir -p test-files
echo "This is a test file" > test-files/test.txt
echo "fuzzy definition file" > test-files/fuzzy.def
# 复制到工作区目录
mkdir -p ${{ github.workspace }}/artifacts
cp -r test-files/* ${{ github.workspace }}/artifacts/
# 验证文件已复制
echo "Files in artifacts directory:"
ls -la ${{ github.workspace }}/artifacts/
- name: Verify file transfer (PowerShell) steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate test files (Step 1)
shell: powershell shell: powershell
run: | run: |
Write-Host "Checking transferred files in PowerShell:" # 创建工作目录
Get-ChildItem -Path "${{ github.workspace }}\artifacts" -Recurse $testDir = "${{ github.workspace }}\test-files"
New-Item -ItemType Directory -Path $testDir -Force
# 验证文件内容 # 创建几个测试文件
Write-Host "Content of test.txt:" "This is a test content for file1.txt" | Out-File -FilePath "$testDir\file1.txt"
Get-Content "${{ github.workspace }}\artifacts\test.txt" "fuzzy.def test content" | Out-File -FilePath "$testDir\fuzzy.def"
Write-Host "Content of fuzzy.def:" # 创建一个包含文件列表的 JSON 文件
Get-Content "${{ github.workspace }}\artifacts\fuzzy.def" $files = Get-ChildItem -Path $testDir
$fileInfo = @()
foreach ($file in $files) {
$fileInfo += @{
Name = $file.Name
Path = $file.FullName
Size = $file.Length
LastWriteTime = $file.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
}
}
$fileInfo | ConvertTo-Json | Out-File -FilePath "$testDir\files.json"
# 检查文件是否存在 # 输出生成的文件信息
$testFile = "${{ github.workspace }}\artifacts\test.txt" Write-Host "Generated files:"
$fuzzyFile = "${{ github.workspace }}\artifacts\fuzzy.def" Get-ChildItem -Path $testDir | Format-Table Name, Length
if (Test-Path $testFile -PathType Leaf) { - name: Read test files (Step 2)
Write-Host "✓ test.txt successfully transferred" shell: powershell
} else { run: |
Write-Host "✗ test.txt not found" $testDir = "${{ github.workspace }}\test-files"
# 检查目录是否存在
if (-not (Test-Path -Path $testDir)) {
Write-Error "Test directory does not exist!"
exit 1 exit 1
} }
if (Test-Path $fuzzyFile -PathType Leaf) { # 读取文件列表
Write-Host "✓ fuzzy.def successfully transferred" $filesJson = Get-Content -Path "$testDir\files.json" -Raw | ConvertFrom-Json
Write-Host "Files found:"
$filesJson | Format-Table Name, Size
# 读取特定文件内容
Write-Host "Content of fuzzy.def:"
Get-Content -Path "$testDir\fuzzy.def"
# 验证文件存在
if (Test-Path -Path "$testDir\fuzzy.def") {
Write-Host "SUCCESS: fuzzy.def file exists and is accessible!"
} else { } else {
Write-Host "✗ fuzzy.def not found" Write-Error "ERROR: fuzzy.def file not found!"
exit 1 exit 1
} }