Skip to content

Commit

Permalink
Fix radicle-httpd tests for release instead of build from source
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez committed Jul 8, 2024
1 parent 2b491a1 commit 698ae0b
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 63 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/check-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: "20.9.0"
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
workspaces: radicle-httpd -> target
- name: Build
run: cargo build --all --release --manifest-path=./radicle-httpd/Cargo.toml
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
Expand Down
12 changes: 1 addition & 11 deletions .github/workflows/check-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
workspaces: radicle-httpd -> target
- name: Build
run: cargo build --all --release --manifest-path=./radicle-httpd/Cargo.toml
- uses: actions/setup-node@v4
with:
node-version: "20.9.0"

- name: Install dependencies
run: npm ci

Expand All @@ -38,7 +28,7 @@ jobs:
- name: Install Radicle binaries
run: |
mkdir -p tests/artifacts;
./scripts/install-binaries;
./scripts/install-binaries
- name: Run Playwright tests
run: npm run test:e2e -- --project ${{ matrix.browser }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/check-http-client-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ jobs:
run: |
mkdir -p tests/artifacts;
./scripts/install-binaries;
./scripts/install-binaries --show-path >> $GITHUB_PATH;
- run: |
npm run test:http-client:unit
7 changes: 0 additions & 7 deletions .github/workflows/check-visual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: "20.9.0"
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
workspaces: radicle-httpd -> target
- name: Build
run: cargo build --all --release --manifest-path=./radicle-httpd/Cargo.toml

- name: Install dependencies
run: npm ci
Expand Down Expand Up @@ -62,7 +56,6 @@ jobs:
run: |
mkdir -p tests/artifacts;
./scripts/install-binaries;
./scripts/install-binaries --show-path >> $GITHUB_PATH;
- name: Run Playwright tests
run: |
Expand Down
57 changes: 31 additions & 26 deletions scripts/install-binaries
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,31 @@ set -e

REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || echo "$PWD")
RELEASE=$(cat "$REPO_ROOT/tests/support/heartwood-release")
BINARY_PATH=$REPO_ROOT/tests/tmp/bin/$RELEASE
HTTPD_RELEASE=$(cat "$REPO_ROOT/tests/support/radicle-httpd-release")
BINARY_PATH=$REPO_ROOT/tests/tmp/bin
OS=$(uname)

install() {
if test -d "$BINARY_PATH/$1"; then
echo"Folder $BINARY_PATH/$1 exists already skipping download and build."
else
mkdir -p "$BINARY_PATH/$1"
case "$OS" in
Darwin)
echo Downloading "$1" from "https://files.radicle.xyz/releases$2/$1/radicle-aarch64-apple-darwin.tar.xz into /tests/tmp/bin/$1"
curl --fail -s "https://files.radicle.xyz/releases$2/$1/radicle-aarch64-apple-darwin.tar.xz" | tar -xJ --strip-components=2 -C "$BINARY_PATH/$1" "radicle-$1-aarch64-apple-darwin/bin/" || (echo "Download failed" && exit 1)
;;
Linux)
echo Downloading "$1" from "https://files.radicle.xyz/releases$2/$1/radicle-x86_64-unknown-linux-musl.tar.xz into /tests/tmp/bin/$1"
curl --fail -s "https://files.radicle.xyz/releases$2/$1/radicle-x86_64-unknown-linux-musl.tar.xz" | tar -xJ --strip-components=2 -C "$BINARY_PATH/$1" "radicle-$1-x86_64-unknown-linux-musl/bin/" || (echo "Download failed" && exit 1)
;;
*)
echo "There are no precompiled binaries for your OS: $OS, compile $1 manually and make sure it's in PATH." && exit 1
;;
esac
fi
}

