-
Notifications
You must be signed in to change notification settings - Fork 0
fix: improve docker ci cache reuse #1597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4dbfd64
fix: improve docker CI cache reuse
shunkakinoki f7bf315
feat(noctalia): add DarkModeToggle widget to bar
shunkakinoki 42aa729
Merge branch 'main' into fix/docker-cache-reuse
shunkakinoki e01539b
fix: add nix-cache-warmup.sh to shell test coverage
shunkakinoki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,24 @@ else | |||||||
| echo "USER variable is already set to: $USER. Ensuring it is exported." | ||||||||
| fi | ||||||||
|
|
||||||||
| NIX_GITHUB_TOKEN="" | ||||||||
| if [ -n "${GITHUB_TOKEN:-}" ]; then | ||||||||
| NIX_GITHUB_TOKEN="$GITHUB_TOKEN" | ||||||||
| elif [ -n "${GITHUB_TOKEN_FILE:-}" ] && [ -r "$GITHUB_TOKEN_FILE" ]; then | ||||||||
| NIX_GITHUB_TOKEN=$(cat "$GITHUB_TOKEN_FILE") | ||||||||
| fi | ||||||||
|
|
||||||||
| if [ -n "$NIX_GITHUB_TOKEN" ]; then | ||||||||
| if [ -n "${NIX_CONFIG:-}" ]; then | ||||||||
| NIX_CONFIG="${NIX_CONFIG} access-tokens = github.com=$NIX_GITHUB_TOKEN" | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Preserve the newline separator here; a space can make the existing NIX_CONFIG entry and Prompt for AI agents
Suggested change
Tip: Review your code locally with the cubic CLI to iterate faster. |
||||||||
| else | ||||||||
| NIX_CONFIG="access-tokens = github.com=$NIX_GITHUB_TOKEN" | ||||||||
| fi | ||||||||
| export NIX_CONFIG | ||||||||
| echo "Configured a GitHub token for Nix fetches during this install." | ||||||||
| fi | ||||||||
| unset NIX_GITHUB_TOKEN | ||||||||
|
|
||||||||
| # Install Nix if not already installed | ||||||||
| if ! command -v nix >/dev/null 2>&1; then | ||||||||
| echo "Installing Nix..." | ||||||||
|
|
||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -e | ||
|
|
||
| repo_dir=${1:-.} | ||
| if [ "$#" -gt 0 ]; then | ||
| shift | ||
| fi | ||
|
|
||
| nix_github_token="" | ||
| if [ -n "${GITHUB_TOKEN:-}" ]; then | ||
| nix_github_token="$GITHUB_TOKEN" | ||
| elif [ -n "${GITHUB_TOKEN_FILE:-}" ] && [ -r "$GITHUB_TOKEN_FILE" ]; then | ||
| nix_github_token=$(cat "$GITHUB_TOKEN_FILE") | ||
| fi | ||
|
|
||
| if [ -n "$nix_github_token" ]; then | ||
| if [ -n "${NIX_CONFIG:-}" ]; then | ||
| NIX_CONFIG="${NIX_CONFIG} | ||
| access-tokens = github.com=$nix_github_token" | ||
| else | ||
| NIX_CONFIG="access-tokens = github.com=$nix_github_token" | ||
| fi | ||
| export NIX_CONFIG | ||
| fi | ||
| unset nix_github_token | ||
|
|
||
| if ! command -v nix >/dev/null 2>&1; then | ||
| echo "Nix unavailable; skipping cache warmup" | ||
| exit 0 | ||
| fi | ||
|
|
||
| nix flake metadata "$repo_dir" "$@" --no-write-lock-file >/dev/null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #!/usr/bin/env bash | ||
| # shellcheck disable=SC2329,SC2034,SC2016 | ||
|
|
||
| Describe 'scripts/nix-cache-warmup.sh' | ||
| SCRIPT="$PWD/scripts/nix-cache-warmup.sh" | ||
|
|
||
| Describe 'script properties' | ||
| It 'uses sh shebang' | ||
| When run bash -c "head -1 '$SCRIPT'" | ||
| The output should include '#!/bin/sh' | ||
| End | ||
|
|
||
| It 'uses strict mode' | ||
| When run bash -c "head -5 '$SCRIPT'" | ||
| The output should include 'set -e' | ||
| End | ||
| End | ||
|
|
||
| Describe 'github token handling' | ||
| It 'checks GITHUB_TOKEN env var' | ||
| When run bash -c "grep 'GITHUB_TOKEN' '$SCRIPT'" | ||
| The output should include 'GITHUB_TOKEN' | ||
| End | ||
|
|
||
| It 'checks GITHUB_TOKEN_FILE env var' | ||
| When run bash -c "grep 'GITHUB_TOKEN_FILE' '$SCRIPT'" | ||
| The output should include 'GITHUB_TOKEN_FILE' | ||
| End | ||
|
|
||
| It 'sets access-tokens in NIX_CONFIG' | ||
| When run bash -c "grep 'access-tokens' '$SCRIPT'" | ||
| The output should include 'access-tokens' | ||
| End | ||
|
|
||
| It 'unsets token variable after use' | ||
| When run bash -c "grep 'unset nix_github_token' '$SCRIPT'" | ||
| The output should include 'unset nix_github_token' | ||
| End | ||
| End | ||
|
|
||
| Describe 'nix availability check' | ||
| It 'checks if nix command exists' | ||
| When run bash -c "grep 'command -v nix' '$SCRIPT'" | ||
| The output should include 'command -v nix' | ||
| End | ||
|
|
||
| It 'skips gracefully when nix is unavailable' | ||
| When run bash -c "grep 'skipping cache warmup' '$SCRIPT'" | ||
| The output should include 'skipping cache warmup' | ||
| End | ||
| End | ||
|
|
||
| Describe 'flake metadata' | ||
| It 'runs nix flake metadata' | ||
| When run bash -c "grep 'nix flake metadata' '$SCRIPT'" | ||
| The output should include 'nix flake metadata' | ||
| End | ||
|
|
||
| It 'uses --no-write-lock-file flag' | ||
| When run bash -c "grep 'no-write-lock-file' '$SCRIPT'" | ||
| The output should include '--no-write-lock-file' | ||
| End | ||
| End | ||
|
|
||
| Describe 'repo directory argument' | ||
| It 'sets repo_dir' | ||
| When run bash -c "grep 'repo_dir=' '$SCRIPT'" | ||
| The output should include 'repo_dir=' | ||
| End | ||
| End | ||
|
|
||
| Describe 'runtime behavior' | ||
| setup_runtime() { | ||
| TEMP_DIR=$(mktemp -d) | ||
| cp -f "$SCRIPT" "$TEMP_DIR/nix-cache-warmup.sh" | ||
| chmod +x "$TEMP_DIR/nix-cache-warmup.sh" | ||
| mkdir -p "$TEMP_DIR/bin" | ||
| } | ||
|
|
||
| cleanup_runtime() { | ||
| rm -rf "$TEMP_DIR" | ||
| } | ||
|
|
||
| Before 'setup_runtime' | ||
| After 'cleanup_runtime' | ||
|
|
||
| It 'exits successfully when nix is unavailable' | ||
| When run env PATH="$TEMP_DIR/bin" /bin/sh "$TEMP_DIR/nix-cache-warmup.sh" "$TEMP_DIR" | ||
| The status should be success | ||
| The output should include 'Nix unavailable; skipping cache warmup' | ||
| End | ||
|
|
||
| It 'invokes nix flake metadata with tokenized NIX_CONFIG' | ||
| cat >"$TEMP_DIR/bin/nix" <<'EOF' | ||
| #!/bin/sh | ||
| echo "ARGS:$*" >>"$TMPDIR/nix.log" | ||
| echo "NIX_CONFIG:$NIX_CONFIG" >>"$TMPDIR/nix.log" | ||
| EOF | ||
| chmod +x "$TEMP_DIR/bin/nix" | ||
| mkdir -p "$TEMP_DIR/repo" | ||
|
|
||
| When run bash -c "TMPDIR='$TEMP_DIR' PATH='$TEMP_DIR/bin:$PATH' GITHUB_TOKEN='ghp_test_token' /bin/sh '$TEMP_DIR/nix-cache-warmup.sh' '$TEMP_DIR/repo' --show-trace >/dev/null; cat '$TEMP_DIR/nix.log'" | ||
| The status should be success | ||
| The output should include 'ARGS:flake metadata' | ||
| The output should include '--no-write-lock-file' | ||
| The output should include '--show-trace' | ||
| The output should include 'NIX_CONFIG:access-tokens = github.com=ghp_test_token' | ||
| End | ||
| End | ||
|
|
||
| End |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.