Skip to content

Commit 98ae0a7

Browse files
committed
Consolidate license header workflows
1 parent 82d42a0 commit 98ae0a7

10 files changed

Lines changed: 83 additions & 122 deletions

File tree

.github/workflows/android-license-headers.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ jobs:
3838
android:
3939
- 'platforms/android/**'
4040
- '.github/workflows/android-test.yml'
41-
- '.github/workflows/android-license-headers.yml'
41+
- '.github/workflows/license-headers.yml'
42+
- 'scripts/check_license_headers.rb'
4243
- '.github/workflows/ci.yml'
4344
swift:
4445
- 'platforms/swift/**'
@@ -61,7 +62,8 @@ jobs:
6162
web:
6263
- 'platforms/web/**'
6364
- '.github/workflows/web.yml'
64-
- '.github/workflows/web-license-headers.yml'
65+
- '.github/workflows/license-headers.yml'
66+
- 'scripts/check_license_headers.rb'
6567
- '.github/actions/setup/**'
6668
- '.github/workflows/ci.yml'
6769
@@ -75,7 +77,9 @@ jobs:
7577
name: Android
7678
needs: changes
7779
if: needs.changes.outputs.android == 'true'
78-
uses: ./.github/workflows/android-license-headers.yml
80+
uses: ./.github/workflows/license-headers.yml
81+
with:
82+
target: platforms/android
7983

8084
swift-test-package:
8185
name: Swift
@@ -147,7 +151,9 @@ jobs:
147151
name: Web
148152
needs: changes
149153
if: needs.changes.outputs.web == 'true'
150-
uses: ./.github/workflows/web-license-headers.yml
154+
uses: ./.github/workflows/license-headers.yml
155+
with:
156+
target: platforms/web/src
151157

152158
# Single required status check for branch protection.
153159
# Passes when every relevant platform job either succeeded or was skipped
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Check License Headers
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
target:
7+
description: Directory to scan, relative to repo root (e.g. platforms/android)
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
check:
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 5
18+
steps:
19+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
20+
with:
21+
submodules: true
22+
23+
- uses: ruby/setup-ruby@6aaa311d81eba98ae12eaffbcb63296ace0efcde # v1.307.0
24+
with:
25+
ruby-version: '3.3.6'
26+
27+
- name: Check license headers
28+
run: ruby scripts/check_license_headers.rb "${{ inputs.target }}"

.github/workflows/web-license-headers.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/web-publish-bootstrap.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
run: pnpm verify
6565

6666
- name: Check license headers
67-
run: ./scripts/check_license_headers.rb
67+
run: ruby "$GITHUB_WORKSPACE/scripts/check_license_headers.rb" platforms/web/src
6868

6969
- name: Pack and inspect contents
7070
run: |

.github/workflows/web-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
run: pnpm verify
101101

102102
- name: Check license headers
103-
run: ./scripts/check_license_headers.rb
103+
run: ruby "$GITHUB_WORKSPACE/scripts/check_license_headers.rb" platforms/web/src
104104

105105
- name: Pack and inspect contents
106106
run: |

dev.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ open:
7676
"PRs": "https://github.com/Shopify/checkout-kit/pulls"
7777

7878
check:
79-
android-license-headers: cd platforms/android && ./scripts/check_license_headers.rb
79+
android-license-headers: ./scripts/check_license_headers.rb platforms/android
8080
android-detekt: cd platforms/android && ./gradlew detekt
8181
android-lint: cd platforms/android && ./gradlew lintRelease
8282
swift-lint: cd platforms/swift && ./Scripts/lint
@@ -164,14 +164,14 @@ commands:
164164
desc: Run all Android checks (license headers, detekt, android lint)
165165
run: |
166166
set -e
167+
./scripts/check_license_headers.rb platforms/android
167168
cd platforms/android
168-
./scripts/check_license_headers.rb
169169
./gradlew detekt
170170
./gradlew lintRelease
171171
subcommands:
172172
license-headers:
173173
desc: Check MIT license headers in source files
174-
run: cd platforms/android && ./scripts/check_license_headers.rb
174+
run: ./scripts/check_license_headers.rb platforms/android
175175
detekt:
176176
desc: Run detekt static analysis
177177
run: cd platforms/android && ./gradlew detekt

platforms/android/scripts/check_license_headers.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

platforms/web/scripts/check_license_headers.rb

Lines changed: 0 additions & 39 deletions
This file was deleted.

scripts/check_license_headers.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env ruby
2+
require 'find'
3+
4+
# Extensions and excludes are baked in — this script is opinionated for the
5+
# platforms in this repo. Add to these lists when introducing a new language
6+
# or build-output directory that should be covered.
7+
EXTENSIONS = %w[.kt .kts .ts .tsx].freeze
8+
EXCLUDES = %w[
9+
*/build/generated/*
10+
*/build/*
11+
*.test.ts
12+
*.test.tsx
13+
*.d.ts
14+
].freeze
15+
16+
abort 'Usage: check_license_headers.rb <root>' if ARGV.empty?
17+
18+
root = File.expand_path(ARGV[0])
19+
abort "error: #{ARGV[0]} is not a directory" unless File.directory?(root)
20+
21+
missing = []
22+
23+
Find.find(root) do |path|
24+
next unless File.file?(path)
25+
next unless EXTENSIONS.any? { |ext| path.end_with?(ext) }
26+
next if EXCLUDES.any? { |pattern| File.fnmatch?(pattern, path) }
27+
28+
lines = File.readlines(path)
29+
has_header = lines[0]&.start_with?('/*') && lines[1]&.include?('MIT License')
30+
missing << path unless has_header
31+
end
32+
33+
if missing.empty?
34+
puts 'No missing license headers found'
35+
exit 0
36+
end
37+
38+
puts "#{missing.size} file(s) missing license headers:"
39+
missing.each { |f| puts " #{f.sub("#{root}/", '')}" }
40+
exit 1

0 commit comments

Comments
 (0)