-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from mole99/nix
WIP: Nix build system
- Loading branch information
Showing
13 changed files
with
872 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: Build/Cache Nix | ||
description: Builds default devShell for a platform, caching the results (if applicable) | ||
inputs: | ||
cachix_cache: | ||
description: "The name of the Cachix cache to download to and/or upload from" | ||
required: true | ||
default: "openlane" | ||
cachix_token: | ||
description: "An authentication token for Cachix" | ||
required: false | ||
default: "" | ||
shell: | ||
description: "Shell to use" | ||
required: true | ||
default: "bash" | ||
nix_system: | ||
description: "The nix platform string to build for" | ||
required: true | ||
default: "x86_64-linux" | ||
local_cache_key: | ||
description: Key to use for the cache | ||
required: false | ||
default: "" | ||
run_tests: | ||
description: Whether to run unit tests and the smoke test | ||
required: false | ||
default: "false" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- id: cache | ||
name: Cache Derivation | ||
uses: actions/cache@v3 | ||
with: | ||
key: ${{ inputs.local_cache_key }}-${{ inputs.nix_system }} | ||
path: /tmp/${{ inputs.local_cache_key }} | ||
- id: Build | ||
name: Build | ||
shell: ${{ inputs.shell }} | ||
run: | | ||
substituters='https://${{ inputs.cachix_cache }}.cachix.org https://cache.nixos.org' | ||
if [ '${{ inputs.local_cache_key }}' = '' ]; then | ||
substituters="file:///tmp/${{ inputs.local_cache_key }} $substituters" | ||
fi | ||
echo "#################################################################" | ||
outPath=$(nix build\ | ||
--print-out-paths\ | ||
--no-link\ | ||
--accept-flake-config\ | ||
--option system ${{ inputs.nix_system }}\ | ||
--extra-platforms ${{ inputs.nix_system }}\ | ||
--option substituters "$substituters"\ | ||
.#devShells.${{ inputs.nix_system }}.default) | ||
echo "out-path=$outPath" >> $GITHUB_OUTPUT | ||
sudo du -hs /nix/store/* | sort -h | tail -n 20 | ||
- name: Unit/Step Tests | ||
shell: ${{ inputs.shell }} | ||
if: inputs.run_tests == 'true' | ||
run: echo TODO | ||
- name: Smoke Test | ||
shell: ${{ inputs.shell }} | ||
if: inputs.run_tests == 'true' | ||
run: | | ||
echo "#################################################################" | ||
nix run\ | ||
--option system ${{ inputs.nix_system }}\ | ||
--extra-platforms ${{ inputs.nix_system }}\ | ||
--accept-flake-config\ | ||
.#packages.${{ inputs.nix_system }}.cace -- --help | ||
- name: Push to local cache | ||
shell: ${{ inputs.shell }} | ||
if: inputs.local_cache_key != '' && steps.cache.outputs.cache-hit != 'true' | ||
run: | | ||
nix copy\ | ||
--to 'file:///tmp/${{ inputs.local_cache_key }}?compression=zstd¶llel-compression=true'\ | ||
${{ steps.build.outputs.out-path }} | ||
- name: Install + Push to Cachix | ||
shell: ${{ inputs.shell }} | ||
if: ${{ inputs.cachix_token != '' }} | ||
run: | | ||
echo "#################################################################" | ||
nix-env -iA cachix -f https://cachix.org/api/v1/install | ||
cachix authtoken ${{ inputs.cachix_token }} | ||
cachix push ${{ inputs.cachix_cache }} ${{ steps.build.outputs.out-path }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Check Space | ||
description: Reusable step that prints disk usage information | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Check Space | ||
shell: bash | ||
run: | | ||
if test -d /nix/store; then | ||
sudo du -hs /nix/store/* | sort -h | tail -n 10 | ||
fi | ||
echo =============== | ||
df -h | ||
echo =============== | ||
du -hs ~/* | sort -h | ||
echo =============== | ||
du -hs * | sort -h | ||
echo =============== | ||
du -hs /home/runner/runners/* | sort -h | ||
echo =============== | ||
du -hs /home/runner/work/* | sort -h | ||
echo =============== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Set up environment | ||
description: Sets up a number of environment variables that are useful for publishing | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Export Repo URL | ||
shell: bash | ||
run: echo "REPO_URL=https://github.com/${{ github.repository }}.git" >> $GITHUB_ENV | ||
|
||
- name: Export Branch Name | ||
shell: bash | ||
run: echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV | ||
|
||
- name: Set default for env.NEW_TAG | ||
shell: bash | ||
run: echo "NEW_TAG=NO_NEW_TAG" >> $GITHUB_ENV | ||
|
||
- name: Check for new version | ||
if: ${{ github.event_name == 'push' && env.BRANCH_NAME == 'main' }} | ||
shell: bash | ||
run: | | ||
python3 ./.github/scripts/generate_tag.py | ||
- name: Publish | ||
if: ${{ github.event_name == 'push' && env.BRANCH_NAME == 'main' && env.NEW_TAG != 'NO_NEW_TAG' }} | ||
shell: bash | ||
run: | | ||
echo "PUBLISH=1" >> $GITHUB_ENV |
Oops, something went wrong.