Skip to content

Commit

Permalink
Merge pull request #348 from nix-community/reusable-actions
Browse files Browse the repository at this point in the history
ci: split out reusable actions
  • Loading branch information
nzbr authored Nov 30, 2023
2 parents 3ac7e5d + 654152e commit c9d56cc
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 142 deletions.
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

0 comments on commit c9d56cc

Please sign in to comment.