From 29a345f99fdf68d272360e7df3a3dcbd5ad46328 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Mon, 12 Dec 2022 09:27:43 -0800 Subject: [PATCH] Curl on ci (#110) * Perform sudo in harmonic * Remove sudo in scripts * A bit more tweaking... * Yay unix * Use curl sh on ci * Preserve environments we require * Fix the yamls * Better explain a run step * Preserve GITHUB_PATH too * Correct trace * Include install-nix.sh in artifacts * Remove unused vars * Use /nix/harmonic for uninstall * Only pass --preserve-env if required * Wait for python server to start * Use a sudo uninstall * Pass verbosity correctly * Pass no-confirm by env * Pass no-confirm by env redux * Hahaha very funny yaml * handle env in no-confirm * Preserve env on ci * Mac stuff --- .github/workflows/ci.yml | 99 ++++++++++++++++++++++++--------- nix-install.sh | 3 + src/cli/arg/instrumentation.rs | 4 +- src/cli/subcommand/install.rs | 2 + src/cli/subcommand/uninstall.rs | 2 + 5 files changed, 82 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 430410c..944af85 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,14 @@ on: push: branches: [main] +env: + NIX_INSTALL_FORCE_ALLOW_HTTP: "1" + NIX_INSTALL_UPDATE_ROOT: "http://0.0.0.0:8000" + RUST_BACKTRACE: "full" + HARMONIC_VERBOSITY: "2" + HARMONIC_NO_CONFIRM: "true" + HARMONIC_LOGGER: "pretty" + jobs: lints: name: Lints @@ -29,6 +37,12 @@ jobs: run: nix develop --store ~/.ci-store --command check-nixpkgs-fmt - name: Check EditorConfig conformance run: nix develop --store ~/.ci-store --command check-editorconfig + - name: Create artifact for `nix-install.sh` + uses: actions/upload-artifact@v3 + with: + name: nix-install + path: | + nix-install.sh build-x86_64-linux: name: Build x86_64 Linux @@ -53,7 +67,7 @@ jobs: run: | RESULT=$(nix eval --raw --store ~/.ci-store --print-build-logs .#packages.x86_64-linux.harmonicStatic --apply "x: \"$HOME/.ci-store\${x}\"") cp $RESULT/bin/harmonic harmonic - - name: Create artifact for x86_64-linux harmonicStatic + - name: Create artifact for x86_64-linux harmonic uses: actions/upload-artifact@v3 with: name: harmonic-x86_64-linux @@ -63,23 +77,34 @@ jobs: run-x86_64-linux: name: Run x86_64 Linux runs-on: ubuntu-22.04 - needs: build-x86_64-linux + needs: [build-x86_64-linux, lints] steps: - run: sudo apt install fish zsh - uses: actions/download-artifact@v3 with: name: harmonic-x86_64-linux - - name: Set executable - run: chmod +x ./harmonic + - uses: actions/download-artifact@v3 + with: + name: nix-install + - name: Move & set executable + run: | + chmod +x ./harmonic + mv harmonic harmonic-x86_64-linux - name: Initial install - run: GITHUB_PATH=$GITHUB_PATH RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic install linux-multi --extra-conf "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" --no-confirm + run: | + python -m http.server --bind 0.0.0.0 8000 & + timeout 20 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/localhost/8000; do echo "Waiting for server..."; sleep 1; done' + curl -L http://0.0.0.0:8000/nix-install.sh | sh -s -- install linux-multi --extra-conf "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" - name: Initial uninstall (without a `nix run` first) - run: GITHUB_PATH=$GITHUB_PATH RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic uninstall --no-confirm + run: sudo -E /nix/harmonic uninstall - name: Repeated install - run: GITHUB_PATH=$GITHUB_PATH RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic install linux-multi --extra-conf "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" --no-confirm + run: | + python -m http.server --bind 0.0.0.0 8000 & + timeout 20 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/localhost/8000; do echo "Waiting for server..."; sleep 1; done' + curl -L http://0.0.0.0:8000/nix-install.sh | sh -s -- install linux-multi --extra-conf "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" - name: echo $PATH run: echo $PATH - - name: Test `nix` + - name: Test `nix` with `$GITHUB_PATH` if: success() || failure() run: nix run nixpkgs#fortune - name: Test bash @@ -99,19 +124,24 @@ jobs: if: success() || failure() shell: fish --login {0} - name: Repeated uninstall - run: GITHUB_PATH=$GITHUB_PATH RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic uninstall --no-confirm + run: sudo -E /nix/harmonic uninstall run-steam-deck: name: Run Steam Deck (mock) runs-on: ubuntu-22.04 - needs: build-x86_64-linux + needs: [build-x86_64-linux, lints] steps: - run: sudo apt install fish zsh - uses: actions/download-artifact@v3 with: name: harmonic-x86_64-linux - - name: Set executable - run: chmod +x ./harmonic + - uses: actions/download-artifact@v3 + with: + name: nix-install + - name: Move & set executable + run: | + chmod +x ./harmonic + mv harmonic harmonic-x86_64-linux - name: Make the CI look like a steam deck run: | mkdir -p ~/bin @@ -119,14 +149,20 @@ jobs: sudo chmod +x /bin/steamos-readonly sudo useradd -m deck - name: Initial install - run: GITHUB_PATH=$GITHUB_PATH PATH=$PATH:$HOME/bin RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic install steam-deck --persistence `pwd`/ci-test-nix --extra-conf "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" --no-confirm + run: | + python -m http.server --bind 0.0.0.0 8000 & + timeout 20 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/localhost/8000; do echo "Waiting for server..."; sleep 1; done' + curl -L http://0.0.0.0:8000/nix-install.sh | sh -s -- install steam-deck --persistence `pwd`/ci-test-nix --extra-conf "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" - name: Initial uninstall (without a `nix run` first) - run: GITHUB_PATH=$GITHUB_PATH PATH=$PATH:$HOME/bin RUST_LOG=harmonic=trace RUST_BACKTRACE=full /nix/harmonic uninstall --no-confirm + run: sudo -E /nix/harmonic uninstall - name: Repeated install - run: GITHUB_PATH=$GITHUB_PATH PATH=$PATH:$HOME/bin RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic install steam-deck --persistence `pwd`/ci-test-nix --extra-conf "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" --no-confirm + run: | + python -m http.server --bind 0.0.0.0 8000 & + timeout 20 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/localhost/8000; do echo "Waiting for server..."; sleep 1; done' + curl -L http://0.0.0.0:8000/nix-install.sh | sh -s -- install steam-deck --persistence `pwd`/ci-test-nix --extra-conf "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" - name: echo $PATH run: echo $PATH - - name: Test `nix` + - name: Test `nix` with `$GITHUB_PATH` if: success() || failure() run: nix run nixpkgs#fortune - name: Test bash @@ -146,7 +182,7 @@ jobs: if: success() || failure() shell: fish --login {0} - name: Repeated uninstall - run: GITHUB_PATH=$GITHUB_PATH PATH=$PATH:$HOME/bin RUST_LOG=harmonic=trace RUST_BACKTRACE=full /nix/harmonic uninstall --no-confirm + run: sudo -E /nix/harmonic uninstall build-x86_64-darwin: name: Build x86_64 Darwin @@ -170,23 +206,34 @@ jobs: run-x86_64-darwin: name: Run x86_64 Darwin runs-on: macos-12 - needs: build-x86_64-darwin + needs: [build-x86_64-darwin, lints] steps: - - run: brew install fish + - run: brew install fish coreutils - uses: actions/download-artifact@v3 with: name: harmonic-x86_64-darwin - - name: Set executable - run: chmod +x ./harmonic + - uses: actions/download-artifact@v3 + with: + name: nix-install + - name: Move & set executable + run: | + chmod +x ./harmonic + mv harmonic harmonic-x86_64-darwin - name: Initial install - run: GITHUB_PATH=$GITHUB_PATH RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic install darwin-multi --extra-conf "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" --no-confirm + run: | + python3 -m http.server --bind 0.0.0.0 8000 & + gtimeout 20 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/localhost/8000; do echo "Waiting for server..."; sleep 1; done' + curl -L http://0.0.0.0:8000/nix-install.sh | sh -s -- install darwin-multi --extra-conf "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" - name: Initial uninstall (without a `nix run` first) - run: GITHUB_PATH=$GITHUB_PATH RUST_LOG=harmonic=trace RUST_BACKTRACE=full /nix/harmonic uninstall --no-confirm + run: sudo -E /nix/harmonic uninstall - name: Repeated install - run: GITHUB_PATH=$GITHUB_PATH RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic install darwin-multi --extra-conf "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" --no-confirm + run: | + python -m http.server --bind 0.0.0.0 8000 & + timeout 20 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/localhost/8000; do echo "Waiting for server..."; sleep 1; done' + curl -L http://0.0.0.0:8000/nix-install.sh | sh -s -- install darwin-multi --extra-conf "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" - name: echo $PATH run: echo $PATH - - name: Test `nix` + - name: Test `nix` with `$GITHUB_PATH` if: success() || failure() run: nix run nixpkgs#fortune - name: Test bash @@ -206,5 +253,5 @@ jobs: if: success() || failure() shell: fish --login {0} - name: Repeated uninstall - run: GITHUB_PATH=$GITHUB_PATH RUST_LOG=harmonic=trace RUST_BACKTRACE=full /nix/harmonic uninstall --no-confirm + run: sudo -E /nix/harmonic uninstall \ No newline at end of file diff --git a/nix-install.sh b/nix-install.sh index 79348be..7265d04 100755 --- a/nix-install.sh +++ b/nix-install.sh @@ -77,6 +77,9 @@ main() { ;; esac done + if [ "${HARMONIC_NO_CONFIRM-}" ]; then + need_tty=no + fi if $_ansi_escapes_are_valid; then printf "\33[1minfo:\33[0m downloading installer \33[4m%s\33[0m\n" "$_url" 1>&2 diff --git a/src/cli/arg/instrumentation.rs b/src/cli/arg/instrumentation.rs index 63a507e..c95a9c0 100644 --- a/src/cli/arg/instrumentation.rs +++ b/src/cli/arg/instrumentation.rs @@ -29,10 +29,10 @@ impl std::fmt::Display for Logger { #[derive(clap::Args, Debug, Valuable)] pub struct Instrumentation { /// Enable debug logs, -vv for trace - #[clap(short = 'v', long, action = clap::ArgAction::Count, global = true)] + #[clap(short = 'v', env = "HARMONIC_VERBOSITY", long, action = clap::ArgAction::Count, global = true)] pub verbose: u8, /// Which logger to use - #[clap(long, default_value_t = Default::default(), global = true)] + #[clap(long, env = "HARMONIC_LOGGER", default_value_t = Default::default(), global = true)] pub logger: Logger, } diff --git a/src/cli/subcommand/install.rs b/src/cli/subcommand/install.rs index 686fdf4..bbeaa3c 100644 --- a/src/cli/subcommand/install.rs +++ b/src/cli/subcommand/install.rs @@ -22,6 +22,7 @@ use owo_colors::OwoColorize; pub struct Install { #[clap( long, + env = "HARMONIC_NO_CONFIRM", action(ArgAction::SetTrue), default_value = "false", global = true @@ -30,6 +31,7 @@ pub struct Install { #[clap( long, + env = "HARMONIC_EXPLAIN", action(ArgAction::SetTrue), default_value = "false", global = true diff --git a/src/cli/subcommand/uninstall.rs b/src/cli/subcommand/uninstall.rs index 28376bd..0f41fcd 100644 --- a/src/cli/subcommand/uninstall.rs +++ b/src/cli/subcommand/uninstall.rs @@ -21,6 +21,7 @@ use crate::cli::{interaction, CommandExecute}; pub struct Uninstall { #[clap( long, + env = "HARMONIC_NO_CONFIRM", action(ArgAction::SetTrue), default_value = "false", global = true @@ -28,6 +29,7 @@ pub struct Uninstall { pub no_confirm: bool, #[clap( long, + env = "HARMONIC_EXPLAIN", action(ArgAction::SetTrue), default_value = "false", global = true