Skip to content

Commit

Permalink
Setup semantic-release (#3)
Browse files Browse the repository at this point in the history
* Setup release workflow

* Update status badge

* Move release workflow to the right directory
  • Loading branch information
sestrella authored Nov 21, 2023
1 parent f0e6041 commit 810fa57
Show file tree
Hide file tree
Showing 10 changed files with 5,879 additions and 107 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
29 changes: 15 additions & 14 deletions .github/workflows/ci.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
name: CI
name: Build

on: push

concurrency:
group: ci-${{ github.ref }}
group: build-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v23
- name: Run tests
run: nix eval --impure .#tests
working-directory: tests

templates:
runs-on: ubuntu-latest
needs: [test]
strategy:
matrix:
template:
- name: default
test: nix develop --accept-flake-config -c python --version
- name: devenv
test: nix develop --accept-flake-config --impure -c python --version
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -33,14 +45,3 @@ jobs:
run: ${{ matrix.template.test }}
working-directory: ${{ steps.mktemp.outputs.tmpdir }}

test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v23
- name: Run tests
run: nix eval --impure .#tests
working-directory: tests

30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Release

on:
workflow_run:
workflows: [Build]
types: [completed]

concurrency:
group: release
cancel-in-progress: true

jobs:
release:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v6
- name: Install tools via Nix
run: nix develop --check
- name: Install dependencies
run: nix develop -c npm ci
- name: Run semantic-release
run: nix develop -c npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.direnv
node_modules
templates/*/flake.lock
5 changes: 5 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
branches: [main]
plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- ["@semantic-release/github", { successComment: false }]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# asdf2nix

[![CI](https://github.com/sestrella/asdf2nix/actions/workflows/ci.yml/badge.svg)](https://github.com/sestrella/asdf2nix/actions/workflows/ci.yml)
[![Build](https://github.com/sestrella/asdf2nix/actions/workflows/build.yml/badge.svg)](https://github.com/sestrella/asdf2nix/actions/workflows/build.yml)
[![Release](https://github.com/sestrella/asdf2nix/actions/workflows/release.yml/badge.svg)](https://github.com/sestrella/asdf2nix/actions/workflows/release.yml)

asdf2nix is a tool designed for [asdf] users who want to experiment with
nix-shells, as well as former Nix users who want to simplify package version
Expand Down
46 changes: 39 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

186 changes: 101 additions & 85 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,97 +1,113 @@
{
inputs.nixpkgs-lib.url = "github:nixos/nixpkgs/nixos-23.05?dir=lib";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
};

outputs = { self, nixpkgs-lib }:
let
lib = nixpkgs-lib.lib;
in
{
lib.packagesFromVersionsFile =
{ versionsFile
, system ? builtins.currentSystem
, plugins ? { }
, skipMissingPlugins ? false
}:
outputs = { self, flake-utils, nixpkgs }:
flake-utils.lib.eachDefaultSystem
(system:
let
fileLines = file: lib.splitString "\n" (lib.fileContents file);
removeComments = builtins.filter (line: !lib.hasPrefix "#" line);
parseVersions = builtins.map
(line:
let
pluginAndVersion = lib.splitString " " line;
in
{
name = builtins.elemAt pluginAndVersion 0;
version = builtins.elemAt pluginAndVersion 1;
});
filterPlugins = builtins.filter
({ name, ... }:
let
hasPlugin = builtins.hasAttr name plugins;
in
lib.throwIf (!skipMissingPlugins && !hasPlugin)
''
No plugin found for "${name}", try adding the missing plugin:
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell {
buildInputs = [ pkgs.nodejs ];
};
})
//
(
let
lib = nixpkgs.lib;
in
{
lib.packagesFromVersionsFile =
{ versionsFile
, system ? builtins.currentSystem
, plugins ? { }
, skipMissingPlugins ? false
}:
let
fileLines = file: lib.splitString "\n" (lib.fileContents file);
removeComments = builtins.filter (line: !lib.hasPrefix "#" line);
parseVersions = builtins.map
(line:
let
pluginAndVersion = lib.splitString " " line;
in
{
name = builtins.elemAt pluginAndVersion 0;
version = builtins.elemAt pluginAndVersion 1;
});
filterPlugins = builtins.filter
({ name, ... }:
let
hasPlugin = builtins.hasAttr name plugins;
in
lib.throwIf (!skipMissingPlugins && !hasPlugin)
''
No plugin found for "${name}", try adding the missing plugin:
```
<asdf2nix>.lib.packagesFromVersionsFile {
plugins = {
${name} = <asdf2nix-${name}>.lib.packageFromVersion;
```
<asdf2nix>.lib.packagesFromVersionsFile {
plugins = {
${name} = <asdf2nix-${name}>.lib.packageFromVersion;
...
};
...
};
...
};
```
```
Or enable `skipMissingPlugins` to skip this error:
Or enable `skipMissingPlugins` to skip this error:
```
<asdf2nix>.lib.packagesFromVersionsFile {
plugins = { ... };
skipMissingPlugins = true;
...
};
```
''
lib.warnIf
(!hasPlugin) "Skipping \"${name}\" plugin"
hasPlugin);
findPackages = builtins.map
({ name, version }:
let
plugin = plugins.${name};
in
lib.throwIf (!plugin.hasVersion { inherit system version; })
''
Plugin "${name}" does not provide version "${version}", try
updating the plugin's input:
```
<asdf2nix>.lib.packagesFromVersionsFile {
plugins = { ... };
skipMissingPlugins = true;
...
};
```
''
lib.warnIf
(!hasPlugin) "Skipping \"${name}\" plugin"
hasPlugin);
findPackages = builtins.map
({ name, version }:
let
plugin = plugins.${name};
in
lib.throwIf (!plugin.hasVersion { inherit system version; })
''
Plugin "${name}" does not provide version "${version}", try
updating the plugin's input:
```
> nix flake lock --update-input <asdf2nix-${name}>
```
''
{
inherit name;
value = plugin.packageFromVersion { inherit system version; };
}
);
in
builtins.listToAttrs
(findPackages
(filterPlugins
(parseVersions
(removeComments
(fileLines versionsFile)))));
```
> nix flake lock --update-input <asdf2nix-${name}>
```
''
{
inherit name;
value = plugin.packageFromVersion { inherit system version; };
}
);
in
builtins.listToAttrs
(findPackages
(filterPlugins
(parseVersions
(removeComments
(fileLines versionsFile)))));

templates = {
default = {
description = "Install Nix packages from asdf versions file";
path = ./templates/default;
};
devenv = {
description = "Integration with devenv";
path = ./templates/devenv;
templates = {
default = {
description = "Install Nix packages from asdf versions file";
path = ./templates/default;
};
devenv = {
description = "Integration with devenv";
path = ./templates/devenv;
};
};
};
};
}
);
}
Loading

0 comments on commit 810fa57

Please sign in to comment.