diff --git a/LICENSE b/LICENSE index 6fb4e41..11d45a3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,205 +1,15 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ +Copyright 2023 The Assay Depot Inc. - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION +Additional copyright may be held by others, as reflected in the commit history. - 1. Definitions. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. + http://www.apache.org/licenses/LICENSE-2.0 - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2012 Penn State University - Copyright 2013 University of Notre Dame, Northwestern University, and Data Curation Experts - Copyright 2014 Data Curation Experts - Additional copyright may be held by others, as reflected in the commit log - - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/README.md b/README.md index 3276d9b..379300e 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,121 @@ + + +**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* + +- [HykuKnapsack](#hykuknapsack) + - [Introduction](#introduction) + - [Precedence](#precedence) + - [Usage](#usage) + - [Creating Your Knapsack](#creating-your-knapsack) + - [New Repository](#new-repository) + - [Fork on Github](#fork-on-github) + - [Hyku and HykuKnapsack](#hyku-and-hykuknapsack) + - [Overrides](#overrides) + - [Deployment scripts](#deployment-scripts) + - [Theme files](#theme-files) + - [Gems](#gems) + - [Converting a Fork of Hyku Prime to a Knapsack](#converting-a-fork-of-hyku-prime-to-a-knapsack) + - [Installation](#installation) + - [Contributing](#contributing) + - [License](#license) + + + # HykuKnapsack -Hyku Knapsack is a little wrapper around Hyku to make development and deployment easier. Primary goals of this project include making contributing back to the Hyku project easier and making upgrades a snap. + +[Hyku Knapsack](https://github.com/samvera-labs/hyku_knapsack) is a little wrapper around Hyku to make development and deployment easier. Primary goals of this project +include making contributing back to the Hyku project easier and making upgrades a snap. + +## Introduction + +[Hyku](https://github.com/samvera/hyku) is a Rails application that leverages Rails Engines and other gems to provide functionality. A Hyku Knapsack is also a Rails engine, but it integrates differently than other engines. + +### Precedence + +In a traditional setup, a Rails' application's views, translations, and code supsedes all other gems and engines. However, we have setup Hyku Knapsack to have a higher load precedence than the underlying Hyku application. + +The goal being that a Hyku Knapsack should make it easier to maintain, upgrade, and contribute fixes back to Hyku. + +See [Overrides](#overrides) for more discussion on working with a Hyku Knapsack. ## Usage -Start by making a clone. You can do this by: +### Creating Your Knapsack + +In working on a Hyku Knapsack, you want to be able to track changes in the upstream knapsack as well as make local changes for your application. Start by making a clone. You can do this by: -- (Preferred) Creating a [New Repository](#new-repository) and pushing your local clone +- _Preferred_ Creating a [New Repository](#new-repository) and pushing your local clone - Creating a [Fork on Github](#fork-on-github) -### New Repository +#### New Repository -In your Repository host of choice, create a new (and for now empty) repository. That will provide you `$NEW_REPO_URL`. +In your Repository host of choice, create a new (and for now empty) repository. -**Note:** Due to bundler limitations, the name of your project (e.g. `$PROJECT_NAME`) must only contain letters, numbers and underscores. +- `$PROJECT_NAME` must only contain letters, numbers and underscores due to a bundler limitation. +- `$NEW_REPO_URL` is the location of your application's knapsack git project (e.g. https://github.com/my-org/my_org_knapsack) ```bash -git clone git@github.com:samvera-labs/hyku_knapsack.git $PROJECT_NAME_knapsack +git clone https://github.com/scientist-softserv/adventist_knapsack $PROJECT_NAME_knapsack cd $PROJECT_NAME_knapsack -git remote rename origin upstream +git remote rename origin prime git remote add origin $NEW_REPO_URL git branch -M main git push -u origin main ``` -### Fork on Github +#### Fork on Github If you choose to fork Knapsack, be aware that this will impact how you manage pull requests via Github. Namely as you submit PRs on your Fork, the UI might default to applying that to the fork's origin (e.g. Knapsack upstream). +To ease synchronization of your Knapsack and Knapsack “prime”, consider adding knapsack prime as a remote: + +```bash +cd $PROJECT_NAME_knapsack +git remote add prime https://github.com/samvera-labs/hyku_knapsack +``` + +### Hyku and HykuKnapsack + +You run your Hyku application by way of the HykuKnapsack. As mentioned, the HykuKnapsack contains your application's relevant information for running an instance of Hyku. A newly cloned knapsack will have an empty `./hyrax-webapp` directory. That is where the Hyku application will exist. The version of Hyku is managed via a [Git submodule](https://git-scm.com/docs/git-submodule). + +To bring that application into your knapsack, you will need to initialize the Hyku submodule: + +```bash +❯ git submodule init +Submodule 'hyrax-webapp' (https://github.com/samvera/hyku.git) registered for path 'hyrax-webapp' +``` + +Then update the submodule to clone the remote Hyku repository into `./hyrax-webapp`. The `KNAPSACK-SPECIFIED-HYKU-REPOSITORY-SHA` is managed within the Hyku Knapsack (via Git submodules). + +```bash +❯ git submodule update +Cloning into '/path/to/$PROJECT_NAME_knapsack/hyrax-webapp'... +Submodule path 'hyrax-webapp': checked out '' +``` + +The configuration of the submodule can be found in the `./.gitmodules` file. During development, we've specified the submodule's branch (via `git submodule set-branch --branch -- ./hyrax-webapp`). + +Below is an example of our Adventist Knapsack submodule. + +``` +❯ cat .gitmodules +[submodule "hyrax-webapp"] + path = hyrax-webapp + url = https://github.com/samvera/hyku.git + branch = adventist_dev +``` + +When you want to bring down an updated version of your Hyku submodule, use the following: + +```bash +> git submodule update --remote +``` + +This will checkout the submodule to the HEAD of the specified branch. + ### Overrides -Before overriding anything, please think hard about whether what you are working on is a bug or feature that can apply to Hyku itself. If it is, please make a branch in your Hyku checkout (`./hyrax-webapp`) and do the work there. [See here](https://github.com/samvera-labs/hyku_knapsack/wiki/Hyku-Branches) for more information about working with Hyku branches in your Knapsack + +Before overriding anything, please think hard (or ask the community) about whether what you are working on is a bug or feature that can apply to Hyku itself. If it is, please make a branch in your Hyku checkout (`./hyrax-webapp`) and do the work there. [See here](https://github.com/samvera-labs/hyku_knapsack/wiki/Hyku-Branches) for more information about working with Hyku branches in your Knapsack Adding decorators to override features is fairly simple. We do recommend some best practices [found here](https://github.com/samvera-labs/hyku_knapsack/wiki/Decorators-and-Overrides) @@ -44,9 +131,41 @@ Theme files (views, css, etc) can be added in the the Knapsack. We recommend add ### Gems -It can be useful to add additional gems to the bundle. This can be done w/o editing Hyku by adding them as dependencies to `hyku_knapsack.gemspec` +It can be useful to add additional gems to the bundle. This can be done w/o editing Hyku by adding them to the [./bundler.d/example.rb](./bundler.d/example.rb]. [See the bundler-inject documentation for more details] on overriding and adding gems. + +## Converting a Fork of Hyku Prime to a Knapsack + +Prior to Hyku Knapsack, organizations would likely clone [Hyku](https://github.com/samvera/hyku) and begin changing the code to reflect their specific needs. The result was that the clone would often drift away from Samvera Hyku version. This drift created challenges in reconciling what you had changed locally as well as how you could easily contribute some of your changes upstream to Samvera's Hyku. + +With Hyku Knapsack, the goal is three-fold: + +1. To isolate the upstream Samvera Hyku code from your local modifications. This isolation is via the `./hyrax-webapp` submodule. +2. To provide a clear and separate space for extending/overriding Hyku functionality. +3. To provide a cleaner pathway for upgrading the underlying Hyku application; for things such as security updates, bug fixes, and upstream enhancements. + +From those goals, we can begin to see what we want in our Hyku Knapsack: + +1. Files that are not found in Hyku +2. Or files that are different from what is in Hyku (and thus will be loaded at a higher precedence) + +Assuming you're working from a fork of Samvera's Hyku repository, these are some general steps. First clone the Hyku Knapsack ([see the Usage section](#usage)). You'll also want to initialize the git submodule. Point the `./hyrax-webapp` to the branch/SHA of Samvera's Hyku that you want to use; **Note:** that version must include a `gem 'hyku_knapsack'` declaration (e.g. introduced in [7853fe5d](https://github.com/samvera/hyku/blob/7853fe5d79afd9d90cec3b9ef666681b287ef4d0/Gemfile)). + +You'll also want to have a local copy of your Hyku application. + +You can then use `bin/knapsacker` to generate a list of files that need review. That will give you a list of: + +- Files in your Hyku that are exact duplicates of upstream Hyku file (prefix with `=`) +- Files that are in your Hyku but not in upstream Hyku (prefixed with `+`) +- Files that are changed in your Hyku relative to upstream Hyku (prefix with `Δ`) + +You can pipe that output into a file and begin working on reviewing and moving files into the Knapsack. This is not an easy to automate task, after all we're paying down considerable tech debt. + +Once you've moved over the files, you'll want to boot up your Knapsack and then work through your test plan. + +The `bin/knapsacker` is general purpose. I have used it to compare one non-Knapsack Hyku instance against Samvera's Hyku. I have also used it to compare a Knapsack's file against it's submodule Hyku instance. ## Installation + If not using a current version, add this line to Hyku's Gemfile: ```ruby @@ -59,7 +178,9 @@ $ bundle ``` ## Contributing + Contribution directions go here. ## License -The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). + +The gem is available as open source under the terms of the [Apache 2.0](https://opensource.org/license/apache-2-0/). diff --git a/bin/knapsacker b/bin/knapsacker new file mode 100755 index 0000000..2617e7c --- /dev/null +++ b/bin/knapsacker @@ -0,0 +1,126 @@ +#!/usr/bin/env ruby -wU + +# The purpose of this script is to quickly assess which files should: +# +# - be removed (e.g. duplicate in Knapsack and Hyku) +# - be reviewed (e.g. differences between Knapsack and Hyku) +# - kept outright (e.g. in Knapsack but not Hyku) + +require 'optparse' +config = { yours: './', upstream: './hyrax-webapp', patterns_to_check: ["spec/**/*.*", "app/**/*.*", "lib/**/*.*"] } + +command_name = File.basename(__FILE__) + + +nlp = new_line_padding = " " * 37 +optparse = OptionParser.new do |options| + # This banner is the first line of your help documentation. + options.set_banner "Usage: #{command_name} [options]\n\n" \ + "Knapsacker - A command line tool for assisting on moving from Hyku towards\n Knapsack.\n\n" + + options.on('-u PATH', '--upstream', String, "The file path that contains the upstream\n#{nlp}repository. Not your Hyku application.\n#{nlp}Default: #{config[:upstream]}") do |upstream| + config[:upstream] = upstream + end + + options.on('-y PATH', '--yours', String, "The file path to your application\n#{nlp}(e.g. what you forked from Samvera Hyku or your Knapsack).\n#{nlp}Default: #{config[:yours]}") do |yours| + config[:yours] = yours + end + + options.on_tail('-h', '--help', "You're looking at it!") do + warn options + exit 1 + end +end + +begin + optparse.parse! + mandatory = %i[yours upstream] + missing = mandatory.select { |param| config[param].nil? } + raise OptionParser::MissingArgument, missing.join(', ') unless missing.empty? +rescue OptionParser::InvalidOption, OptionParser::MissingArgument + warn "\e[0m\e[1m\e[31m#{$!}\e[0m\n" + warn optparse + exit +end + +require 'fileutils' + +in_yours_but_not_in_upstream = [] +duplicates = [] +changed_in_yours = [] + +yours = config.fetch(:yours) +upstream = config.fetch(:upstream) +dir_glob_patterns_to_check = config.fetch(:patterns_to_check) + +unless File.exist?(File.join(yours, "Gemfile")) + $stderr.puts "ERROR: Expected \"your\" hyku not found at #{yours}" + exit!(2) +end + +unless File.exist?(File.join(upstream, "Gemfile")) + $stderr.puts "ERROR: Expected \"upstream\" hyku not found at #{upstream}" + exit!(3) +end + +# TODO: This is not generally working. +dir_glob_patterns_to_check.each do |pattern| + Dir.glob(File.join(yours, pattern)).each do |your_path| + path = your_path.sub(File.join(yours, '/'), '') + upstream_path = File.join(upstream, path) + if File.exist?(upstream_path) + results = `diff #{your_path} #{upstream_path}`.strip + if results.empty? + duplicates << path + else + changed_in_yours << path + end + else + in_yours_but_not_in_upstream << path + end + end +end + + +puts "-"*72 +puts "Knapsacker run context:" +puts "-"*72 +puts "- Working Directory: #{FileUtils.pwd}" +puts "- Your Dir: #{yours}" +puts "- Upstream Dir: #{upstream}" +puts "- Patterns to Check:" +config.fetch(:patterns_to_check).each do |pattern| + puts " - #{pattern}" +end +puts "" + +puts "------------------------------------------------------------------" +puts "Files in \"yours\" that are exact duplicates of \"upstream\" files" +puts "They are prefixed with a `='" +puts "------------------------------------------------------------------" +duplicates.each do |path| + puts "= #{path}" + if ENV['RM_DUPS'] + File.unlink(path) + end +end + +puts "" + +puts "----------------------------------------------------" +puts "Files that are in \"yours\" but not in \"upstream\" " +puts "They are prefixed with a `+'" +puts "----------------------------------------------------" +in_yours_but_not_in_upstream.each do |path| + puts "+ #{path}" +end + +puts "" + +puts "-------------------------------------------------------------" +puts "Files that are changed in \"yours\" relative to \"upstream\"" +puts "They are prefixed with a `Δ'" +puts "-------------------------------------------------------------" +changed_in_yours.each do |path| + puts "Δ #{path}" +end