Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CONTRIBUTING: Add hotlinks to package and module reviewing guides, minor touchups #263575

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

pbsds
Copy link
Member

@pbsds pbsds commented Oct 26, 2023

Description of changes

I missed a detail myself, so let's improve discoverability.

Rendered:

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Oct 26, 2023
@pbsds pbsds force-pushed the contributing-link-naming-conventino branch from b3505fe to af7dc47 Compare October 26, 2023 12:14
@pbsds pbsds changed the title docs: Add hotlinks to package and module reviewing guides, minor touchups CONTRIBUTING.md: Add hotlinks to package and module reviewing guides, minor touchups Oct 26, 2023
@pbsds pbsds marked this pull request as ready for review October 26, 2023 12:15
@pbsds pbsds requested a review from infinisil as a code owner October 26, 2023 12:15
@pbsds pbsds mentioned this pull request Oct 26, 2023
12 tasks
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Oct 26, 2023
nixos/README.md Outdated Show resolved Hide resolved
@pbsds pbsds force-pushed the contributing-link-naming-conventino branch from af7dc47 to 3a97930 Compare October 27, 2023 13:34
@pbsds pbsds changed the title CONTRIBUTING.md: Add hotlinks to package and module reviewing guides, minor touchups CONTRIBUTING: Add hotlinks to package and module reviewing guides, minor touchups Oct 27, 2023
CONTRIBUTING.md Outdated
@@ -556,6 +556,7 @@ Pull requests should not be squash merged in order to keep complete commit messa
If you removed packages or made some major NixOS changes, write about it in the release notes for the next stable release in [`nixos/doc/manual/release-notes`](./nixos/doc/manual/release-notes).

### File naming and organisation
[file-naming-and-organisation]: #file-naming-and-organisation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately these only work locally in the file, changing the title will still break pages linking to it..

What should work, and I really think we should have that, is custom HTML anchors like

<a name="location"></a>

Can you try that and confirm whether it works?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is pandoc commonmark notation supported?

### File naming and organisation {#location}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not

