-
-
Notifications
You must be signed in to change notification settings - Fork 110
127 lines (110 loc) · 4.04 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: 'CI'
on:
push: {}
pull_request: {}
workflow_call: {}
jobs:
prepare:
name: Prepare 🚀
runs-on: ubuntu-latest
outputs:
tests: ${{ steps.tests.outputs.tests }}
checks: ${{ steps.checks.outputs.checks }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install nix ❄️
uses: cachix/install-nix-action@v18
with:
extra_nix_config: 'access-tokens = github.com=${{ github.token }}'
- name: Find tests 🔍
id: tests
run: |
find tests -name '*.Tests.ps1' -print0 | perl -pe 's|(.*?)\x0|"\1",|g;s|,$||;s|(.*)|tests=[\1]|' >> $GITHUB_OUTPUT
- name: Find checks 🔍
id: checks
run: |
nix-instantiate --json --eval --strict -E 'with builtins; attrNames (getFlake (toString ./.)).checks.${currentSystem}' | perl -pe 's|(.*)|checks=\1|' >>$GITHUB_OUTPUT
- name: Generate Version 🏷️
id: version
run: |
TAG_COUNT=$(git rev-list --tags --no-walk --count) # Count all tags
COMMIT_COUNT=$(git rev-list --use-bitmap-index --count $(git rev-list --tags --no-walk --max-count=1)..HEAD) # Count all commits since the last tag
NIXOS_VERSION=$(nix-instantiate --eval -E '(import ./.).inputs.nixpkgs.lib.version' | sed -E 's/"(.+\...).*"/\1/') # Get NixOS version from nixpkgs
NIXOS_VERSION_MS=$(echo $NIXOS_VERSION | sed -E 's/\.0*(.+)/\.\1/') # Remove the leading 0 from the minor version (if it exists)
NIXOS_WSL_VERSION=${NIXOS_VERSION_MS}.${TAG_COUNT}.${COMMIT_COUNT} # Compose the NixOS-WSL version number
echo "version=$NIXOS_WSL_VERSION" >> $GITHUB_OUTPUT
build:
name: Build 🛠️
needs:
- prepare
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install nix ❄️
uses: cachix/install-nix-action@v18
with:
extra_nix_config: 'access-tokens = github.com=${{ github.token }}'
- name: Set version 🏷️
run: |
echo ${{ needs.prepare.outputs.version }} > ./VERSION
echo $(git rev-parse HEAD) >> ./VERSION
- name: Build installer 🛠️
run: |
nix build '.#nixosConfigurations.mysystem.config.system.build.installer'
- name: Upload installer 📤
uses: actions/upload-artifact@v3
with:
name: installer
path: result/tarball/nixos-wsl-installer.tar.gz
checks:
name: Flake Check 📋
needs:
- prepare
strategy:
fail-fast: false
matrix:
check: ${{ fromJSON(needs.prepare.outputs.checks) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install nix ❄️
uses: cachix/install-nix-action@v18
with:
extra_nix_config: 'access-tokens = github.com=${{ github.token }}'
- name: Run check 📋
run: |
nix build -L --impure --expr "with builtins; (getFlake (toString ./.)).checks.\${currentSystem}.${{ matrix.check }}"
tests:
name: Test 🧪
needs:
- prepare
- build
strategy:
fail-fast: false
matrix:
test: ${{ fromJSON(needs.prepare.outputs.tests) }}
os:
- ubuntu-20.04
# - windows-latest # doesn't work due to lack of nested virtualization on the runners, hopefully this will work one day
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download installer 📥
uses: actions/download-artifact@v3
with:
name: installer
- name: Execute test 🧪
shell: pwsh
run: |
Invoke-Pester -Output Detailed ${{ matrix.test }}