Skip to content

Commit

Permalink
chore: replaces action steps with xtask steps
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Jun 3, 2021
1 parent aa65dad commit 0306648
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 81 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,5 @@ jobs:
restore-keys: |
linux-stable-cargo-index-
- name: Check formatting
run: cargo fmt --all -- --check

- name: Check idiomatic code (composition-js)
run: cargo clippy --all -- -D warnings

- name: Check idiomatic code (no-composition)
run: cargo clippy --all --no-default-features -- -D warnings
- name: Lint
run: cargo xtask lint --verbose
84 changes: 48 additions & 36 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ jobs:
- build: linux-gnu
os: ubuntu-16.04
rust: stable
target: ${{ env.LINUX_GNU_TARGET }}
- build: linux-musl
os: ubuntu-latest
rust: stable
target: ${{ env.LINUX_MUSL_TARGET }}
- build: macos
os: macos-latest
rust: stable
target: ${{ env.MACOS_TARGET }}
- build: windows
os: windows-latest
rust: stable
target: ${{ env.WINDOWS_TARGET }}

outputs:
version: ${{ steps.get_version.outputs.version }}
Expand Down Expand Up @@ -79,34 +83,14 @@ jobs:
sudo apt update
sudo apt install musl-tools
- name: Build (GNU Linux)
if: matrix.build == 'linux-gnu'
run: |
rustup target add ${{ env.LINUX_GNU_TARGET }}
cargo build --release --target ${{ env.LINUX_GNU_TARGET }}
env:
OPENSSL_STATIC: 1
- name: Install Rust toolchain
run: rustup target add ${{ matrix.target }}

- name: Build (MUSL Linux)
if: matrix.build == 'linux-musl'
run: |
rustup target add ${{ env.LINUX_MUSL_TARGET }}
cargo build --release --no-default-features --target ${{ env.LINUX_MUSL_TARGET }}
env:
OPENSSL_STATIC: 1 # statically link OpenSSL

- name: Build (MacOS)
if: matrix.build == 'macos'
run: cargo build --release
env:
OPENSSL_DIR: /usr/local/opt/openssl@1.1 # don't use system install of LibreSSL
OPENSSL_STATIC: 1 # statically link OpenSSL

- name: Build (Windows)
if: matrix.build == 'windows'
run: cargo build --release
env:
RUSTFLAGS: -Ctarget-feature=+crt-static # fully static build
- name: Test
run: cargo xtask test --verbose

- name: Build
run: cargo xtask dist --verbose --target ${{ matrix.target }}

