Skip to content
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

Split CI into reusable actions #348

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/actions/build-nix-expression/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
inputs:
expression:
description: 'Nix expression to build'
required: true

outputs:
derivation:
description: 'Path to the built derivation'
value: ${{ steps.build.outputs.derivation }}

runs:
using: 'composite'
steps:
- name: Install Nix ❄️
uses: ./.github/actions/install-nix

- name: Build ${{ inputs.expression }} 🛠️
id: build
shell: bash
run: |
JSON=$(mktemp)
(nix build -L ${{ inputs.expression }} --no-link --json >$JSON) |& sed -uE 's/^(trace: +)?warning:(\s+|$)/::warning::/;s/^(trace: +)?error:(\s+|$)/::error::/;s/^trace:(\s+|$)/::notice::trace: /'
DRV=$(jq -r .[0].outputs.out <$JSON)
echo "derivation=$DRV" >> $GITHUB_OUTPUT
echo "- Built \`$DRV\`" >> $GITHUB_STEP_SUMMARY
echo " - $(nix show-derivation -r $DRV | jq 'keys[]' | wc -l) derivations in closure" >> $GITHUB_STEP_SUMMARY
echo " - $(nix path-info -S --json $DRV | jq -r '.[0].closureSize' | xargs numfmt --to=iec-i --suffix=B --format='%.3f') total size" >> $GITHUB_STEP_SUMMARY
20 changes: 20 additions & 0 deletions .github/actions/build-wsl-tarball/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
inputs:
config:
description: 'System configuration to build'
required: true
filename:
description: 'Filename to save the image as'
required: true

runs:
using: 'composite'
steps:
- name: Build tarball builder 🛠️
id: buildBuilder
uses: ./.github/actions/build-nix-expression
with:
expression: '.#nixosConfigurations.${{ inputs.config }}.config.system.build.tarballBuilder'

- name: Build tarball 📦
shell: bash
run: sudo ${{ steps.buildBuilder.outputs.derivation }}/bin/nixos-wsl-tarball-builder ${{ inputs.filename }}
19 changes: 19 additions & 0 deletions .github/actions/install-nix/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
runs:
using: 'composite'
steps:
- name: Check for nix ✅
id: check-nix
shell: bash
run: |
if command -v nix &> /dev/null
then
echo "nix-found=true" | tee -a $GITHUB_OUTPUT
else
echo "nix-found=false" | tee -a $GITHUB_OUTPUT
fi

- name: Install Nix ❄️
if: ${{ steps.check-nix.outputs.nix-found != 'true' }}
uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ github.token }}
136 changes: 0 additions & 136 deletions .github/workflows/main.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Push"

on:
push:
branches: [main]
pull_request: {}

jobs:
build:
name: Build Tarballs 🛠️
uses: ./.github/workflows/run_build.yml

checks:
name: Flake Checks 📋
uses: ./.github/workflows/run_checks.yml

tests:
name: Tests 🧪
uses: ./.github/workflows/run_tests.yml
needs:
- build
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
name: 'Release'
name: "Release"

on:
push:
tags: []

jobs:
build:
name: Build 🛠️
uses: nix-community/nixos-wsl/.github/workflows/main.yml@main
name: Build Tarballs 🛠️
uses: ./.github/workflows/run_build.yml

release:
needs:
- build
name: Create Release 📢
runs-on: ubuntu-latest
steps:
- name: Download tarball 📥
- name: Download Tarball 📥
uses: actions/download-artifact@v3

- name: Generate checksums 🔑
- name: Generate Checksums 🔑
run: |
mv tarball-modern/nixos-wsl.tar.gz nixos-wsl.tar.gz
mv tarball-legacy/nixos-wsl.tar.gz nixos-wsl-legacy.tar.gz
for x in *.tar.gz; do
sha256sum $x > ${x}.sha256
done

- name: Attach to release 📦
- name: Attach to Release 📎
uses: softprops/action-gh-release@v1
with:
files: |
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/run_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build Tarballs

on:
workflow_call: {}

jobs:
build:
name: Build 🛠️
runs-on: ubuntu-latest
strategy:
matrix:
config:
- modern
- legacy
- test
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Nix ❄️
uses: ./.github/actions/install-nix

- 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

echo $NIXOS_WSL_VERSION > ./VERSION
echo $(git rev-parse HEAD) >> ./VERSION

- name: Build Tarball 🛠️
uses: ./.github/actions/build-wsl-tarball
with:
config: ${{ matrix.config }}
filename: nixos-wsl.tar.gz

- name: Upload Tarball 📤
uses: actions/upload-artifact@v3
with:
name: tarball-${{ matrix.config }}
path: nixos-wsl.tar.gz
46 changes: 46 additions & 0 deletions .github/workflows/run_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Flake Checks

on:
workflow_call: {}

jobs:
prepare:
name: Find Checks 🔍
runs-on: ubuntu-latest
outputs:
checks: ${{ steps.checks.outputs.checks }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Nix ❄️
uses: ./.github/actions/install-nix

- 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

checks:
name: Check 📋
needs:
- prepare
strategy:
fail-fast: false
matrix:
check: ${{ fromJSON(needs.prepare.outputs.checks) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Nix ❄️
uses: ./.github/actions/install-nix

- name: Run Check 📋
run: |
nix build -L --impure --expr "with builtins; (getFlake (toString ./.)).checks.\${currentSystem}.${{ matrix.check }}"
Loading
Loading