Skip to content

Commit 2dd8848

Browse files
authored
CI: Use a custom token (non-fork PRs), or fall back to GITHUB_TOKEN (fork PRs) (#207)
1 parent add7161 commit 2dd8848

File tree

3 files changed

+56
-26
lines changed

3 files changed

+56
-26
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ jobs:
4242
${{ runner.os }}-
4343
- uses: julia-actions/julia-buildpkg@v1
4444
- uses: julia-actions/julia-runtest@v1
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
MY_CUSTOM_GITHUB_TOKEN: ${{ secrets.MY_CUSTOM_GITHUB_TOKEN }}
48+
# If there is a problem with MY_CUSTOM_GITHUB_TOKEN, please contact someone that has access to
49+
# subscriptions@julialang
50+
# Tell them that the +alias is +githubtestbot
4551
- uses: julia-actions/julia-processcoverage@v1
4652
- uses: codecov/codecov-action@v1
4753
with:

test/read_only_api_tests.jl

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# The below tests are network-dependent, and actually make calls to GitHub's
22
# API. They're all read-only, meaning none of them require authentication.
33

4-
testuser = Owner("julia-github-test-bot")
5-
testuser2 = Owner("julia-github-test-bot2")
4+
# testuser = Owner("julia-github-test-bot")
5+
# testuser2 = Owner("julia-github-test-bot2")
66
julweb = Owner("JuliaWeb", true)
77
ghjl = Repo("JuliaWeb/GitHub.jl")
88
testcommit = Commit("627128970bbf09d27c526cb66a17891c389ab914")
@@ -22,17 +22,37 @@ testuser2_sshkey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCkj86sSo36bkgv+gKp"*
2222

2323
hasghobj(obj, items) = any(x -> name(x) == name(obj), items)
2424

25-
# This token has public, read-only access, and is required so that our
26-
# tests don't get rate-limited. The only way a malicious party could do harm
27-
# with this token is if they used it to abuse the rate limit associated with
28-
# the token (not too big of a deal). The token is hard-coded in an obsfucated
29-
# manner in an attempt to thwart token-stealing crawlers.
30-
auth = authenticate(string(circshift(["bcc", "3fc", "03a", "33e",
31-
"c09", "363", "5f1", "bd3",
32-
"fc6", "77b", '5', "9cf",
33-
"868", "033"], 3)...))
25+
auth = nothing
26+
27+
names = [
28+
"MY_CUSTOM_GITHUB_TOKEN",
29+
"GITHUB_TOKEN",
30+
]
31+
for name in names
32+
global auth
33+
if auth === nothing
34+
if haskey(ENV, name)
35+
str = strip(ENV[name])
36+
if !isempty(str)
37+
@info "Trying token from $name"
38+
auth = authenticate(str)
39+
else
40+
@warn "The $name environment variable is defined, but it is empty or consists only of whitespace"
41+
end
42+
end
43+
end
44+
end
3445

35-
@test rate_limit(; auth = auth)["rate"]["limit"] == 5000
46+
if auth === nothing
47+
@warn "Using anonymous GitHub access. If you get rate-limited, please set the MY_CUSTOM_GITHUB_TOKEN or GITHUB_TOKEN env var to an appropriate value."
48+
auth = GitHub.AnonymousAuth()
49+
end
50+
51+
w = GitHub.whoami(; auth=auth)
52+
@info "" w w.login
53+
testuser = Owner(w.login)
54+
55+
@test rate_limit(; auth = auth)["rate"]["limit"] > 0
3656

3757
@testset "Owners" begin
3858
# test GitHub.owner
@@ -45,8 +65,8 @@ auth = authenticate(string(circshift(["bcc", "3fc", "03a", "33e",
4565
@test length(members) > 1
4666

4767
# test GitHub.followers, GitHub.following
48-
@test hasghobj("jrevels", first(followers(testuser; auth = auth)))
49-
@test hasghobj("jrevels", first(following(testuser; auth = auth)))
68+
@test_skip hasghobj("jrevels", first(followers(testuser; auth = auth))) # TODO FIXME: Fix these tests. https://github.com/JuliaWeb/GitHub.jl/issues/236
69+
@test_skip hasghobj("jrevels", first(following(testuser; auth = auth))) # TODO FIXME: Fix these tests. https://github.com/JuliaWeb/GitHub.jl/issues/236
5070

5171
# test GitHub.repos
5272
@test hasghobj(ghjl, first(repos(julweb; auth = auth)))
@@ -188,11 +208,11 @@ end
188208
@testset "Activity" begin
189209
# test GitHub.stargazers, GitHub.starred
190210
@test length(first(stargazers(ghjl; auth = auth))) > 10 # every package should fail tests if it's not popular enough :p
191-
@test hasghobj(ghjl, first(starred(testuser; auth = auth)))
211+
@test_skip hasghobj(ghjl, first(starred(testuser; auth = auth))) # TODO FIXME: Fix these tests. https://github.com/JuliaWeb/GitHub.jl/issues/237
192212

193213
# test GitHub.watched, GitHub.watched
194-
@test hasghobj(testuser, first(watchers(ghjl; auth = auth)))
195-
@test hasghobj(ghjl, first(watched(testuser; auth = auth)))
214+
@test_skip hasghobj(testuser, first(watchers(ghjl; auth = auth))) # TODO FIXME: Fix these tests. https://github.com/JuliaWeb/GitHub.jl/issues/237
215+
@test_skip hasghobj(ghjl, first(watched(testuser; auth = auth))) # TODO FIXME: Fix these tests. https://github.com/JuliaWeb/GitHub.jl/issues/237
196216
end
197217

198218
testbot_key =
@@ -321,4 +341,4 @@ end
321341
@test_throws ArgumentError GitHub.api_uri(GitHub.DEFAULT_API, "/repos/foo/../bar")
322342
@test_throws ArgumentError GitHub.api_uri(GitHub.DEFAULT_API, "/repos/foo/../bar")
323343
@test string(GitHub.api_uri(GitHub.DEFAULT_API, "/repos/foo/bar")) == "https://api.github.com/repos/foo/bar"
324-
end
344+
end

test/runtests.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ using Dates, Test, Base64
33
using GitHub: Branch, name
44
using GitHub.Checks
55

6-
include("ghtype_tests.jl")
7-
include("event_tests.jl")
8-
include("read_only_api_tests.jl")
9-
include("auth_tests.jl")
6+
@testset "GitHub.jl" begin
7+
8+
include("ghtype_tests.jl")
9+
include("event_tests.jl")
10+
include("read_only_api_tests.jl")
11+
include("auth_tests.jl")
12+
13+
@testset "SSH keygen" begin
14+
pubkey, privkey = GitHub.genkeys(keycomment="GitHub.jl")
15+
@test endswith(pubkey, "GitHub.jl")
16+
@test isa(privkey, String)
17+
end
1018

11-
@testset "SSH keygen" begin
12-
pubkey, privkey = GitHub.genkeys(keycomment="GitHub.jl")
13-
@test endswith(pubkey, "GitHub.jl")
14-
@test isa(privkey, String)
1519
end

0 commit comments

Comments
 (0)