- name: Populate artifact directory
shell: bash
Expand Down Expand Up @@ -276,19 +260,49 @@ jobs:
- name: Unzip binaries
shell: bash
run: |
tar -xzvf ./linux/${{ env.RELEASE_BIN }}-${{ needs.build.outputs.version }}-${{ env.LINUX_GNU_TARGET }}.tar.gz && mv ./dist/${{ env.RELEASE_BIN }} ./linux-gnu-cli && rm -rf dist
tar -xzvf ./linux/${{ env.RELEASE_BIN }}-${{ needs.build.outputs.version }}-${{ env.LINUX_MUSL_TARGET }}.tar.gz && mv ./dist/${{ env.RELEASE_BIN }} ./linux-musl-cli && rm -rf dist
tar -xzvf ./linux-gnu/${{ env.RELEASE_BIN }}-${{ needs.build.outputs.version }}-${{ env.LINUX_GNU_TARGET }}.tar.gz && mv ./dist/${{ env.RELEASE_BIN }} ./linux-gnu-cli && rm -rf dist
tar -xzvf ./linux-musl/${{ env.RELEASE_BIN }}-${{ needs.build.outputs.version }}-${{ env.LINUX_MUSL_TARGET }}.tar.gz && mv ./dist/${{ env.RELEASE_BIN }} ./linux-musl-cli && rm -rf dist
tar -xzvf ./windows/${{ env.RELEASE_BIN }}-${{ needs.build.outputs.version }}-${{ env.WINDOWS_TARGET }}.tar.gz && mv ./dist/${{ env.RELEASE_BIN }}.exe ./windows-cli.exe && rm -rf dist
tar -xzvf ./macos/${{ env.RELEASE_BIN }}-${{ needs.build.outputs.version }}-${{ env.MACOS_TARGET }}.tar.gz && mv ./dist/${{ env.RELEASE_BIN }} ./macos-cli && rm -rf dist
- name: Hash binaries
id: get_shas
shell: bash
run: |
echo ::set-output name=linux-gnu-sha::"$(sha256sum -b linux-gnu-cli | cut -d ' ' -f1)"
echo ::set-output name=linux-musl-sha::"$(sha256sum -b linux-musl-cli | cut -d ' ' -f1)"
echo ::set-output name=windows-sha::"$(sha256sum -b windows-cli.exe | cut -d ' ' -f1)"
echo ::set-output name=macos-sha::"$(sha256sum -b macos-cli | cut -d ' ' -f1)"
LINUX_GNU_SHA="$(sha256sum -b linux-gnu-cli | cut -d ' ' -f1)"
LINUX_MUSL_SHA="$(sha256sum -b linux-musl-cli | cut -d ' ' -f1)"
WINDOWS_SHA="$(sha256sum -b windows-cli.exe | cut -d ' ' -f1)"
MACOS_SHA="$(sha256sum -b macos-cli | cut -d ' ' -f1)"
failed=0
if [ ${#LINUX_GNU_SHA} -ne 64 ]; then
((failed=$failed+1))
echo "::debug::\$LINUX_GNU_SHA has not been computed."
fi
if [ ${#LINUX_MUSL_SHA} -ne 64 ]; then
((failed=$failed+1))
echo "::debug::\$LINUX_MUSL_SHA has not been computed."
fi
if [ ${#WINDOWS_SHA} -ne 64 ]; then
((failed=$failed+1))
echo "::debug::\$WINDOWS_SHA has not been computed."
fi
if [ ${#MACOS_SHA} -ne 64 ]; then
((failed=$failed+1))
echo "::debug::\$MACOS_SHA has not been computed."
fi
if [ "$failed" -gt 0 ]; then
echo "::debug::Failed to compute $failed checksum(s)."
exit 1
fi
echo ::set-output name=linux-gnu-sha::"$LINUX_GNU_SHA"
echo ::set-output name=linux-musl-sha::"$LINUX_MUSL_SHA"
echo ::set-output name=windows-sha::"$WINDOWS_SHA"
echo ::set-output name=macos-sha::"$MACOS_SHA"
- name: Create Release
id: create_release
Expand All @@ -300,9 +314,7 @@ jobs:
release_name: ${{ needs.build.outputs.version }}
prerelease: ${{ env.is-prerelease }}
body: |
<!---
paste the changelog entry here!
-->
<!-- changelog -->
---
This release was automatically created by [Github Actions](./.github/workflows/release.yml).
Expand Down
25 changes: 9 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
name: Tests

on: [push]
on:
push:
# Tests are run in the release job on tag pushes -
# We don't need to run them twice.
tags-ignore:
- "v*"

jobs:
test:
name: Test

runs-on: ${{ matrix.os }}
continue-on-error: ${{ contains(matrix.build, 'nightly') }}
strategy:
fail-fast: false
matrix:
build:
[
Expand Down Expand Up @@ -91,19 +98,5 @@ jobs:
sudo apt update
sudo apt install musl-tools
# Test with `rover supergraph compose`
- name: Run Tests
if: (!startsWith(matrix.build, 'linux-musl-'))
run: |
cargo test --workspace --locked --target ${{ matrix.target }}
env:
RUST_BACKTRACE: 1


# Test without `rover supergraph compose`
- name: Run Tests
if: startsWith(matrix.build, 'linux-musl-')
run: |
cargo test --workspace --locked --target ${{ matrix.target }} --no-default-features
env:
RUST_BACKTRACE: 1
run: cargo xtask test --verbose --target ${{ matrix.target }}
68 changes: 53 additions & 15 deletions crates/xtask/src/commands/cargo/runner.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use anyhow::Result;
use std::{collections::HashMap, str::FromStr};

use anyhow::{anyhow, Result};
use camino::Utf8PathBuf;

use crate::commands::Target;
Expand All @@ -25,7 +27,28 @@ impl CargoRunner {
if !target.composition_js() {
args.push("--no-default-features");
}
self.cargo_exec(&args)?;
let mut env = HashMap::new();
match target {
Target::GnuLinux | Target::MuslLinux => {
env.insert("OPENSSL_STATIC".to_string(), "1".to_string());
}
Target::MacOS => {
let openssl_path = "/usr/local/opt/openssl@1.1".to_string();
if Utf8PathBuf::from_str(&openssl_path)?.exists() {
env.insert("OPENSSL_DIR".to_string(), openssl_path);
} else {
return Err(anyhow!("OpenSSL v1.1 is not installed. Please install with `brew install openssl@1.1`"));
}
env.insert("OPENSSL_STATIC".to_string(), "1".to_string());
}
Target::Windows => {
env.insert(
"RUSTFLAGS".to_string(),
"-Ctarget-feature=+crt-static".to_string(),
);
}
}
self.cargo_exec(&args, Some(env))?;
Ok(self
.rover_package_directory
.join("target")
Expand All @@ -35,16 +58,19 @@ impl CargoRunner {
}

pub(crate) fn lint(&self) -> Result<()> {
self.cargo_exec(&["fmt", "--all", "--", "--check"])?;
self.cargo_exec(&["clippy", "--all", "--", "-D", "warnings"])?;
self.cargo_exec(&[
"clippy",
"--all",
"--no-default-features",
"--",
"-D",
"warnings",
])?;
self.cargo_exec(&["fmt", "--all", "--", "--check"], None)?;
self.cargo_exec(&["clippy", "--all", "--", "-D", "warnings"], None)?;
self.cargo_exec(
&[
"clippy",
"--all",
"--no-default-features",
"--",
"-D",
"warnings",
],
None,
)?;
Ok(())
}

Expand All @@ -55,12 +81,24 @@ impl CargoRunner {
if !target.composition_js() {
args.push("--no-default-features");
}
self.cargo_exec(&args)?;
let mut env = HashMap::new();
env.insert("RUST_BACKTRACE".to_string(), "1".to_string());
self.cargo_exec(&args, Some(env))?;

Ok(())
}

fn cargo_exec(&self, args: &[&str]) -> Result<CommandOutput> {
utils::exec("cargo", args, &self.rover_package_directory, self.verbose)
fn cargo_exec(
&self,
args: &[&str],
env: Option<HashMap<String, String>>,
) -> Result<CommandOutput> {
utils::exec(
"cargo",
args,
&self.rover_package_directory,
self.verbose,
env,
)
}
}
8 changes: 7 additions & 1 deletion crates/xtask/src/commands/dist/strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ impl StripRunner {
pub(crate) fn run(&self) -> Result<()> {
let project_root = utils::project_root()?;
let rover_executable = self.rover_executable.to_string();
utils::exec("strip", &[&rover_executable], &project_root, self.verbose)?;
utils::exec(
"strip",
&[&rover_executable],
&project_root,
self.verbose,
None,
)?;
Ok(())
}
}
8 changes: 7 additions & 1 deletion crates/xtask/src/commands/prep/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ impl NpmInstaller {
}

fn npm_exec(&self, args: &[&str]) -> Result<CommandOutput> {
utils::exec("npm", args, &self.rover_package_directory, self.verbose)
utils::exec(
"npm",
args,
&self.rover_package_directory,
self.verbose,
None,
)
}
}

Expand Down
16 changes: 12 additions & 4 deletions crates/xtask/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use cargo_metadata::MetadataCommand;
use lazy_static::lazy_static;

use std::{
collections::HashMap,
convert::TryFrom,
env,
process::{Command, Output, Stdio},
Expand Down Expand Up @@ -51,6 +52,7 @@ pub(crate) fn exec(
args: &[&str],
directory: &Utf8PathBuf,
verbose: bool,
env: Option<HashMap<String, String>>,
) -> Result<CommandOutput> {
if Command::new(command_name)
.arg("--version")
Expand All @@ -65,10 +67,16 @@ pub(crate) fn exec(
}
let full_command = format!("`{} {}`", command_name, args.join(" "));
info(&format!("running {}", &full_command));
let output = Command::new(command_name)
.current_dir(directory)
.args(args)
.output()?;
let mut command = Command::new(command_name);
command.current_dir(directory).args(args);

if let Some(env) = env {
for (key, value) in env {
command.env(&key, &value);
}
}

let output = command.output()?;
let command_was_successful = output.status.success();
let stdout = str::from_utf8(&output.stdout)
.context("Command's stdout was not valid UTF-8.")?
Expand Down

0 comments on commit 0306648

Please sign in to comment.