Skip to content

Commit ec9ba8b

Browse files
committed
feat: ライセンススナップショットのチェックと自動更新ワークフローを追加
1 parent a04a334 commit ec9ba8b

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

.gitattributes

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Enforce LF endings for text files to avoid CRLF noise, especially in generated license snapshot
2+
* text=auto eol=lf
3+
4+
# Explicitly enforce LF for the generated OSS licenses snapshot
5+
lib/generated/oss_licenses.dart text eol=lf
6+
7+
# Keep binary files untouched
8+
*.png binary
9+
*.jpg binary
10+
*.jpeg binary
11+
*.ttf binary
12+
*.otf binary
13+
*.ico binary
14+
15+
# Scripts (shell) also LF
16+
*.sh text eol=lf
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: License Snapshot Check
2+
3+
on:
4+
pull_request:
5+
branches: [ main, fix/** ]
6+
paths:
7+
- 'pubspec.yaml'
8+
- 'pubspec.lock'
9+
- 'lib/generated/oss_licenses.dart'
10+
- '.github/workflows/license_snapshot.yml'
11+
push:
12+
branches: [ main ]
13+
paths:
14+
- 'pubspec.yaml'
15+
- 'pubspec.lock'
16+
- 'lib/generated/oss_licenses.dart'
17+
- '.github/workflows/license_snapshot.yml'
18+
workflow_dispatch: {}
19+
20+
jobs:
21+
license-diff:
22+
name: Verify generated OSS licenses snapshot is up-to-date
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Set up Flutter (stable)
31+
uses: subosito/flutter-action@v2
32+
with:
33+
channel: 'stable'
34+
cache: true
35+
36+
- name: Pub get
37+
run: flutter pub get
38+
39+
- name: Generate license snapshot
40+
run: >-
41+
dart run flutter_oss_licenses:generate
42+
--output lib/generated/oss_licenses.dart
43+
44+
- name: Check diff
45+
run: |
46+
if git diff --name-only --exit-code lib/generated/oss_licenses.dart; then
47+
echo "License snapshot is up-to-date.";
48+
else
49+
echo '::error file=lib/generated/oss_licenses.dart::License snapshot is outdated. Run:';
50+
echo 'dart run flutter_oss_licenses:generate --output lib/generated/oss_licenses.dart';
51+
echo 'and commit the result.';
52+
exit 1;
53+
fi
54+
55+
- name: Show diff (only when failed previously)
56+
if: failure()
57+
run: git --no-pager diff lib/generated/oss_licenses.dart
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: License Snapshot Auto-Update
2+
3+
on:
4+
schedule:
5+
# 毎日 03:15 UTC (日本時間 12:15 JST頃) 実行。GitHub Actions は分散なので多少の誤差あり。
6+
- cron: '15 3 * * *'
7+
workflow_dispatch: {}
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
update-license-snapshot:
15+
name: Generate & Auto PR (oss licenses)
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Set up Flutter (stable)
25+
uses: subosito/flutter-action@v2
26+
with:
27+
channel: 'stable'
28+
cache: true
29+
30+
- name: Pub get
31+
run: flutter pub get
32+
33+
- name: Re-generate license snapshot
34+
run: >-
35+
dart run flutter_oss_licenses:generate
36+
--output lib/generated/oss_licenses.dart
37+
38+
- name: Detect changes
39+
id: diff
40+
run: |
41+
if git diff --quiet --exit-code lib/generated/oss_licenses.dart; then
42+
echo "changed=false" >> $GITHUB_OUTPUT
43+
else
44+
echo "changed=true" >> $GITHUB_OUTPUT
45+
fi
46+
47+
- name: Create Pull Request
48+
if: steps.diff.outputs.changed == 'true'
49+
uses: peter-evans/create-pull-request@v6
50+
with:
51+
commit-message: 'chore(licenses): update oss licenses snapshot'
52+
title: 'chore(licenses): update oss licenses snapshot'
53+
body: |
54+
自動生成ワークフローにより `lib/generated/oss_licenses.dart` を更新しました。
55+
56+
- 依存追加/更新/削除を検出
57+
- コミット時刻: ${{ github.run_id }}
58+
59+
マージ後、手動のライセンス差分チェック (#license_snapshot.yml) も最新となります。
60+
branch: ci/update-oss-licenses
61+
delete-branch: true
62+
add-paths: |
63+
lib/generated/oss_licenses.dart
64+
labels: |
65+
chore
66+
automation
67+
68+
- name: No changes summary
69+
if: steps.diff.outputs.changed != 'true'
70+
run: echo "No license snapshot changes detected."

0 commit comments

Comments
 (0)