Skip to content

Commit 454ca28

Browse files
authored
Merge pull request #5 from antifuchs/github-token-input
Add github token action parameter
2 parents 54a4026 + 08c30f2 commit 454ca28

File tree

5 files changed

+124
-3
lines changed

5 files changed

+124
-3
lines changed

.github/workflows/docs.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "docs"
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- "latest"
7+
8+
jobs:
9+
check-docs:
10+
name: Verify docs are up-to-date
11+
runs-on: ubuntu-24.04
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
15+
- name: (Setup Lix with this action...)
16+
uses: ./
17+
18+
- name: Check docs are up-to-date
19+
shell: bash
20+
run: |
21+
(
22+
PS4=" $ "
23+
set -eux -o pipefail
24+
export LC_CTYPE=en_US.UTF-8
25+
support/update-readme.rb --check
26+
)

README.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,23 @@ Some differences:
1414
- We use the `channel:` ref to Nixpkgs instead of the `flake:` ref, as the `flake:` ref may have issues within the GHA ecosystem, regarding rate-limiting.
1515
- We configure the current user as a trusted user.
1616

17-
No options.
18-
1917
* * *
2018

19+
Configuring the action
20+
----------------------
21+
22+
<!-- ACTION.YML INPUTS START -->
23+
24+
### `github_access_token`
25+
26+
A github token that is added as an entry on extra-access-tokens in nix.conf.
27+
28+
By default, the `github.token` is configured. See https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
29+
for a description of the default token's permissions.
30+
31+
32+
<!-- ACTION.YML INPUTS END -->
33+
34+
---
35+
2136
<sup>1</sup>: And checks Nix is available, and also wraps with error reporting...

action.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
name: Lix GHA Installer Action
2-
description: Simple action to install Lix (the independent variant of the Nix package manager).
2+
description: Simple action to install Lix (the independent variant of the Nix package manager).
3+
inputs:
4+
github_access_token:
5+
description: |
6+
A github token that is added as an entry on extra-access-tokens in nix.conf.
7+
8+
By default, the `github.token` is configured. See https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
9+
for a description of the default token's permissions.
310
runs:
411
using: "composite"
512
steps:
613
- name: Install Lix
714
run: bash ${{ github.action_path }}/do-the-lix-thing
815
shell: bash
16+
env:
17+
INPUT_GITHUB_ACCESS_TOKEN: "${{inputs.github_access_token}}"
18+
GITHUB_TOKEN: "${{github.token}}"

do-the-lix-thing

+7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ curl -sSf -L https://install.lix.systems/lix | bash -s -- install --no-confirm
130130

131131
(
132132
< /etc/nix/nix.conf sed -e 's/nixpkgs=flake:nixpkgs/nixpkgs=channel:nixos-unstable/'
133+
if [ -z "${INPUT_GITHUB_ACCESS_TOKEN:-}" ]; then
134+
echo "Configuring default github access token" >&2
135+
printf "extra-access-tokens = github.com=%s\n" "${GITHUB_TOKEN}"
136+
else
137+
echo "Configuring custom github access token" >&2
138+
printf "extra-access-tokens = github.com=%s\n" "${INPUT_GITHUB_ACCESS_TOKEN}"
139+
fi
133140
printf "trusted-users = root %s\n" "${USER:-}"
134141
) > tmp.conf
135142
sudo mv -v tmp.conf /etc/nix/nix.conf

support/update-readme.rb

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env nix-shell
2+
#!nix-shell -p ruby
3+
#!nix-shell -i ruby
4+
5+
require "yaml"
6+
7+
CHECK = ARGV.include?("--check")
8+
9+
def marker(which, direction)
10+
"<!-- ACTION.YML #{which.upcase} #{direction.upcase} -->"
11+
end
12+
13+
def replace_markers(str, which, content)
14+
str.gsub(
15+
%r{#{marker(which, "start")}.*#{marker(which, "end")}}m,
16+
[
17+
marker(which, "start"),
18+
"",
19+
content,
20+
"",
21+
marker(which, "end"),
22+
].join("\n")
23+
)
24+
end
25+
26+
TOP = File.join(__dir__(), "..")
27+
README = File.join(TOP, "README.md")
28+
ACTION = File.join(TOP, "action.yml")
29+
30+
action_data = YAML.load(File.read(ACTION))
31+
formatted_inputs = action_data["inputs"].map do |key, data|
32+
[
33+
"### `#{key}`",
34+
if data["default"] then [
35+
"",
36+
"*Default: `#{data["default"]}`*",
37+
] else [] end,
38+
"",
39+
data["description"]
40+
].flatten().join("\n")
41+
end.join("\n\n")
42+
43+
readme = File.read(README)
44+
new_contents = replace_markers(readme, "inputs", formatted_inputs)
45+
46+
unless readme == new_contents
47+
if CHECK
48+
message = [
49+
"NOTE: generated README sections differ from current README.",
50+
" run support/update-readme.rb to update, and then make a new commit.",
51+
].join("\n")
52+
$stderr.puts ""
53+
$stderr.puts %Q{::error title="Documentation is not up-to-date!"::#{message.gsub("\n", "%0A")}}
54+
$stderr.puts ""
55+
$stderr.puts message
56+
exit 1
57+
else
58+
File.write(README, new_contents)
59+
end
60+
end
61+
62+
63+
#vim ft=ruby

0 commit comments

Comments
 (0)