show_usage() {
echo
echo "Installs binaries required for running e2e test suite."
Expand All @@ -21,8 +43,12 @@ show_usage() {

while [ $# -ne 0 ]; do
case "$1" in
--show-path | -s)
echo "$BINARY_PATH"
--show-rad-path)
echo "$BINARY_PATH/$RELEASE"
exit
;;
--show-httpd-path)
echo "$BINARY_PATH/$HTTPD_RELEASE"
exit
;;
--help | -h)
Expand All @@ -32,28 +58,7 @@ while [ $# -ne 0 ]; do
esac
done

if test -d "$BINARY_PATH"; then
echo"Folder $BINARY_PATH exists already skipping download and build."
else
mkdir -p "$BINARY_PATH"
case "$OS" in
Darwin)
echo Downloading "$RELEASE" from "https://files.radicle.xyz/releases/$RELEASE/radicle-aarch64-apple-darwin.tar.xz into /tests/tmp/bin/$RELEASE"
curl --fail -s "https://files.radicle.xyz/releases/$RELEASE/radicle-aarch64-apple-darwin.tar.xz" | tar -xJ --strip-components=2 -C "$BINARY_PATH" "radicle-$RELEASE-aarch64-apple-darwin/bin/" || (echo "Download failed" && exit 1)
;;
Linux)
echo Downloading "$RELEASE" from "https://files.radicle.xyz/releases/$RELEASE/radicle-x86_64-unknown-linux-musl.tar.xz into /tests/tmp/bin/$RELEASE"
curl --fail -s "https://files.radicle.xyz/releases/$RELEASE/radicle-x86_64-unknown-linux-musl.tar.xz" | tar -xJ --strip-components=2 -C "$BINARY_PATH" "radicle-$RELEASE-x86_64-unknown-linux-musl/bin/" || (echo "Download failed" && exit 1)
;;
*)
echo "There are no precompiled binaries for your OS: $OS, compile $RELEASE manually and make sure it's in PATH." && exit 1
;;
esac

echo Building radicle-httpd
CARGO_TERM_PROGRESS_WIDTH=80 CARGO_TERM_PROGRESS_WHEN=always cargo build --release --all --quiet --manifest-path=$REPO_ROOT/radicle-httpd/Cargo.toml
echo Copying radicle-httpd into /tests/tmp/bin/$RELEASE
cp $REPO_ROOT/radicle-httpd/target/release/radicle-httpd $BINARY_PATH
fi
install "$RELEASE" "/"
install "$HTTPD_RELEASE" "/radicle-httpd"

echo
20 changes: 18 additions & 2 deletions tests/support/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as Fs from "node:fs";
import * as Path from "node:path";
import {
assertRadInstalled,
assertBinariesInstalled,
heartwoodRelease,
radicleHttpdRelease,
removeWorkspace,
tmpDir,
} from "@tests/support/support.js";
Expand All @@ -15,9 +17,23 @@ import {
} from "@tests/support/fixtures.js";
import { createPeerManager } from "@tests/support/peerManager.js";

const heartwoodBinaryPath = Path.join(tmpDir, "bin", heartwoodRelease);
const httpdBinaryPath = Path.join(tmpDir, "bin", radicleHttpdRelease);

process.env.PATH = [
heartwoodBinaryPath,
httpdBinaryPath,
process.env.PATH,
].join(Path.delimiter);

export default async function globalSetup(): Promise<() => void> {
try {
await assertRadInstalled();
await assertBinariesInstalled("rad", heartwoodRelease, heartwoodBinaryPath);
await assertBinariesInstalled(
"radicle-httpd",
radicleHttpdRelease,
httpdBinaryPath,
);
} catch (error) {
console.error(error);
console.log("");
Expand Down
1 change: 1 addition & 0 deletions tests/support/radicle-httpd-release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.13.0
26 changes: 16 additions & 10 deletions tests/support/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,27 @@ export const heartwoodRelease = await Fs.readFile(
"utf8",
);

const binaryPath = Path.join(tmpDir, "bin", heartwoodRelease);
process.env.PATH = [binaryPath, process.env.PATH].join(Path.delimiter);
export const radicleHttpdRelease = await Fs.readFile(
`${supportDir}/radicle-httpd-release`,
"utf8",
);

// Assert that the `rad` CLI is installed and has the correct version.
export async function assertRadInstalled(): Promise<void> {
const { stdout: which } = await execa("which", ["rad"]);
if (Path.dirname(which) !== binaryPath) {
// Assert that binaries are installed and are the correct version.
export async function assertBinariesInstalled(
binary: string,
expectedVersion: string,
expectedPath: string,
): Promise<void> {
const { stdout: which } = await execa("which", [binary]);
if (Path.dirname(which) !== expectedPath) {
throw new Error(
`rad path doesn't match used rad binary: ${binaryPath} !== ${which}`,
`${binary} path doesn't match used ${binary} binary: ${expectedPath} !== ${which}`,
);
}
const { stdout: version } = await execa("rad", ["--version"]);
if (!version.includes(heartwoodRelease)) {
const { stdout: version } = await execa(binary, ["--version"]);
if (!version.includes(expectedVersion)) {
throw new Error(
`rad version ${version} does not satisfy ${heartwoodRelease}`,
`${binary} version ${version} does not satisfy ${expectedVersion}`,
);
}
}
Expand Down

0 comments on commit 698ae0b

Please sign in to comment.