Skip to content

Commit 517d786

Browse files
committed
ci: add gh cache to nix action
Change-Id: Ie564f9efc86b64f2582a2fdbf395a6dba84c3c81 Signed-off-by: Thomas Kosiewski <[email protected]>
1 parent a906e98 commit 517d786

File tree

5 files changed

+144
-28
lines changed

5 files changed

+144
-28
lines changed

.github/actions/nix-devshell/action.yaml

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,108 @@ description: "This action sets up a nix devshell environment"
33
runs:
44
using: "composite"
55
steps:
6+
# Adapted from: https://github.com/reitermarkus/dotfiles/blob/349cf6c0aff2ab8666247904779b788a14b99fa0/.github/workflows/ci.yml#L39-L190
7+
- name: Clean environment
8+
shell: bash
9+
run: |
10+
set -euo pipefail
11+
12+
sudo rm -rf /usr/local/miniconda &
13+
rm -rf /usr/local/lib/node_modules &
14+
rm -f /usr/local/bin/terminal-notifier
15+
rm -f /usr/local/bin/change_hostname.sh
16+
rm -f /usr/local/bin/azcopy
17+
18+
# Uninstall Homebrew.
19+
if which brew &>/dev/null; then
20+
eval "$(brew list --formula | xargs -I% echo 'brew uninstall --formula --force --ignore-dependencies "%" &')"
21+
eval "$(brew list --cask | xargs -I% echo '{ brew uninstall --cask --force "%"; brew uninstall --cask --zap --force "%"; } &')"
22+
wait
23+
# required for the quick install action
24+
brew install gnu-tar
25+
# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" -- --force
26+
fi
27+
28+
# Clean environment.
29+
for trash in ~/.DS_Store \
30+
~/.Trash/* \
31+
~/.aliyun \
32+
~/.android \
33+
~/.azcopy \
34+
~/.azure \
35+
~/.bash_history \
36+
~/.bash_profile \
37+
~/.bash_sessions \
38+
~/.bashrc \
39+
~/.cabal \
40+
~/.cache \
41+
~/.cargo \
42+
~/.cocoapods \
43+
~/.composer \
44+
~/.conda \
45+
~/.config \
46+
~/.dotnet \
47+
~/.fastlane \
48+
~/.gem \
49+
~/.ghcup \
50+
~/.gitconfig \
51+
~/.gradle \
52+
~/.local \
53+
~/.m2 \
54+
~/.mono \
55+
~/.npm \
56+
~/.npmrc \
57+
~/.nvm \
58+
~/.oracle_jre_usage \
59+
~/.packer.d \
60+
~/.rustup \
61+
~/.sh_history \
62+
~/.ssh \
63+
~/.subversion \
64+
~/.sqlite_history \
65+
~/.vcpkg \
66+
~/.viminfo \
67+
~/.wget-hsts \
68+
~/.yarn \
69+
~/Library/Caches/Homebrew \
70+
~/Microsoft \
71+
~/hostedtoolcache \
72+
~/*.txt; do
73+
if [[ -e "$trash" ]]; then
74+
rm -rf "$trash"
75+
fi
76+
done
77+
78+
# Delete broken symlinks.
79+
for exe in /usr/local/bin/*; do
80+
if [[ -L "$exe" ]] && ! [[ -e "$exe" ]]; then
81+
rm "$exe"
82+
fi
83+
done
84+
685
- name: Setup Nix
7-
uses: DeterminateSystems/nix-installer-action@e50d5f73bfe71c2dd0aa4218de8f4afa59f8f81d # v16
86+
uses: nixbuild/nix-quick-install-action@5bb6a3b3abe66fd09bbf250dce8ada94f856a703 # v30
87+
88+
- uses: nix-community/cache-nix-action@92aaf15ec4f2857ffed00023aecb6504bb4a5d3d # v6
89+
with:
90+
# restore and save a cache using this key
91+
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
92+
# if there's no cache hit, restore a cache by this prefix
93+
restore-prefixes-first-match: nix-${{ runner.os }}-
94+
# collect garbage until Nix store size (in bytes) is at most this number
95+
# before trying to save a new cache
96+
# 1 GB = 1073741824 B
97+
gc-max-store-size-linux: 1073741824
98+
# do purge caches
99+
purge: true
100+
# purge all versions of the cache
101+
purge-prefixes: nix-${{ runner.os }}-
102+
# created more than this number of seconds ago relative to the start of the `Post Restore` phase
103+
purge-created: 0
104+
# except the version with the `primary-key`, if it exists
105+
purge-primary-key: never
8106

9107
- name: Enter devshell
10108
uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
109+
with:
110+
arguments: ".#ci"

.ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.github

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ XCPROJECT := Coder\ Desktop/Coder\ Desktop.xcodeproj
1111
SCHEME := Coder\ Desktop
1212
SWIFT_VERSION := 6.0
1313

14-
CURRENT_PROJECT_VERSION:=$(shell git describe --match 'v[0-9]*' --dirty='.devel' --always --tags)
14+
ifndef CURRENT_PROJECT_VERSION
15+
CURRENT_PROJECT_VERSION:=$(shell git describe --match 'v[0-9]*' --dirty='.devel' --always --tags)
16+
endif
1517
ifeq ($(strip $(CURRENT_PROJECT_VERSION)),)
16-
$(error CURRENT_PROJECT_VERSION cannot be empty)
18+
$(error CURRENT_PROJECT_VERSION cannot be empty)
1719
endif
1820

19-
MARKETING_VERSION:=$(shell git describe --match 'v[0-9]*' --tags --abbrev=0 | sed 's/^v//' | sed 's/-.*$$//')
21+
ifndef MARKETING_VERSION
22+
MARKETING_VERSION:=$(shell git describe --match 'v[0-9]*' --tags --abbrev=0 | sed 's/^v//' | sed 's/-.*$$//')
23+
endif
2024
ifeq ($(strip $(MARKETING_VERSION)),)
21-
$(error MARKETING_VERSION cannot be empty)
25+
$(error MARKETING_VERSION cannot be empty)
2226
endif
2327

2428
# Define the keychain file name first

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,37 @@
5353
{
5454
inherit formatter;
5555

56-
devShells.default = pkgs.mkShellNoCC {
57-
buildInputs = with pkgs; [
58-
actionlint
59-
apple-sdk_15
60-
clang
61-
coreutils
62-
create-dmg
63-
formatter
64-
gh
65-
gnumake
66-
protobuf_28
67-
protoc-gen-swift
68-
swiftformat
69-
swiftlint
70-
watchexec
71-
xcbeautify
72-
xcodegen
73-
xcpretty
74-
zizmor
75-
];
56+
devShells = rec {
57+
# Need to use a devshell for CI, as we want to reuse the already existing Xcode on the runner
58+
ci = pkgs.mkShellNoCC {
59+
buildInputs = with pkgs; [
60+
actionlint
61+
swiftformat
62+
swiftlint
63+
xcbeautify
64+
xcodegen
65+
zizmor
66+
];
67+
};
68+
69+
default = pkgs.mkShellNoCC {
70+
buildInputs =
71+
with pkgs;
72+
[
73+
apple-sdk_15
74+
clang
75+
coreutils
76+
create-dmg
77+
formatter
78+
gh
79+
gnumake
80+
protobuf_28
81+
protoc-gen-swift
82+
watchexec
83+
xcpretty
84+
]
85+
++ ci.buildInputs;
86+
};
7687
};
7788
}
7889
);

0 commit comments

Comments
 (0)