Skip to content

Commit e317c8b

Browse files
committed
Consolidate license header workflows
1 parent d1903da commit e317c8b

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
@@ -39,7 +39,8 @@ jobs:
3939
- 'platforms/android/**'
4040
- 'protocol/**'
4141
- '.github/workflows/android-test.yml'
42-
- '.github/workflows/android-license-headers.yml'
42+
- '.github/workflows/license-headers.yml'
43+
- 'scripts/check_license_headers.rb'
4344
- '.github/workflows/breaking-changes.yml'
4445
- '.github/workflows/ci.yml'
4546
swift:
@@ -73,7 +74,8 @@ jobs:
7374
web:
7475
- 'platforms/web/**'
7576
- '.github/workflows/web.yml'
76-
- '.github/workflows/web-license-headers.yml'
77+
- '.github/workflows/license-headers.yml'
78+
- 'scripts/check_license_headers.rb'
7779
- '.github/actions/setup/**'
7880
- '.github/workflows/ci.yml'
7981
@@ -87,7 +89,9 @@ jobs:
8789
name: Android
8890
needs: changes
8991
if: needs.changes.outputs.android == 'true'
90-
uses: ./.github/workflows/android-license-headers.yml
92+
uses: ./.github/workflows/license-headers.yml
93+
with:
94+
target: platforms/android
9195

9296
swift-test-package:
9397
name: Swift
@@ -171,7 +175,9 @@ jobs:
171175
name: Web
172176
needs: changes
173177
if: needs.changes.outputs.web == 'true'
174-
uses: ./.github/workflows/web-license-headers.yml
178+
uses: ./.github/workflows/license-headers.yml
179+
with:
180+
target: platforms/web/src
175181

176182
breaking-changes:
177183
name: Breaking Changes
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
@@ -77,7 +77,7 @@ open:
7777
"PRs": "https://github.com/Shopify/checkout-kit/pulls"
7878

7979
check:
80-
android-license-headers: cd platforms/android && ./scripts/check_license_headers.rb
80+
android-license-headers: ./scripts/check_license_headers.rb platforms/android
8181
android-detekt: cd platforms/android && ./gradlew detekt
8282
android-lint: cd platforms/android && ./gradlew lintRelease
8383
swift-lint: cd platforms/swift && ./Scripts/lint
@@ -167,14 +167,14 @@ commands:
167167
desc: Run all Android checks (license headers, detekt, android lint)
168168
run: |
169169
set -e
170+
./scripts/check_license_headers.rb platforms/android
170171
cd platforms/android
171-
./scripts/check_license_headers.rb
172172
./gradlew detekt
173173
./gradlew lintRelease
174174
subcommands:
175175
license-headers:
176176
desc: Check MIT license headers in source files
177-
run: cd platforms/android && ./scripts/check_license_headers.rb
177+
run: ./scripts/check_license_headers.rb platforms/android
178178
detekt:
179179
desc: Run detekt static analysis
180180
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)