@pbsds pbsds force-pushed the contributing-link-naming-conventino branch from 3a97930 to 06d00e3 Compare October 27, 2023 22:16
CONTRIBUTING.md Outdated
@@ -266,7 +266,7 @@ for review, which allows you to sidestep this issue.
This is not a bulletproof method though, as OfBorg still does review requests even on draft PRs.
```

## How to backport pull requests
## How to backport pull requests<a name="how-to-backport-pull-requests"></a>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## How to backport pull requests<a name="how-to-backport-pull-requests"></a>
## How to backport pull requests <a name="how-to-backport-pull-requests"></a>

When I add a space as suggested above then pandoc --to gfm adds a - at the end of the automatic id of the h2 tag. I assume pandoc behaves like github in this manner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i add the anchor below the title, then it gets put inside the p block

@pbsds
Copy link
Member Author

pbsds commented Oct 27, 2023

I did as suggested, but the results is not pretty to read in source. Perhaps a CI check that looks for dead links is the way to go?

EDIT: humble beginnings:

$ pandoc pkgs/README.md --from gfm --to html | htmlq a --attribute href | grep -E '\.md(#[a-z]+)?'
../CONTRIBUTING.md
./by-name/README.md
./by-name/README.md
./by-name/README.md
../CONTRIBUTING.md#commit-conventions
../CONTRIBUTING.md#file-naming
../CONTRIBUTING.md#commit-conventions
../CONTRIBUTING.md#how-to-backport-pull-requests
../CONTRIBUTING.md#how-to-backport-pull-requests

@infinisil
Copy link
Member

It would also be great for third-party documents to be able to link to anchors, but I guess for now something like that would be better than nothing

@pbsds
Copy link
Member Author

pbsds commented Oct 28, 2023

I've committed heinous crimes, but alas we do have a prototype:

{ pkgs ? import ./. {}
, lib ? pkgs.lib
}:

with pkgs;

let
  src = let
    toLink = path: {
      inherit path;
      name = lib.removePrefix "${toString ./.}/" (toString path);
    };
  in pkgs.linkFarm "nixpkgs-gfm-docs" (map toLink [
    ./CONTRIBUTING.md
    ./README.md
    ./doc/README.md
    ./lib/README.md
    ./lib/path/README.md
    ./maintainers/README.md
    ./nixos/README.md
    ./pkgs/README.md
    ./pkgs/by-name/README.md
    ./pkgs/test/nixpkgs-check-by-name/README.md
  ]);
in
  runCommand "test-nixpkgs-gfm-links" {
    nativeBuildInputs = [ htmlq pandoc ];
  } ''
    md2html() {
      local fname="$1" # relative to ${src}
      if test -f html-cache/"$fname"; then
        cat html-cache/"$fname"
      else
        mkdir -p "$(dirname html-cache/"$fname")"
        pandoc ${src}/"$fname" --from gfm --to html | tee html-cache/"$fname"
      fi
    }

    return_code=0

    shopt -s globstar
    for fname in ${src}/**/*.md; do
      fname="''${fname#${src}/}" # strip nix store prefix

      get_links() (
        set +o pipefail
        md2html "$fname" \
          | htmlq a --attribute href --base file:///"$fname" \
          | grep '^file:///' \
          | cut -d/ -f4- \
          | grep -E '\.md(#.*)?$' \
          | sort -u
      )

      while IFS=# read target anchor; do
        if ! test -f ${src}/"$target"; then
          >&2 echo "ERROR ($fname): resolved reference not found: $target"
          return_code=1
          continue
        fi

        test -n "$anchor" || continue

        if test -z "$(md2html "$target" | htmlq "#$anchor")"; then
          >&2 echo "ERROR ($fname): resolved reference not found: $target#$anchor"
          return_code=1
        fi
      done < <(get_links)

    done

    touch $out
    exit $return_code
  ''

Output:

test-nixpkgs-gfm-links> ERROR (CONTRIBUTING.md): resolved reference not found: CONTRIBUTING.md#backporting-changes
test-nixpkgs-gfm-links> ERROR (CONTRIBUTING.md): resolved reference not found: CONTRIBUTING.md#sec-package-naming
test-nixpkgs-gfm-links> ERROR (nixos/README.md): resolved reference not found: CONTRIBUTING.md#file-naming
test-nixpkgs-gfm-links> ERROR (pkgs/README.md): resolved reference not found: CONTRIBUTING.md#file-naming

The first two are genuine errors, and the last two are due to my code not handling name=... in addition to id=.... This could be fixed.

@pbsds pbsds force-pushed the contributing-link-naming-conventino branch from 06d00e3 to 669e8aa Compare October 28, 2023 18:09
@pbsds
Copy link
Member Author

pbsds commented Oct 28, 2023

I cleaned it up and pushed it as tests.nixpkgs-check-readme-links. I believe the way i phrase the src linkTree should avoids both any uneccesary rebuild, and globbing all of nixpkgs

@ofborg build tests.nixpkgs-check-readme-links

@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Oct 28, 2023
@pbsds pbsds force-pushed the contributing-link-naming-conventino branch from 669e8aa to f86a538 Compare October 28, 2023 19:17
@ofborg ofborg bot added 8.has: package (new) This PR adds a new package and removed 2.status: merge conflict This PR has merge conflicts with the target branch labels Oct 28, 2023
@infinisil
Copy link
Member

Nice! Though just recently I was pointed to https://github.com/serokell/xrefcheck, which looks a bit nicer 😅

In any case, could you do that in a separate PR? This way we can merge this one with just the doc improvements/fixes

@pbsds pbsds force-pushed the contributing-link-naming-conventino branch from f86a538 to 68686fb Compare November 8, 2023 00:58
pkgs/README.md Outdated Show resolved Hide resolved
pkgs/README.md Outdated Show resolved Hide resolved
@infinisil
Copy link
Member

Otherwise looking good!

@pbsds pbsds force-pushed the contributing-link-naming-conventino branch from 68686fb to 8feb68f Compare November 13, 2023 12:46
Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thanks!

@infinisil infinisil merged commit fdee770 into NixOS:master Nov 13, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants