Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup release workflow
Browse files Browse the repository at this point in the history
sestrella committed Nov 21, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f0e6041 commit 89be3c9
Showing 9 changed files with 5,877 additions and 106 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
@@ -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

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 }]
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;
};
};
};
};
}
);
}
5,678 changes: 5,678 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "asdf2nix",
"dependencies": {
"semantic-release": "^22.0.8"
}
}
30 changes: 30 additions & 0 deletions 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 }}

0 comments on commit 89be3c9

Please sign in to comment.