Skip to content

Commit 308df53

Browse files
committed
Add documentation and license
1 parent d8cf069 commit 308df53

File tree

3 files changed

+471
-9
lines changed

3 files changed

+471
-9
lines changed

CONTRIBUTING.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Contributing
2+
3+
[Homebrew][brew] is a package manager for MacOS and Linux. It can greatly
4+
improve the user experience of installing tools or libraries on those
5+
platforms.
6+
7+
"Mainstream" packages can be added to the official Homebrew list of packages
8+
(by submitting pull requests on the [Homebrew/Core][core] repository).
9+
10+
Packages that do not fit the requirements of Homebrew-core can be provided by
11+
creating a ["tap"][taps], i.e. an additional and unofficial "Third-party"
12+
source of Homebrew packages.
13+
14+
The Haskell cardano-node itself, and consequently many tools that use the same
15+
dependencies, are not currently ["acceptable formulae"][acceptable] for
16+
[Homebrew/Core][core] so for the time being, I have created a Third-party tap:
17+
18+
<https://github.com/notunrandom/homebrew-cardano>
19+
20+
N.B. The repository must have the `homebrew-` prefix in its name. But in `brew`
21+
commands, one usually refers to this tap without the `homebrew-` prefix.
22+
23+
## Adding formulae
24+
25+
To add a formula, start by adding the tap to your local Homebrew installation
26+
(**N.B.** this clones the repository using the HTTP URL, see below for the
27+
alternative):
28+
29+
```bash
30+
brew tap notunrandom/cardano
31+
```
32+
33+
This actually clones the [notunrandom/homebrew-cardano][tap] repository into
34+
your local Homebrew installation. The path to the local git repository will be
35+
provided in the output of the previous commande, e.g.:
36+
37+
```bash
38+
==> Tapping notunrandom/cardano
39+
Cloning into '/opt/homebrew/Library/Taps/notunrandom/homebrew-cardano'...
40+
remote: Enumerating objects: 57, done.
41+
remote: Counting objects: 100% (57/57), done.
42+
remote: Compressing objects: 100% (44/44), done.
43+
remote: Total 57 (delta 15), reused 43 (delta 9), pack-reused 0 (from 0)
44+
Receiving objects: 100% (57/57), 17.00 KiB | 8.50 MiB/s, done.
45+
Resolving deltas: 100% (15/15), done.
46+
Tapped 4 formulae (20 files, 48.1KB).
47+
```
48+
49+
It is also possible to specify the URL of the tap, which is useful for example
50+
if one wishes to make changes to the repository using SSH and a key-pair rather
51+
than HTTP authentication:
52+
53+
```bash
54+
brew tap notunrandom/cardano git@github.com:notunrandom/homebrew-cardano.git
55+
```
56+
57+
Now you can `cd` to the directory and use Git as usual. It is also possible to
58+
use `brew` to find the correct directory:
59+
60+
```
61+
cd $(brew --repo notunrandom/cardano)
62+
```
63+
64+
But `brew` also provides facilities, for example to create an initial version
65+
of your new formula.
66+
67+
Identify the URL of the repository for which you want to create a formula.
68+
The URL must point to a .tar.gz (not a .zip) of the source code of a specific
69+
branch, tag or commit. Look at the `url` field in existing formulae or follow
70+
these examples:
71+
72+
- <https://github.com/IntersectMBO/cardano-node/archive/refs/tags/10.5.1.tar.gz>
73+
points to a version tag.
74+
- <https://github.com/IntersectMBO/ouroboros-consensus/archive/refs/heads/release/ouroboros-consensus-0.28.0.0.tar.gz>
75+
points to a release/version branch
76+
- <https://github.com/intersectMBO/libsodium/archive/dbb48cce5429cb6585c9034f002568964f1ce567.tar.gz>
77+
points to a commit - here brew will not be able to deduce a version so a
78+
`--set-version` flag will be needed.
79+
80+
Use `brew create --help` to see whether brew has a template for the kind of
81+
code used in the repository (e.g. it has a `--cabal` option for Haskell and a
82+
`--rust` option for Rust).
83+
84+
Use `brew create` to initialise your formula, specifying the tap, the template
85+
and the URL.
86+
87+
Here is a first example, for Moog, which is a Haskell project built with Cabal,
88+
and has version tags:
89+
90+
```bash
91+
brew create --tap notunrandom/cardano --cabal https://github.com/cardano-foundation/moog/archive/refs/tags/v0.4.1.1.tar.gz
92+
```
93+
94+
Here is a second example, for Amaru, which is a Rust project which does not yet
95+
have version tags or branches, so we will use the HEAD of main and manually
96+
specify a low version:
97+
98+
```bash
99+
brew create --tap notunrandom/cardano --rust --set-version 0.1.0.0 https://github.com/pragma-org/amaru/archive/refs/heads/main.tar.gz
100+
```
101+
102+
This will open an editor session of the generated Formula. You can keep the
103+
session open to continue editing the Formula, or close it and open the file
104+
later or with another editor.
105+
106+
Make sure you are working in a branch, and one formula at a time. So, before
107+
continuing work on the `amaru` formula:
108+
109+
```
110+
pushd $(brew --repo notunrandom/cardano)
111+
git checkout -b amaru
112+
```
113+
114+
From now on, as you work on the formula, you can commit (locally) to save your
115+
progress.
116+
117+
To adapt the generated formula to the specifics of the project, get inspiration
118+
from existing formula in the [notunrandom/cardano][tap], read the [Formula
119+
Cookbook][formula] and/or get inspiration from exiting formulae in
120+
[Homebrew/Core][core].
121+
122+
When you are ready to try it out, you must first test your formula locally
123+
using these three steps (I will use the example of the Amaru formula
124+
initialised above):
125+
126+
```
127+
HOMEBREW_NO_INSTALL_FROM_API=1 brew audit --new amaru
128+
```
129+
130+
This will analyse your formula code, it's like a linter. Fix all errors before proceeding.
131+
132+
```
133+
HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source --verbose --debug amaru
134+
```
135+
136+
This will attempt to use your Formula to build, from source, a locally
137+
installed version of the package. Again, fix all errors before proceeding. N.B.
138+
Once the installation succeeded at least once, if you want to make changes, you
139+
will need to replace `install` by `reinstall` in the above command.
140+
141+
```
142+
HOMEBREW_NO_INSTALL_FROM_API=1 brew test amaru
143+
```
144+
145+
This will test the resulting installation (using the test you should have
146+
provided in the formula).
147+
148+
Once you are satisfied that your formula is working, you can commit your new
149+
formula.
150+
151+
Important:
152+
153+
- you must work in a branch, and one formula at a time.
154+
- you must push your branch to the upstream repo so that a pull request can be
155+
created. Do not push directly to main.
156+
- you must use a pull request to submit your new or modified formula (only this
157+
way will the GitHub actions be usable)
158+
- your pull request must only concern a single formula - use a separate branch
159+
and separate pull request for each formula you add or modify.
160+
161+
For the maintainers of the tap, the last stages are done in GitHub:
162+
163+
1. Create a pull request from the pushed branch.
164+
2. Wait for the GitHub actions triggered by the pull request to complete.
165+
3. If they are all green, add the "pr-pull" label to the PR - this will
166+
automatically merge and delete the branch, create the "bottles" and put them
167+
in "Releases", add the links to the "bottles" in the formula and close the
168+
PR.
169+
170+
## Creating a tap
171+
172+
Although new Formulae can now be added to the existing
173+
[notunrandom/cardano tap][tap], the process of creating the tap is documented
174+
here for posterity or future reference.
175+
176+
Create a completely empty GitHub repository for formulae, whose name must be
177+
prefixed with "homebrew": e.g. notunrandom/homebrew-cardano
178+
179+
Then locally create a new tap, initialise git and push:
180+
181+
```
182+
brew tap-new --no-git notunrandom/homebrew-cardano
183+
pushd $(brew --repo notunrandom/cardano)
184+
git init -b main
185+
git config user.name "notunrandom"
186+
git config user.email "122674938+notunrandom@users.noreply.github.com"
187+
git add .github README.md
188+
git commit -m"Genesis"
189+
git remote add origin git@github.com:notunrandom/homebrew-cardano.git
190+
git push -u origin main
191+
```
192+
193+
Then from GitHub, add a license, then locally, pull, and create a branch:
194+
195+
```
196+
git pull
197+
```
198+
199+
This (with the `--no-git` option) is the most failsafe process, so that you can
200+
control the git init process.
201+
202+
203+
[brew]: https://brew.sh/
204+
[taps]: https://docs.brew.sh/Taps
205+
[core]: https://github.com/Homebrew/homebrew-core
206+
[acceptable]: https://docs.brew.sh/Acceptable-Formulae
207+
[tap]: https://github.com/notunrandom/homebrew-cardano
208+
[formula]: https://docs.brew.sh/Formula-Cookbook
209+

0 commit comments

Comments
 (0)