From 937e49a3ff461f8a6dc21842e1dcc7d90dfdb414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ka=C5=A1par?= Date: Thu, 29 Aug 2019 00:05:48 +0200 Subject: [PATCH 1/7] Update ci.yml Add name to the script run phase --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf9ce035c..c0c8a5e0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: CI -on: [push, pull_request] +on: [push] jobs: buildsh: @@ -29,4 +29,5 @@ jobs: steps: - name: Checkout the Git repository uses: actions/checkout@v1 - - run: ./build.sh ${{ matrix.mode }} + - name: Run build script + run: ./build.sh ${{ matrix.mode }} From 509949028f62be2499a00af0d365051ae52c6dd3 Mon Sep 17 00:00:00 2001 From: Jakub Kaspar Date: Thu, 29 Aug 2019 00:06:38 +0200 Subject: [PATCH 2/7] Revert back Dangerfile and remove danger JS, create separate workflow for push for tests and for PR for tests + danger, run ruby danger as part of the PR check --- .github/workflows/ci_pr.yml | 37 +++++++++++++++ .github/workflows/danger.yml | 28 ------------ Dangerfile | 83 +++++++++++++++++++++++++++++++++ build.sh | 7 +++ dangerfile.js | 89 ------------------------------------ 5 files changed, 127 insertions(+), 117 deletions(-) create mode 100644 .github/workflows/ci_pr.yml delete mode 100644 .github/workflows/danger.yml create mode 100644 Dangerfile delete mode 100644 dangerfile.js diff --git a/.github/workflows/ci_pr.yml b/.github/workflows/ci_pr.yml new file mode 100644 index 000000000..98cc8715e --- /dev/null +++ b/.github/workflows/ci_pr.yml @@ -0,0 +1,37 @@ +name: CI + +on: [pull_request] + +jobs: + buildsh: + strategy: + matrix: + mode: [tests, danger, framework, life-without-cocoapods, carthage, examples-pt1, examples-pt2, examples-pt3, examples-pt4] + include: + - mode: tests + name: Build and run tests + - mode: danger + name: Run Danger + - mode: framework + name: Build Texture as a dynamic framework + - mode: life-without-cocoapods + name: Build Texture as a static library + - mode: carthage + name: Verify that Carthage works + - mode: examples-pt1 + name: Build examples (examples-pt1) + - mode: examples-pt2 + name: Build examples (examples-pt2) + - mode: examples-pt3 + name: Build examples (examples-pt3) + - mode: examples-pt4 + name: Build examples (examples-pt4) + name: ${{ matrix.name }} + runs-on: macOS-10.14 + steps: + - name: Checkout the Git repository + uses: actions/checkout@v1 + - name: Run build script + run: ./build.sh ${{ matrix.mode }} + env: + DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }} diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml deleted file mode 100644 index 6d2a2e838..000000000 --- a/.github/workflows/danger.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Danger - -on: [pull_request] - -jobs: - danger: - name: Danger JS - runs-on: ubuntu-latest - steps: - - name: Checkout the Git repository - uses: actions/checkout@v1 - # TODO: Figure out why GITHUB_TOKEN isn't enough for Danger JS to create a comment. - # Our dangerfile.js escalates any warnings as failures to get more attention. - # - # Here is the error response from GitHub API: - # - # Request failed [403]: https://api.github.com/repos/TextureGroup/Texture/issues/1635/comments - # Response: { - # "message": "Resource not accessible by integration", - # "documentation_url": "https://developer.github.com/v3/issues/comments/#create-a-comment" - # } - # - # https://github.com/TextureGroup/Texture/pull/1635/checks?check_run_id=200541353 - - name: Danger - uses: danger/danger-js@9.1.8 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DANGER_DISABLE_TRANSPILATION: true diff --git a/Dangerfile b/Dangerfile new file mode 100644 index 000000000..147d38906 --- /dev/null +++ b/Dangerfile @@ -0,0 +1,83 @@ +require 'open-uri' + +source_pattern = /(\.m|\.mm|\.h)$/ + +modified_source_files = git.modified_files.grep(source_pattern) +has_modified_source_files = !modified_source_files.empty? +added_source_files = git.added_files.grep(source_pattern) +has_added_source_files = !added_source_files.empty? + +# Make it more obvious that a PR is a work in progress and shouldn't be merged yet +warn("PR is classed as Work in Progress") if github.pr_title.include? "[WIP]" + +# Warn when there is a big PR +warn("This is a big PR, please consider splitting it up to ease code review.") if git.lines_of_code > 500 + +# Modifying the changelog will probably get overwritten. +if git.modified_files.include?("CHANGELOG.md") && !github.pr_title.include?("#changelog") + warn("PR modifies CHANGELOG.md, which is a generated file. Add #changelog to the title to suppress this warning.") +end + +def full_license(partial_license, filename) + license_header = <<-HEREDOC +// + HEREDOC + license_header += "// " + filename + "\n" + license_header += <<-HEREDOC +// Texture +// + HEREDOC + license_header += partial_license + return license_header +end + +def check_file_header(files_to_check, licenses) + repo_name = github.pr_json["base"]["repo"]["full_name"] + pr_number = github.pr_json["number"] + files = github.api.pull_request_files(repo_name, pr_number) + files.each do |file| + if files_to_check.include?(file["filename"]) + filename = File.basename(file["filename"]) + + data = "" + contents = github.api.get file["contents_url"] + open(contents["download_url"]) { |io| + data += io.read + } + + correct_license = false + licenses.each do |license| + license_header = full_license(license, filename) + if data.include? "Pinterest, Inc." + correct_license = true + end + end + + if correct_license == false + warn ("Please ensure license is correct for #{filename}: \n```\n" + full_license(licenses[0], filename) + "```") + end + + end + end +end + +# Ensure new files have proper header +new_source_license_header = <<-HEREDOC +// Copyright (c) Pinterest, Inc. All rights reserved. +// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0 +HEREDOC + +if has_added_source_files + check_file_header(added_source_files, [new_source_license_header]) +end + +# Ensure modified files have proper header +modified_source_license_header = <<-HEREDOC +// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. +// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved. +// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0 +HEREDOC + +if has_modified_source_files + check_file_header(modified_source_files, [modified_source_license_header, new_source_license_header]) +end diff --git a/build.sh b/build.sh index a58fc11fc..5d8c38575 100755 --- a/build.sh +++ b/build.sh @@ -80,6 +80,13 @@ if [ "$MODE" = "tests" -o "$MODE" = "all" ]; then success="1" fi +if [ "$MODE" = "danger" -o "$MODE" = "all" ]; then + bundle install + echo "Running Danger..." + bundle exec danger --fail-on-errors=true + success="1" +fi + if [ "$MODE" = "tests_listkit" ]; then echo "Building & testing AsyncDisplayKit+IGListKit." pod install --project-directory=SubspecWorkspaces/ASDKListKit diff --git a/dangerfile.js b/dangerfile.js deleted file mode 100644 index b191420c3..000000000 --- a/dangerfile.js +++ /dev/null @@ -1,89 +0,0 @@ -const { danger, fail, warn, schedule } = require('danger'); -const { readFileSync } = require('fs'); - -const source_pattern = /(\.m|\.mm|\.h)$/; -const modified_source_files = danger.git.modified_files.filter(f => source_pattern.test(f)); -const has_modified_source_files = (Array.isArray(modified_source_files) && modified_source_files.length > 0); -const added_source_files = danger.git.created_files.filter(f => source_pattern.test(f)); -const has_added_source_files = (Array.isArray(added_source_files) && added_source_files.length > 0); - -// Make it more obvious that a PR is a work in progress and shouldn't be merged yet -if (danger.github.pr.title.includes("[WIP]")) { - const msg = "PR is classed as Work in Progress"; - console.error("FAIL: " + msg); - fail(msg); -} - -// Warn when there is a big PR -if (danger.github.pr.additions + danger.github.pr.deletions > 500) { - const msg = "This is a big PR, please consider splitting it up to ease code review."; - console.error("WARN: "+ msg); - warn(msg); -} - -// Modifying the changelog will probably get overwritten. -if (danger.git.modified_files.includes("CHANGELOG.md")) { - if (danger.github.pr.title.includes("#changelog")) { - const msg = "PR modifies CHANGELOG.md, which is a generated file. #changelog added to the title to suppress this warning."; - console.error("WARN: "+ msg); - warn(msg); - } else { - const msg = "PR modifies CHANGELOG.md, which is a generated file. Add #changelog to the title to suppress this failure."; - console.error("FAIL: " + msg); - fail(msg); - } -} - -// Reference: http://a32.me/2014/03/heredoc-multiline-variable-with-javascript/ -function hereDoc(f) { - return f.toString(). - replace(/^[^\/]+\/\*!?/, ''). - replace(/\*\/[^\/]+$/, ''); -} - -function full_license(partial_license, filename) { - var license_header = hereDoc(function() {/*! -// -*/}); - license_header += "// " + filename; - license_header += hereDoc(function() {/*! -// Texture -//*/}); - license_header += partial_license; - return license_header; -} - -function check_file_header(files_to_check, license) { - for (let file of files_to_check) { - const filename = file.replace(/^.*[\\\/]/, ''); // Reference: https://stackoverflow.com/a/423385 - schedule(async () => { - const content = await danger.github.utils.fileContents(file); - if (!content.includes("Pinterest, Inc.")) { - const msg = "Please ensure license is correct for " + filename +":\n```" + full_license(license, filename) + "\n```"; - console.error("FAIL: " + msg); - fail(msg); - } - }); - } -} - -const new_source_license_header = hereDoc(function() {/*! -// Copyright (c) Pinterest, Inc. All rights reserved. -// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0 -//*/}); - -const modified_source_license_header = hereDoc(function() {/*! -// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. -// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved. -// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0 -//*/}); - -// Ensure new files have proper header -if (has_added_source_files) { - check_file_header(added_source_files, new_source_license_header); -} - -// Ensure modified files have proper header -if (has_modified_source_files) { - check_file_header(modified_source_files, modified_source_license_header); -} From 839ba3ae2a6bc94240735bdcb84075bd7f6f82af Mon Sep 17 00:00:00 2001 From: Jakub Kaspar Date: Thu, 29 Aug 2019 00:07:42 +0200 Subject: [PATCH 3/7] remove PR ci --- .github/workflows/ci_pr.yml | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 .github/workflows/ci_pr.yml diff --git a/.github/workflows/ci_pr.yml b/.github/workflows/ci_pr.yml deleted file mode 100644 index 98cc8715e..000000000 --- a/.github/workflows/ci_pr.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: CI - -on: [pull_request] - -jobs: - buildsh: - strategy: - matrix: - mode: [tests, danger, framework, life-without-cocoapods, carthage, examples-pt1, examples-pt2, examples-pt3, examples-pt4] - include: - - mode: tests - name: Build and run tests - - mode: danger - name: Run Danger - - mode: framework - name: Build Texture as a dynamic framework - - mode: life-without-cocoapods - name: Build Texture as a static library - - mode: carthage - name: Verify that Carthage works - - mode: examples-pt1 - name: Build examples (examples-pt1) - - mode: examples-pt2 - name: Build examples (examples-pt2) - - mode: examples-pt3 - name: Build examples (examples-pt3) - - mode: examples-pt4 - name: Build examples (examples-pt4) - name: ${{ matrix.name }} - runs-on: macOS-10.14 - steps: - - name: Checkout the Git repository - uses: actions/checkout@v1 - - name: Run build script - run: ./build.sh ${{ matrix.mode }} - env: - DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }} From b34e54452139f189012b71e318ecc9eded298e62 Mon Sep 17 00:00:00 2001 From: Jakub Kaspar Date: Thu, 29 Aug 2019 00:10:42 +0200 Subject: [PATCH 4/7] Revert "remove PR ci" This reverts commit 839ba3ae2a6bc94240735bdcb84075bd7f6f82af. --- .github/workflows/ci_pr.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/ci_pr.yml diff --git a/.github/workflows/ci_pr.yml b/.github/workflows/ci_pr.yml new file mode 100644 index 000000000..98cc8715e --- /dev/null +++ b/.github/workflows/ci_pr.yml @@ -0,0 +1,37 @@ +name: CI + +on: [pull_request] + +jobs: + buildsh: + strategy: + matrix: + mode: [tests, danger, framework, life-without-cocoapods, carthage, examples-pt1, examples-pt2, examples-pt3, examples-pt4] + include: + - mode: tests + name: Build and run tests + - mode: danger + name: Run Danger + - mode: framework + name: Build Texture as a dynamic framework + - mode: life-without-cocoapods + name: Build Texture as a static library + - mode: carthage + name: Verify that Carthage works + - mode: examples-pt1 + name: Build examples (examples-pt1) + - mode: examples-pt2 + name: Build examples (examples-pt2) + - mode: examples-pt3 + name: Build examples (examples-pt3) + - mode: examples-pt4 + name: Build examples (examples-pt4) + name: ${{ matrix.name }} + runs-on: macOS-10.14 + steps: + - name: Checkout the Git repository + uses: actions/checkout@v1 + - name: Run build script + run: ./build.sh ${{ matrix.mode }} + env: + DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }} From 7375d07b1a162eecffdedbdd96486b8e6b743d70 Mon Sep 17 00:00:00 2001 From: Jakub Kaspar Date: Thu, 29 Aug 2019 00:14:47 +0200 Subject: [PATCH 5/7] cahnge token to default one --- .github/workflows/ci_pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_pr.yml b/.github/workflows/ci_pr.yml index 98cc8715e..791ae11fe 100644 --- a/.github/workflows/ci_pr.yml +++ b/.github/workflows/ci_pr.yml @@ -34,4 +34,4 @@ jobs: - name: Run build script run: ./build.sh ${{ matrix.mode }} env: - DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }} + DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} From e0c06a22fbb639b15923a13ff871fafbeefbecb3 Mon Sep 17 00:00:00 2001 From: Jakub Kaspar Date: Thu, 29 Aug 2019 08:14:56 +0200 Subject: [PATCH 6/7] PR feedback --- .github/workflows/ci.yml | 2 +- .github/workflows/ci_pr.yml | 37 ------------------------------------ .github/workflows/danger.yml | 21 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 38 deletions(-) delete mode 100644 .github/workflows/ci_pr.yml create mode 100644 .github/workflows/danger.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0c8a5e0b..61bd5bfce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: CI -on: [push] +on: [push, pull_request] jobs: buildsh: diff --git a/.github/workflows/ci_pr.yml b/.github/workflows/ci_pr.yml deleted file mode 100644 index 791ae11fe..000000000 --- a/.github/workflows/ci_pr.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: CI - -on: [pull_request] - -jobs: - buildsh: - strategy: - matrix: - mode: [tests, danger, framework, life-without-cocoapods, carthage, examples-pt1, examples-pt2, examples-pt3, examples-pt4] - include: - - mode: tests - name: Build and run tests - - mode: danger - name: Run Danger - - mode: framework - name: Build Texture as a dynamic framework - - mode: life-without-cocoapods - name: Build Texture as a static library - - mode: carthage - name: Verify that Carthage works - - mode: examples-pt1 - name: Build examples (examples-pt1) - - mode: examples-pt2 - name: Build examples (examples-pt2) - - mode: examples-pt3 - name: Build examples (examples-pt3) - - mode: examples-pt4 - name: Build examples (examples-pt4) - name: ${{ matrix.name }} - runs-on: macOS-10.14 - steps: - - name: Checkout the Git repository - uses: actions/checkout@v1 - - name: Run build script - run: ./build.sh ${{ matrix.mode }} - env: - DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml new file mode 100644 index 000000000..1fce393a0 --- /dev/null +++ b/.github/workflows/danger.yml @@ -0,0 +1,21 @@ +name: CI + +on: [pull_request] + +jobs: + buildsh: + strategy: + matrix: + mode: [danger] + include: + - mode: danger + name: Run Danger + name: ${{ matrix.name }} + runs-on: macOS-10.14 + steps: + - name: Checkout the Git repository + uses: actions/checkout@v1 + - name: Run build script + run: ./build.sh ${{ matrix.mode }} + env: + DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} From af6362c7924b1ae76fa4484f611d5212297279a4 Mon Sep 17 00:00:00 2001 From: Jakub Kaspar Date: Thu, 29 Aug 2019 08:15:43 +0200 Subject: [PATCH 7/7] Rename danger.yml name --- .github/workflows/danger.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml index 1fce393a0..c71f053fa 100644 --- a/.github/workflows/danger.yml +++ b/.github/workflows/danger.yml @@ -1,4 +1,4 @@ -name: CI +name: Danger on: [pull_request]