Skip to content

Commit c042dcb

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

File tree

5 files changed

+144
-28
lines changed

5 files changed

+144
-28
lines changed

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

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

9106
- name: Enter devshell
10107
uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a # v1.2.1
108+
with:
109+
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: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,38 @@
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+
clang
62+
coreutils
63+
create-dmg
64+
gh
65+
git
66+
gnumake
67+
protobuf_28
68+
protoc-gen-swift
69+
swiftformat
70+
swiftlint
71+
xcbeautify
72+
xcodegen
73+
xcpretty
74+
zizmor
75+
];
76+
};
77+
78+
default = pkgs.mkShellNoCC {
79+
buildInputs =
80+
with pkgs;
81+
[
82+
apple-sdk_15
83+
formatter
84+
watchexec
85+
]
86+
++ ci.buildInputs;
87+
};
7688
};
7789
}
7890
);

0 commit comments

Comments
 (0)