Skip to content

Commit f53df97

Browse files
authored
Merge pull request #151 from Jayman2000/ref-statuses
Add `refStatuses` CEL variable
2 parents ca7cfb3 + e3f635a commit f53df97

File tree

14 files changed

+200
-160
lines changed

14 files changed

+200
-160
lines changed

.github/workflows/allowed-refs.yaml

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Check that ref statuses are up to date
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *" # Daily
6+
7+
jobs:
8+
check-ref-statuses:
9+
runs-on: ubuntu-22.04
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- uses: DeterminateSystems/nix-installer-action@main
14+
15+
- uses: DeterminateSystems/magic-nix-cache-action@main
16+
17+
- name: Check ref statuses
18+
run: |
19+
nix develop --command cargo run --features ref-statuses -- --check-ref-statuses
20+
21+
- name: Update ref-statuses.json
22+
if: failure()
23+
run: |
24+
ref_statuses_json=$(nix develop --command cargo run --features ref-statuses -- --get-ref-statuses | jq --sort-keys .)
25+
echo "${ref_statuses_json}" > ref-statuses.json
26+
27+
- name: Create pull request
28+
if: failure()
29+
uses: peter-evans/create-pull-request@v6
30+
with:
31+
commit-message: Update ref-statuses.json to new valid Git refs list
32+
title: Update ref-statuses.json
33+
body: |
34+
Nixpkgs has changed its list of maintained references. This PR updates `ref-statuses.json` to reflect that change.
35+
branch: updated-ref-statuses
36+
base: main

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ thiserror = { workspace = true }
3838

3939
[features]
4040
default = []
41-
allowed-refs = []
41+
ref-statuses = []

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Variable | Description
7272
`numDaysOld` | The number of days old the input is.
7373
`owner` | The input's owner (if a GitHub input).
7474
`supportedRefs` | A list of [supported Git refs](#supported-branches) (all are branch names).
75+
`refStatuses` | A map. Each key is a branch name. Each value is a branch status (`"rolling"`, `"beta"`, `"stable"`, `"deprecated"` or `"unmaintained"`).
7576

7677
We recommend a condition *at least* this stringent:
7778

allowed-refs.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

flake.lock

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@
9191
runtimeInputs = with pkgs; [ rustToolchain ];
9292
text = "cargo fmt --check";
9393
};
94-
get-allowed-refs = pkgs.writeShellApplication {
95-
name = "get-allowed-refs";
94+
get-ref-statuses = pkgs.writeShellApplication {
95+
name = "get-ref-statuses";
9696
runtimeInputs = with pkgs; [ rustToolchain ];
97-
text = "cargo run --features allowed-refs -- --get-allowed-refs";
97+
text = "cargo run --features ref-statuses -- --get-ref-statuses";
9898
};
9999
in
100100
pkgs.mkShell {
@@ -117,7 +117,7 @@
117117
check-rustfmt
118118

119119
# Scripts
120-
get-allowed-refs
120+
get-ref-statuses
121121
]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [ Security SystemConfiguration ]);
122122

123123
env = {

ref-statuses.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"nixos-24.05": "unmaintained",
3+
"nixos-24.05-small": "unmaintained",
4+
"nixos-24.11": "stable",
5+
"nixos-24.11-small": "stable",
6+
"nixos-unstable": "rolling",
7+
"nixos-unstable-small": "rolling",
8+
"nixpkgs-24.05-darwin": "unmaintained",
9+
"nixpkgs-24.11-darwin": "stable",
10+
"nixpkgs-unstable": "rolling"
11+
}

src/allowed_refs.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/condition.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use cel_interpreter::{Context, Program, Value};
22
use parse_flake_lock::{FlakeLock, Node};
33

4+
use std::collections::HashMap;
5+
46
use crate::{
57
error::FlakeCheckerError,
68
flake::{nixpkgs_deps, num_days_old},
@@ -10,16 +12,19 @@ use crate::{
1012
const KEY_GIT_REF: &str = "gitRef";
1113
const KEY_NUM_DAYS_OLD: &str = "numDaysOld";
1214
const KEY_OWNER: &str = "owner";
15+
const KEY_REF_STATUSES: &str = "refStatuses";
1316
const KEY_SUPPORTED_REFS: &str = "supportedRefs";
1417

1518
pub(super) fn evaluate_condition(
1619
flake_lock: &FlakeLock,
1720
nixpkgs_keys: &[String],
1821
condition: &str,
22+
ref_statuses: HashMap<String, String>,
1923
supported_refs: Vec<String>,
2024
) -> Result<Vec<Issue>, FlakeCheckerError> {
2125
let mut issues: Vec<Issue> = vec![];
2226
let mut ctx = Context::default();
27+
ctx.add_variable_from_value(KEY_REF_STATUSES, ref_statuses);
2328
ctx.add_variable_from_value(KEY_SUPPORTED_REFS, supported_refs);
2429

2530
let deps = nixpkgs_deps(flake_lock, nixpkgs_keys)?;

0 commit comments

Comments
 (0)