Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
data/git-platinum: use tarball file to keep track of git-platinum
Browse files Browse the repository at this point in the history
Instead of using a git submodule to keep track of git-platinum, we use a
cloned version of git-platinum that is compressed into a tarball file.
This gets uncompressed via the `build.rs` file so that it can used by
the tests. A helper script for cloning and compressing git-platinum is
provided to get new updates, while also adding custom branches for our
tests.

Signed-off-by: Tomasz Kurcz <[email protected]>
Signed-off-by: Fintan Halpenny <[email protected]>
  • Loading branch information
FintanH committed Apr 22, 2021
1 parent 16fa64d commit f238a45
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 46 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ Cargo.lock
# JetBrains IDE project files (Intellij, CLion, etc.)
.idea
*.iml

# Workdir for data generated by scripts.
/.workdir

# This is an inner git repo unpacked (if necessary) from the archive.
# Git doesn't like nested repos, and we don't really want to use submodules.
/data/git-platinum
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
[submodule "data/git-platinum"]
path = data/git-platinum
url = https://github.com/radicle-dev/git-platinum.git
branch = master
23 changes: 6 additions & 17 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,17 @@ the toolchain via the `rust-toolchain` file, and the formatting rules `.rustmt.t
For the [Nix](https://nixos.org/) inclined there is a `default.nix` file to get all the necessary
dependencies and it also uses the `rust-toolchain` file to pin to that version of Rust.

First, if you haven't already, you should set up the submodule under `data/git-platinum`. Do this by
the script:

```bash
$ ./scripts/submodule.sh
You can build the project the usual way:
```

The `build.rs` file takes care of setting up specific references for testing purposes. So to build
and test `radicle-surf` we need to run with the `GIT_FIXTURES` set. **Note** that it's only
necessary to do this once.

```bash
$ GIT_FIXTURES=1 cargo build
cargo build
```

and

```bash
$ GIT_FIXTURES=1 cargo test
To run all the tests:
```
cargo test
```

For the full list of commands that get executed on CI you can checkout the [ci/run](./ci/run) script.
For the full list of checks that get executed in CI you can checkout the [ci/run](./ci/run) script.

If any of this _isn't_ working, then let's work through it together and get it Working on Your
Machine™.
Expand Down
6 changes: 0 additions & 6 deletions ci/run
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ then
sed -i -e 's|db-path.*|db-path = "/cache/cargo/advisory-db"|' deny.toml
fi

echo '--- cleanup: Tear Down Mock Branches'
./scripts/teardown-branches.sh

echo '--- setup: Create Mock Branches'
./scripts/setup-branches.sh

echo '--- deny: Advisories'
cargo deny check advisories

Expand Down
11 changes: 11 additions & 0 deletions data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Updating [git-platinum](https://github.com/radicle-dev/git-platinum) Just `cd`
into the repo root, then run `scripts/update-git-platinum.sh`. This will update
the tarball and it's necessary to commit the change. We provide a template below
so that we can easily identify changes to `git-platinum`. Please fill in the
details that follow a comment (`#`):


data/git-platinum: # short reason for updating

# provide a longer reason for making changes to git-platinum
# as well as what has changed.
1 change: 0 additions & 1 deletion data/git-platinum
Submodule git-platinum deleted from a0dd91
Binary file added data/git-platinum.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion scripts/setup-branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ while IFS= read -r line
do
IFS=, read -a pair <<< $line
echo "Creating branch ${pair[0]}"
git submodule foreach "git update-ref ${pair[0]} ${pair[1]}"
git -C data/git-platinum/ update-ref ${pair[0]} ${pair[1]}
done < "$input"
5 changes: 0 additions & 5 deletions scripts/submodule.sh

This file was deleted.

10 changes: 0 additions & 10 deletions scripts/teardown-branches.sh

This file was deleted.

40 changes: 40 additions & 0 deletions scripts/update-git-platinum.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -euo pipefail

# Verify that the script is run from project root.
BASE=$(basename $(pwd))

if [ "${BASE}" != "radicle-surf" ]
then
echo "ERROR: this script should be run from the root of radicle-surf"
exit 1
fi

TARBALL_PATH=data/git-platinum.tgz
WORKDIR=.workdir

# Create the workdir if needed.
mkdir -p $WORKDIR

# This is here in case the last script run failed and it never cleaned up.
rm -rf $WORKDIR/git-platinum

# Clone an up-to-date version of git-platinum.
git clone https://github.com/radicle-dev/git-platinum.git $WORKDIR/git-platinum
git -C $WORKDIR/git-platinum/ checkout dev

# Add the necessary refs.
input="./data/mock-branches.txt"
while IFS= read -r line
do
IFS=, read -a pair <<< $line
echo "Creating branch ${pair[0]}"
git -C $WORKDIR/git-platinum/ update-ref ${pair[0]} ${pair[1]}
done < "$input"

# Update the archive.
tar -czf $WORKDIR/git-platinum.tgz $WORKDIR/git-platinum
mv $WORKDIR/git-platinum.tgz $TARBALL_PATH

# Clean up.
rm -rf $WORKDIR/git-platinum
4 changes: 4 additions & 0 deletions surf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ proptest = "0.9"
criterion = "0.3"
serde_json = "1"

[build-dependencies]
flate2 = "1"
tar = "0.4"

[[bench]]
name = "last_commit"
harness = false
4 changes: 2 additions & 2 deletions surf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Alongside this, we will wish to take two snapshots and view their differences.

## Contributing

To get started on contributing you can check out our [developing guide](./DEVELOPMENT.md), and also
our [LICENSE](./LICENSE) file.
To get started on contributing you can check out our [developing guide](../DEVELOPMENT.md), and also
our [LICENSE](../LICENSE) file.

## The Community

Expand Down
39 changes: 39 additions & 0 deletions surf/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This file is part of radicle-surf
// <https://github.com/radicle-dev/radicle-surf>
//
// Copyright (C) 2019-2020 The Radicle Team <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 3 or
// later as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use std::{fs::File, path::Path};

use flate2::read::GzDecoder;
use tar::Archive;

fn main() {
let git_platinum_tarball = "../data/git-platinum.tgz";
let target = "../data/";

unpack(git_platinum_tarball, target).expect("Failed to unpack git-platinum");

println!("cargo:rerun-if-changed={}", git_platinum_tarball);
}

fn unpack(archive_path: impl AsRef<Path>, target: impl AsRef<Path>) -> Result<(), std::io::Error> {
let tar_gz = File::open(archive_path.as_ref())?;
let tar = GzDecoder::new(tar_gz);
let mut archive = Archive::new(tar);
archive.unpack(target)?;

Ok(())
}

0 comments on commit f238a45

Please sign in to comment.