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

GH actions #200

Merged
merged 5 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: ci
on: [push, pull_request]
jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt
- uses: Swatinem/rust-cache@v1
- run: ./ci/fmt
shell: bash

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy
- uses: Swatinem/rust-cache@v1
- run: ./ci/lint
shell: bash

docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- uses: Swatinem/rust-cache@v1
- run: ./ci/docs
shell: bash

cargo-deny:
runs-on: ubuntu-latest
strategy:
matrix:
checks:
- advisories
- bans licenses sources
continue-on-error: ${{ matrix.checks == 'advisories' }}
steps:
- uses: actions/checkout@v2
- uses: EmbarkStudios/cargo-deny-action@v1
with:
command: check ${{ matrix.checks }}

linux:
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable
- nightly
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
- uses: Swatinem/rust-cache@v1
- run: ./ci/gh/build-test
shell: bash

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- uses: Swatinem/rust-cache@v1
- run: ./ci/gh/build-test
shell: bash

windows:
runs-on: windows-latest
continue-on-error: true
permissions: write-all
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- uses: Swatinem/rust-cache@v1
- run: ./ci/gh/build-test
shell: bash
8 changes: 8 additions & 0 deletions ci/advisory
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -eoux pipefail

cargo deny --version
cargo deny check advisories
cargo deny check licenses
cargo deny check bans
cargo deny check sources
5 changes: 5 additions & 0 deletions ci/build-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eoux pipefail

cargo build --workspace
GIT_FIXTURES=1 cargo test --workspace --features serialize
5 changes: 5 additions & 0 deletions ci/docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eoux pipefail

RUSTDOCFLAGS="-D rustdoc::broken-intra-doc-links -D warnings" \
cargo doc --no-deps --workspace --document-private-items
4 changes: 4 additions & 0 deletions ci/fmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -eoux pipefail

cargo +nightly fmt -- --check
5 changes: 5 additions & 0 deletions ci/gh/build-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eoux pipefail

cargo build --workspace
GIT_FIXTURES=1 cargo test --workspace --features serialize --features gh-actions
4 changes: 4 additions & 0 deletions ci/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -eoux pipefail

cargo clippy --all-targets -- -D warnings
4 changes: 4 additions & 0 deletions ci/nix/fmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -eoux pipefail

cargo fmt -- --check
8 changes: 8 additions & 0 deletions ci/nix/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -eou pipefail

./ci/nix/fmt
./ci/lint
./ci/build-test
./ci/docs
./ci/advisory
36 changes: 5 additions & 31 deletions ci/run
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
#!/usr/bin/env bash
set -eou pipefail

echo '--- Formatting'
cargo fmt -- --check

echo '--- Clippy'
cargo clippy --all-targets --all-features -- -D warnings

if [[ "${CI:-false}" = "true" ]]
then
sed -i -e 's|db-path.*|db-path = "/cache/cargo/advisory-db"|' deny.toml
fi

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

echo '--- deny: Licenses'
cargo deny check licenses

echo '--- deny: Bans'
cargo deny check bans

echo '--- deny: Sources'
cargo deny check sources

echo '--- Build'
cargo build --verbose --workspace --all-features

echo '--- Build & Test'
GIT_FIXTURES=1 cargo test --workspace --all-features

echo '--- Docs'
cargo doc --no-deps
./ci/fmt
./ci/lint
./ci/build-test
./ci/docs
./ci/advisory
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# The path where the advisory database is cloned/fetched into
db-path = "~/cargo/advisory-db"
# The url of the advisory database to use
db-url = "https://github.com/rustsec/advisory-db"
db-urls = [ "https://github.com/rustsec/advisory-db" ]
# The lint level for security vulnerabilities
vulnerability = "deny"
# The lint level for unmaintained crates
Expand Down
6 changes: 6 additions & 0 deletions surf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ include = [

[features]
serialize = ["serde"]
# NOTE: testing `test_submodule_failure` on GH actions
# is painful since it uses this specific repo and expects
# certain branches to be setup. So we use this feature flag
# to ignore the test on CI.
gh-actions = []

[dependencies]
either = "1.5"
Expand All @@ -38,6 +43,7 @@ criterion = "0.3"
serde_json = "1"

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

Expand Down
13 changes: 9 additions & 4 deletions surf/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::{
path::{Path, PathBuf},
};

use anyhow::Context as _;
use flate2::read::GzDecoder;
use tar::Archive;

Expand Down Expand Up @@ -62,15 +63,19 @@ fn main() {
println!("cargo:rerun-if-changed={}", git_platinum_tarball);
}

fn unpack(archive_path: impl AsRef<Path>, target: impl AsRef<Path>) -> Result<(), std::io::Error> {
fn unpack(archive_path: impl AsRef<Path>, target: impl AsRef<Path>) -> anyhow::Result<()> {
let content = target.as_ref().join("git-platinum");
if content.exists() {
fs::remove_dir_all(content)?;
fs::remove_dir_all(content).context("attempting to remove git-platinum")?;
}
let tar_gz = File::open(archive_path.as_ref())?;
let archive_path = archive_path.as_ref();
let tar_gz = File::open(archive_path).context(format!(
"attempting to open file: {}",
archive_path.display()
))?;
let tar = GzDecoder::new(tar_gz);
let mut archive = Archive::new(tar);
archive.unpack(target)?;
archive.unpack(target).context("attempting to unpack")?;

Ok(())
}
2 changes: 2 additions & 0 deletions surf/src/vcs/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ impl<'a> Browser<'a> {
mod tests {
use super::*;

#[cfg(not(feature = "gh-actions"))]
#[test]
// An issue with submodules, see: https://github.com/radicle-dev/radicle-surf/issues/54
fn test_submodule_failure() {
Expand Down Expand Up @@ -1488,6 +1489,7 @@ mod tests {
}

#[test]
#[cfg(not(windows))]
fn can_get_last_commit_for_special_filenames() {
let repo = Repository::new("./data/git-platinum")
.expect("Could not retrieve ./data/git-platinum as git repository");
Expand Down