Skip to content

Commit 9c0df2b

Browse files
committed
ci: 更新 OSSLicensesDist.js 文件的自动化流程
-将运行环境从 Ubuntu 改为 Windows - 移除了对 tofrodos 的依赖 - 修改了文件比较逻辑,支持多个文件 - 优化了创建 Pull Request 的配置
1 parent 9b15dff commit 9c0df2b

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

.github/workflows/update-oss-licenses-dist.yml

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,14 @@ on:
77

88
jobs:
99
update-oss-licenses-dist:
10-
runs-on: ubuntu-latest
10+
runs-on: windows-latest
1111
permissions:
1212
contents: write
1313
pull-requests: write
1414
defaults:
1515
run:
1616
working-directory: source
1717

18-
strategy:
19-
matrix:
20-
file:
21-
- pages/utils/OSSLicensesDist.js
22-
2318
steps:
2419
- name: Checkout repository
2520
uses: actions/checkout@v3
@@ -32,42 +27,37 @@ jobs:
3227
- name: Install dependencies
3328
run: yarn install
3429

35-
- name: Install tofrodos
36-
run: sudo apt-get update && sudo apt-get install tofrodos
37-
38-
- name: Backup ${{ matrix.file }}
39-
run: |
40-
if [ -f ${{ matrix.file }} ]; then
41-
cp ${{ matrix.file }} ${{ matrix.file }}.bak
42-
else
43-
touch ${{ matrix.file }}.bak
44-
fi
45-
46-
- name: Build ${{ matrix.file }}
30+
- name: Build OSSLicensesDist.js
4731
run: yarn run build-oss-licenses-dist
4832

49-
- name: todos ${{ matrix.file }}
50-
run: todos ${{ matrix.file }}
33+
- name: Fetch latest changes from remote
34+
run: git fetch origin main
5135

52-
- name: Compare files for ${{ matrix.file }}
36+
- name: Compare files
5337
id: compare-files
5438
run: |
55-
if ! git diff --no-index --ignore-space-at-eol ${{ matrix.file }} ${{ matrix.file }}.bak; then
56-
echo "files_changed=true" >> $GITHUB_ENV
57-
else
58-
echo "files_changed=false" >> $GITHUB_ENV
59-
fi
60-
61-
- name: Delete ${{ matrix.file }}.bak
62-
if: env.files_changed == 'true'
63-
run: rm ${{ matrix.file }}.bak
64-
65-
- name: Create Pull Request for ${{ matrix.file }}
39+
$filesChanged = $false
40+
$files = $env:FILES -split ' '
41+
foreach ($file in $files) {
42+
if (Test-Path $file) {
43+
$diffResult = git diff --no-index --exit-code origin/main:$file $file
44+
if ($LASTEXITCODE -ne 0) {
45+
$filesChanged = $true
46+
break
47+
}
48+
} else {
49+
Write-Output "File $file not found"
50+
}
51+
}
52+
echo "files_changed=$filesChanged" >> $env:GITHUB_ENV
53+
shell: pwsh
54+
55+
- name: Create Pull Request
6656
if: env.files_changed == 'true'
6757
uses: peter-evans/create-pull-request@v4
6858
with:
69-
title: '更新开源许可证信息(${{ matrix.file }}'
70-
body: '自动化更新 ${{ matrix.file }}'
71-
branch: 'update-licenses-${{ matrix.file }}'
72-
commit-message: 'Update ${{ matrix.file }}'
73-
labels: 'auto-generated'
59+
title: '更新开源许可证信息(OSSLicensesDist.js'
60+
body: '自动化更新 OSSLicensesDist.js'
61+
branch: 'update-licenses'
62+
commit-message: 'Update OSSLicensesDist.js'
63+
labels: 'auto-generated'

0 commit comments

Comments
 (0)