Skip to content

Commit 4ca9e01

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

File tree

5 files changed

+212
-28
lines changed

5 files changed

+212
-28
lines changed

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

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,176 @@ 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 -e
11+
set -u
12+
set -o pipefail
13+
14+
# Uninstall Gems.
15+
for gem in $(gem list --no-versions | grep -v \
16+
-e 'bigdecimal' \
17+
-e 'CFPropertyList' \
18+
-e 'cmath' \
19+
-e 'csv' \
20+
-e 'date' \
21+
-e 'dbm' \
22+
-e 'did_you_mean' \
23+
-e 'e2mmap' \
24+
-e 'etc' \
25+
-e 'fcntl' \
26+
-e 'fiddle' \
27+
-e 'fileutils' \
28+
-e 'forwardable' \
29+
-e 'io-console' \
30+
-e 'ipaddr' \
31+
-e 'irb' \
32+
-e 'json' \
33+
-e 'libxml-ruby' \
34+
-e 'logger' \
35+
-e 'matrix' \
36+
-e 'minitest' \
37+
-e 'mutex_m' \
38+
-e 'net-telnet' \
39+
-e 'nokogiri' \
40+
-e 'openssl' \
41+
-e 'ostruct' \
42+
-e 'power_assert' \
43+
-e 'prime' \
44+
-e 'psych' \
45+
-e 'rake' \
46+
-e 'rexml' \
47+
-e 'rdoc' \
48+
-e 'rss' \
49+
-e 'scanf' \
50+
-e 'shell' \
51+
-e 'sqlite3' \
52+
-e 'stringio' \
53+
-e 'strscan' \
54+
-e 'sync' \
55+
-e 'test-unit' \
56+
-e 'thwait' \
57+
-e 'tracer' \
58+
-e 'webrick' \
59+
-e 'xmlrpc' \
60+
-e 'zlib' \
61+
); do
62+
sudo gem uninstall --force --all --ignore-dependencies --executables "$gem" || true
63+
done
64+
65+
# Uninstall Homebrew.
66+
brew update
67+
sudo rm -rf /usr/local/miniconda &
68+
rm -rf /usr/local/lib/node_modules &
69+
rm -f /usr/local/bin/terminal-notifier
70+
rm -f /usr/local/bin/change_hostname.sh
71+
rm -f /usr/local/bin/azcopy
72+
73+
if which brew &>/dev/null; then
74+
eval "$(brew list --formula | xargs -I% echo 'brew uninstall --formula --force --ignore-dependencies "%" &')"
75+
eval "$(brew list --cask | xargs -I% echo '{ brew uninstall --cask --force "%"; brew uninstall --cask --zap --force "%"; } &')"
76+
brew uninstall --cask --zap --force dotnet &
77+
brew uninstall --cask --zap --force adoptopenjdk/openjdk/adoptopenjdk8 &
78+
brew uninstall --cask --zap --force mono-mdk &
79+
brew uninstall --cask --zap --force xamarin-android &
80+
brew uninstall --cask --zap --force xamarin-ios &
81+
brew uninstall --cask --zap --force xamarin-mac &
82+
wait
83+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" -- --force
84+
fi
85+
86+
# Clean environment.
87+
for trash in ~/.DS_Store \
88+
~/.Trash/* \
89+
~/.aliyun \
90+
~/.android \
91+
~/.azcopy \
92+
~/.azure \
93+
~/.bash_history \
94+
~/.bash_profile \
95+
~/.bash_sessions \
96+
~/.bashrc \
97+
~/.cabal \
98+
~/.cache \
99+
~/.cargo \
100+
~/.cocoapods \
101+
~/.composer \
102+
~/.conda \
103+
~/.config \
104+
~/.dotnet \
105+
~/.fastlane \
106+
~/.gem \
107+
~/.ghcup \
108+
~/.gitconfig \
109+
~/.gradle \
110+
~/.local \
111+
~/.m2 \
112+
~/.mono \
113+
~/.npm \
114+
~/.npmrc \
115+
~/.nvm \
116+
~/.oracle_jre_usage \
117+
~/.packer.d \
118+
~/.rustup \
119+
~/.sh_history \
120+
~/.ssh \
121+
~/.subversion \
122+
~/.sqlite_history \
123+
~/.vcpkg \
124+
~/.viminfo \
125+
~/.wget-hsts \
126+
~/.yarn \
127+
~/Library/Caches/Homebrew \
128+
~/Microsoft \
129+
~/hostedtoolcache \
130+
~/*.txt; do
131+
if [[ -e "$trash" ]]; then
132+
mv "$trash" /tmp/trash/
133+
fi
134+
done
135+
136+
# Delete broken symlinks.
137+
for exe in /usr/local/bin/*; do
138+
if [[ -L "$exe" ]] && ! [[ -e "$exe" ]]; then
139+
rm "$exe"
140+
fi
141+
done
142+
143+
mkdir -p /tmp/trash
144+
for pkg in /var/db/receipts/*.plist; do
145+
pkg_id="$(basename "${pkg}" .plist)"
146+
volume="$(pkgutil --pkg-info "${pkg_id}" | sed -n -e 's/^volume: //p')"
147+
location="$(pkgutil --pkg-info "${pkg_id}" | sed -n -e 's/^location: //p')"
148+
pkgutil --only-files --files "${pkg_id}" | xargs -I% sudo mv -f "${volume}${location}/%" /tmp/trash/ || true
149+
pkgutil --only-dirs --files "${pkg_id}" | xargs -I% sudo rmdir -p "${volume}${location}/%" || true
150+
pkgutil --forget "${pkg_id}"
151+
done
152+
6153
- name: Setup Nix
7-
uses: DeterminateSystems/nix-installer-action@e50d5f73bfe71c2dd0aa4218de8f4afa59f8f81d # v16
154+
uses: nixbuild/nix-quick-install-action@5bb6a3b3abe66fd09bbf250dce8ada94f856a703 # v30
155+
156+
- uses: nix-community/cache-nix-action@92aaf15ec4f2857ffed00023aecb6504bb4a5d3d # v6
157+
with:
158+
# restore and save a cache using this key
159+
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
160+
# if there's no cache hit, restore a cache by this prefix
161+
restore-prefixes-first-match: nix-${{ runner.os }}-
162+
# collect garbage until Nix store size (in bytes) is at most this number
163+
# before trying to save a new cache
164+
# 1 GB = 1073741824 B
165+
gc-max-store-size-linux: 1073741824
166+
# do purge caches
167+
purge: true
168+
# purge all versions of the cache
169+
purge-prefixes: nix-${{ runner.os }}-
170+
# created more than this number of seconds ago relative to the start of the `Post Restore` phase
171+
purge-created: 0
172+
# except the version with the `primary-key`, if it exists
173+
purge-primary-key: never
8174

9175
- name: Enter devshell
10176
uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
177+
with:
178+
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)