Skip to content

Commit 199b533

Browse files
vlaciLászló Vaskó
authored andcommitted
chore(nix): auto-update nix vendored dependencies
1 parent bf5fa11 commit 199b533

File tree

3 files changed

+113
-1
lines changed

3 files changed

+113
-1
lines changed

.github/workflows/update-nix.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,19 @@ jobs:
2424
pr-labels: | # Labels to be set on the PR
2525
dependencies
2626
automated
27+
28+
update-vendored:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v3
32+
- uses: cachix/install-nix-action@v20
33+
with:
34+
nix_path: nixpkgs=channel:nixos-unstable
35+
extra_nix_config: |
36+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
37+
- uses: cachix/cachix-action@v12
38+
with:
39+
name: unblob
40+
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
41+
- name: Update vendored package versions
42+
run: .github/workflows/update-vendored-nix-dependencies.py
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env nix-shell
2+
#! nix-shell -i python3 -p "python3.withPackages (ps: with ps; [ PyGithub ])" nvfetcher
3+
# pyright: reportMissingImports=false
4+
import subprocess
5+
from os import environ as env
6+
from pathlib import Path
7+
from tempfile import NamedTemporaryFile
8+
9+
from github import Github
10+
from github.GithubException import GithubException
11+
from github.Repository import Repository
12+
13+
API_TOKEN = env["GITHUB_TOKEN"]
14+
REPOSITORY = env["GITHUB_REPOSITORY"]
15+
BASE_BRANCH = env.get("GITHUB_BASE_BRANCH", "main")
16+
DRY_RUN = bool(env.get("GITHUB_DRY_RUN", False))
17+
18+
USER_NAME = "github-actions[bot]"
19+
USER_EMAIL = "github-actions[bot]@users.noreply.github.com"
20+
21+
22+
def create_pr(
23+
repo: Repository,
24+
pr_branch_name: str,
25+
pr_title: str,
26+
pr_body: str,
27+
):
28+
try:
29+
repo.get_branch(pr_branch_name)
30+
print(f"Branch '{pr_branch_name}' already exist. Skipping update.")
31+
except GithubException as ex:
32+
if ex.status != 404:
33+
raise
34+
else:
35+
return
36+
37+
subprocess.run(["git", "add", "."], check=True)
38+
subprocess.run(
39+
["git", "commit", "-m", f"{pr_title}\n\n{pr_body}"],
40+
check=True,
41+
env={
42+
"GIT_AUTHOR_NAME": USER_NAME,
43+
"GIT_COMMITTER_NAME": USER_NAME,
44+
"GIT_AUTHOR_EMAIL": USER_EMAIL,
45+
"GIT_COMMITTER_EMAIL": USER_EMAIL,
46+
},
47+
)
48+
subprocess.run(["git", "push", "origin", f"+HEAD:{pr_branch_name}"], check=True)
49+
pr = repo.create_pull(
50+
title=pr_title, body=pr_body, head=pr_branch_name, base=BASE_BRANCH
51+
)
52+
pr.add_to_labels("automated", "dependencies")
53+
54+
55+
def update_dependencies():
56+
with NamedTemporaryFile() as log:
57+
subprocess.run(
58+
["nvfetcher", "--build-dir", "nix/_sources", "--changelog", log.name]
59+
)
60+
return Path(log.name).read_text()
61+
62+
63+
def main():
64+
github = Github(API_TOKEN)
65+
66+
repo = github.get_repo(REPOSITORY)
67+
68+
changes = update_dependencies()
69+
if not changes:
70+
print("-- Everything is up-to date")
71+
return
72+
73+
title = "chore(deps): Updating vendored nix dependencies"
74+
75+
body = f"""\
76+
### Changes in dependencies:
77+
78+
{changes}
79+
"""
80+
81+
print(f"-- Creating PR\nTitle: {title}\nBody:\n{body}")
82+
if DRY_RUN:
83+
print("DRY-RUN: NOT creating PR...")
84+
return
85+
86+
pr_branch_name = "refs/heads/update/nix-vendored-dependencies"
87+
create_pr(
88+
repo,
89+
pr_branch_name,
90+
title,
91+
body,
92+
)
93+
94+
95+
if __name__ == "__main__":
96+
main()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ ignore = [
106106
ignore-init-module-imports = true
107107

108108
[tool.ruff.per-file-ignores]
109-
"build.py" = [
109+
".github/*" = [
110110
"T201" # print
111111
]
112112
"tests/*" = [

0 commit comments

Comments
 (0)