Skip to content

Commit e980b72

Browse files
authored
Create PR for NOTICES (#9708)
* Create a PR for Notices Generation.
1 parent cb2cfcb commit e980b72

File tree

4 files changed

+97
-21
lines changed

4 files changed

+97
-21
lines changed

.github/actions/notices_generation/action.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ inputs:
1212
description: 'The minimum version of iOS'
1313
required: true
1414
default: '10.0'
15-
search_local_pod_version:
15+
search-local-pod-version:
1616
description: 'Add pod version from local spec repo'
1717
required: true
1818
default: false
1919
type: boolean
20+
notices-path:
21+
description: 'Path of Notices file containing all licences.'
22+
required: true
2023
outputs:
2124
notices_contents:
2225
description: 'contents of notices'
@@ -26,18 +29,18 @@ runs:
2629
- uses: ruby/setup-ruby@v1
2730
with:
2831
ruby-version: "2.7"
29-
- name: First step
32+
- name: Generate a NOTICES file
3033
run: |
3134
cd "${{ github.action_path }}"
3235
bundle install
33-
if ${{ inputs.search_local_pod_version == 'true' }} ; then
34-
ruby app.rb --pods ${{ inputs.pods }} --sources ${{ inputs.sources }} --min_ios_version ${{ inputs.min-ios-version }} --search_local_pod_version
36+
if ${{ inputs.search-local-pod-version == 'true' }} ; then
37+
ruby app.rb --pods ${{ inputs.pods }} --sources ${{ inputs.sources }} --min_ios_version ${{ inputs.min-ios-version }} --search_local_pod_version --notices_path ${{ inputs.notices-path }}
3538
else
36-
ruby app.rb --pods ${{ inputs.pods }} --sources ${{ inputs.sources }} --min_ios_version ${{ inputs.min-ios-version }}
39+
ruby app.rb --pods ${{ inputs.pods }} --sources ${{ inputs.sources }} --min_ios_version ${{ inputs.min-ios-version }} --notices_path ${{ inputs.notices-path }}
3740
fi
3841
shell: bash
3942
- name: Upload artifacts
4043
uses: actions/upload-artifact@v3
4144
with:
4245
name: notices
43-
path: .github/actions/notices_generation/NOTICES
46+
path: ${{ inputs.notices-path }}

.github/actions/notices_generation/app.rb

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
require 'cocoapods'
1818
require 'digest'
19-
require 'octokit'
2019
require 'optparse'
2120
require 'plist'
2221
require 'tmpdir'
@@ -27,7 +26,7 @@
2726
# Default sources of min iOS version
2827
SOURCES=["https://cdn.cocoapods.org/"]
2928
MIN_IOS_VERSION="12.0"
30-
NOTICES_OUTPUT_PATH="./NOTICES"
29+
NOTICES_OUTPUT_PATH="./CoreOnly/NOTICES"
3130
SEARCH_LOCAL_POD_VERSION=false
3231

3332
@options = {
@@ -42,8 +41,8 @@
4241
opts.on('-p', '--pods PODS', 'Pods seperated by space or comma.') { |v| @options[:pods] = v.split(/[ ,]/) }
4342
opts.on('-s', '--sources SOURCES', 'Sources of Pods') { |v| @options[:sources] = v.split(/[ ,]/) }
4443
opts.on('-m', '--min_ios_version MIN_IOS_VERSION', 'Minimum iOS version') { |v| @options[:min_ios_version] = v }
45-
opts.on('-n', '--output_path OUTPUT_PATH', 'The output path of NOTICES') { |v| @options[:output_path] = v }
46-
opts.on('-v', '--search-local-pod-version', 'Attach the latest pod version to a pod in Podfile') { |v| @options[:search_local_pod_version] = true }
44+
opts.on('-n', '--notices_path OUTPUT_PATH', 'The output path of NOTICES') { |v| @options[:output_path] = v }
45+
opts.on('-v', '--search_local_pod_version', 'Attach the latest pod version to a pod in Podfile') { |v| @options[:search_local_pod_version] = true }
4746
end.parse!
4847

4948
raise OptionParser::MissingArgument if @options[:pods].nil?
@@ -121,18 +120,27 @@ def generate_notices_content(sources: SOURCES, pods: PODS, min_ios_version: MIN_
121120
create_podfile(path: temp_dir, sources: sources, target: DEFAULT_TESTAPP_TARGET,pods: pods, min_ios_version: min_ios_version, search_local_pod_version: SEARCH_LOCAL_POD_VERSION)
122121
pod_install_result = `pod install --allow-root`
123122
puts pod_install_result
124-
licences = Plist.parse_xml("Pods/Target Support Files/Pods-testApp/Pods-testApp-acknowledgements.plist")
123+
licenses = Plist.parse_xml("Pods/Target Support Files/Pods-testApp/Pods-testApp-acknowledgements.plist")
125124

126-
existing_licences={}
127-
for licence in licences["PreferenceSpecifiers"] do
128-
if existing_licences.include?(licence["FooterText"])
129-
existing_licences.store(licence["FooterText"], existing_licences.fetch(licence["FooterText"])+"\n"+licence["Title"])
125+
existing_licenses={}
126+
for license in licenses["PreferenceSpecifiers"] do
127+
if existing_licenses.include?(license["FooterText"])
128+
existing_licenses.store(license["FooterText"], existing_licenses.fetch(license["FooterText"])+"\n"+license["Title"])
130129
next
131130
end
132-
existing_licences.store(licence["FooterText"], licence["Title"])
131+
existing_licenses.store(license["FooterText"], license["Title"])
133132
end
134-
existing_licences.each{ |licence, title|
135-
content += "#{title}\n#{licence}\n"
133+
existing_licenses.each{ |license, title|
134+
# The NOTICES format is like:
135+
# ```
136+
# ${title}
137+
# ${license}
138+
#
139+
# ${title}
140+
# ${license}
141+
# ...
142+
# ```
143+
content += "#{title}\n#{license}\n\n"
136144
}
137145
end
138146
end

.github/workflows/notice_generation.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@ name: generate_notices
33
on:
44
pull_request:
55
paths:
6-
- '.github/workflows/testing_actions.yml'
6+
- '.github/workflows/notice_generation.yml'
77
- '.github/actions/notices_generation**'
88
jobs:
99
generate_a_notice:
1010
# Don't run on private repo.
1111
if: github.repository == 'Firebase/firebase-ios-sdk' && github.event_name != 'schedule'
1212
runs-on: macos-11
1313
name: Generate NOTICES
14+
env:
15+
# The path of NOTICES based on the root dir of repo."
16+
NOTICES_PATH: "CoreOnly/NOTICES"
1417
steps:
15-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
1619
- name: Get all pod names
1720
run: |
1821
cd "${GITHUB_WORKSPACE}/ReleaseTooling/"
1922
swift run manifest --pod-name-output-file-path ./output.txt
2023
PODS=`cat ./output.txt`
2124
echo "PODS=${PODS}" >> $GITHUB_ENV
25+
echo "NOTICES_PATH=${GITHUB_WORKSPACE}/${NOTICES_PATH}" >> $GITHUB_ENV
2226
- name: Create a local specs repo
2327
run: |
2428
cd "${GITHUB_WORKSPACE}/ReleaseTooling/"
@@ -30,4 +34,10 @@ jobs:
3034
pods: ${{ env.PODS }}
3135
sources: "https://github.com/firebase/SpecsTesting,https://github.com/firebase/SpecsStaging,https://cdn.cocoapods.org"
3236
min-ios-version: "13.0"
33-
search_local_pod_version: true
37+
search-local-pod-version: true
38+
notices-path: ${{ env.NOTICES_PATH }}
39+
- name: Create a pull request
40+
run: |
41+
gem install octokit
42+
ruby scripts/create_pull_request.rb --repo-root ${GITHUB_WORKSPACE} --repo-token ${{ secrets.GITHUB_TOKEN }} --notices-path ${{ env.NOTICES_PATH }}
43+
shell: bash

scripts/create_pull_request.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright 2022 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'octokit'
18+
require 'optparse'
19+
20+
@options = {
21+
repo_root: "./"
22+
}
23+
begin
24+
OptionParser.new do |opts|
25+
opts.banner = "Usage: create_pull_request.rb [options]"
26+
opts.on('-r', '--repo-root REPO_ROOT', 'Root path of the repo dir.') { |v| @options[:repo_root] = v }
27+
opts.on('-t', '--repo-token REPO_TOKEN', 'Token with write access') { |v| @options[:repo_token] = v }
28+
opts.on('-n', '--notices-path NOTICES_PATH', 'Path of NOTICES file') { |v| @options[:notices_path] = v }
29+
end.parse!
30+
31+
raise OptionParser::MissingArgument if @options[:repo_token].nil? || @options[:notices_path].nil?
32+
rescue OptionParser::MissingArgument
33+
puts "Notices path, `--notices-path`, should be specified. " if @options[:notices_path].nil?
34+
puts "A token ,`--repo-token`, should be provided for creating a pull request." if @options[:repo_token].nil?
35+
raise
36+
end
37+
38+
REPO_ROOT=@options[:repo_root]
39+
ACCESS_TOKEN=@options[:repo_token]
40+
NOTICES_PATH=@options[:notices_path]
41+
42+
def generate_pr_for_notices_changes(repo_root:, notices_path:)
43+
system("cd #{repo_root}")
44+
system("git checkout -b notices_diff_detected\n git add CoreOnly/NOTICES\n git commit -m \"NOTICES diff detected.\"\n git push -u origin notices_diff_detected")
45+
client = Octokit::Client.new(access_token: ACCESS_TOKEN)
46+
client.create_pull_request("firebase/firebase-ios-sdk", "master", "notices_diff_detected", "Pull Request title", "Pull Request body")
47+
end
48+
49+
50+
def main()
51+
generate_pr_for_notices_changes(repo_root: REPO_ROOT, notices_path: NOTICES_PATH)
52+
end
53+
54+
main()
55+

0 commit comments

Comments
 (0)