Commit Graph

13 Commits

Author SHA1 Message Date
Jan Tojnar
a20a4af62a maintainers/scripts/update.nix: Support committing with nix-update-script
When updating a package using nix-update-script with `--argstr commit true`,
update.nix would not detect the changes because nix-update would stage them
and `git diff` would be empty.

We now detect both staged and unstaged changes to handle this use case.
2021-10-31 11:00:37 +01:00
Jan Tojnar
416cd66e29
maintainers/scripts/update.nix: Ensure the worktree is clean
When an update script fails, it might still modify the source tree.
These changes would then be committed in the next update attempt.
Let’s make sure the worktree is clean before updating to avoid that.
2021-05-05 22:42:30 +02:00
Jan Tojnar
71c246c785
maintainers/scripts/update.nix: Run update scripts from the worktree
`update.nix` extracts `passthru.updateScript` attributes in the main repo
and when they are relative paths (e.g. `./update.sh`), Nix will resolve them
to absolute paths in the main repo.

Update scripts can use $(dirname $0) to get the location of files they
should update but that would point to the main repo.
We want them to modify the appropriate git worktree instead
so we replace the prefix accordingly.

`git rev-parse --show-toplevel` will resolve symlinks but, fortunately,
Nix will do that as well, so the path will match:

https://github.com/NixOS/nixpkgs/pull/98304#issuecomment-695761754
2020-09-20 20:12:34 +02:00
Jan Tojnar
0c5ddf3358
maintainers/scripts/update.nix: run update script with UPDATE_NIX_ATTR_PATH
The environment variable will contain the attribute path the script is supposed to update.
2020-09-20 20:12:33 +02:00
Jan Tojnar
c21a85c6a0
maintainers/scripts/update.nix: auto-detect attrPath 2020-09-20 20:11:46 +02:00
Jan Tojnar
b351de0971
maintainers/scripts/update.nix: mention when there were no changes committed 2020-09-20 20:11:46 +02:00
Jan Tojnar
b828285933
maintainers/scripts/update.nix: support filling in auto-commit attributes
We can determine all of them when attrPath is present so we might jsut as well do it.
2020-09-20 20:11:46 +02:00
Jan Tojnar
4a161ddb3b
maintainers/scripts/update.nix: support auto-committing by passing attrPath
Instead of having the updateScript support returning JSON object,
it should be sufficient to specify attrPath in passthru.updateScript.
It is much easier to use.

The former is now considered experimental.
2020-09-20 20:11:46 +02:00
Jan Tojnar
01b9d5371c
maintainers/scripts/update.nix: switch to asyncio
This will make it cleaner and also better respect SIGTERM.
2020-09-20 20:11:45 +02:00
Jan Tojnar
17f89667b3
maintainers/scripts/update.nix: refactoring
Get rid of some globals, split main into smaller functions, rename some variables, add typehints.
2020-09-20 20:11:45 +02:00
Jan Tojnar
1efc042d92
maintainers/scripts/update.nix: Add support for auto-commiting changes
Update scripts can now declare features using

	passthru.updateScript = {
	  command = [ ../../update.sh pname ];
	  supportedFeatures = [ "commit" ];
	};

A `commit` feature means that when the update script finishes successfully,
it will print a JSON list like the following:

	[
	  {
	    "attrPath": "volume_key",
	    "oldVersion": "0.3.11",
	    "newVersion": "0.3.12",
	    "files": [
	      "/path/to/nixpkgs/pkgs/development/libraries/volume-key/default.nix"
	    ]
	  }
	]

and data from that will be used when update.nix is run with --argstr commit true
to create commits.

We will create a new git worktree for each thread in the pool and run the update
script there. Then we will commit the change and cherry pick it in the main repo,
releasing the worktree for a next change.
2020-09-20 20:11:22 +02:00
Jan Tojnar
5adbeb13c5
update.nix: use ThreadPoolExecutor
Not sure why I chose ProcessPoolExecutor in the first place.
2020-09-18 20:52:07 +02:00
Jan Tojnar
59a94b57f0
update.nix: Run update scripts in parallel
To make updating large attribute sets faster, the update scripts
are now run in parallel.

Please note the following changes in semantics:

- The string passed to updateScript needs to be a path to an executable file.
- The updateScript can also be a list: the tail elements will then be passed
  to the head as command line arguments.
2018-12-01 19:17:13 +01:00