From 0dc9472bbccbe745f9e818fec453f7bf26d7b5d9 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Sat, 27 Aug 2022 06:04:05 -0400 Subject: [PATCH 1/2] Set up GitHub Actions CI on this repository --- .github/workflows/ci.yml | 98 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 26 ----------- docs/Project.toml | 3 -- docs/make.jl | 21 +++++---- test/runtests.jl | 44 ++++++++++++++---- test/server.jl | 8 ---- test/util.jl | 18 ++++++++ test/webui.jl | 62 +++++++++++++++---------- test/webui/gitutils.jl | 12 +---- 9 files changed, 205 insertions(+), 87 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml create mode 100644 test/util.jl diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..5d5c38d509 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,98 @@ +name: CI +on: + pull_request: + push: + branches: + - master + tags: '*' +concurrency: + # Skip intermediate builds: all builds except for builds on the `master` branch + # Cancel intermediate builds: only pull request builds + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.ref != 'refs/heads/master' || github.run_number }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} +permissions: + contents: read +jobs: + test: + runs-on: ${{ matrix.os }} + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + version: + - '1.7' + - '1' + - 'nightly' + force_use_of_manifest: + - 'false' + os: + - ubuntu-latest + include: + - version: '1.7.2' + force_use_of_manifest: 'true' + os: 'ubuntu-latest' + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + - run: | + import Pkg + import TOML + force_use_of_manifest = ${{ matrix.force_use_of_manifest }} + if force_use_of_manifest + manifest = TOML.parsefile("Manifest.toml") + manifest_julia_version_str = manifest["julia_version"] + manifest_julia_version = VersionNumber(manifest_julia_version_str) + if manifest_julia_version != Base.VERSION + msg = "Manifest Julia version $(manifest_julia_version) does not match current Julia version $(Base.VERSION)" + error(msg) + end + else + @info "Deleting the manifest file" + rm("Manifest.toml") + end + shell: julia --color=yes {0} + - uses: julia-actions/julia-buildpkg@latest + - name: Run the package tests + run: | + import Pkg + force_use_of_manifest = ${{ matrix.force_use_of_manifest }} + allow_reresolve = !force_use_of_manifest + coverage = true + if allow_reresolve + force_latest_compatible_version = true + Pkg.test(; allow_reresolve, coverage, force_latest_compatible_version) + else + Pkg.test(; allow_reresolve, coverage) + end + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: julia --color=yes --project {0} + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v1 + with: + file: lcov.info + docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: '1' + - run: | + import Pkg + Pkg.develop(Pkg.PackageSpec(path=pwd())) + Pkg.instantiate() + Pkg.precompile() + shell: julia --color=yes --project=docs {0} + - name: Run the doctests + run: | + import Documenter + import Registrator + Documenter.doctest(Registrator) + shell: julia --color=yes --project=docs {0} + - run: julia --project=docs docs/make.jl + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c2c1a7b44e..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -# Documentation: http://docs.travis-ci.com/user/languages/julia/ -language: julia -os: - - linux - - osx -julia: - - 1.3 - - 1.4 - - nightly -matrix: - allow_failures: - - julia: nightly - fast_finish: true -notifications: - email: false -after_success: - - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' -jobs: - include: - - stage: "Documentation" - julia: 1.3 - os: linux - script: - - julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=".")); Pkg.instantiate()' - - julia --project=docs/ docs/make.jl - after_success: skip diff --git a/docs/Project.toml b/docs/Project.toml index 3fcbfb7d55..dfa65cd107 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,5 +1,2 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" - -[compat] -Documenter = "~0.23" diff --git a/docs/make.jl b/docs/make.jl index 43c1fe91f1..ae0cd65b7a 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,12 +1,17 @@ using Documenter using Registrator -makedocs(modules=[Registrator], - sitename="Registrator.jl", - pages=["Home" => "index.md", - "Hosting Your Own" => "hosting.md", - "Using Docker" => "docker.md", - "Comment Bot" => "commentbot.md", - "Web UI" => "webui.md"]) +makedocs( + modules = [Registrator], + sitename = "Registrator.jl", + pages = [ + "Home" => "index.md", + "Hosting Your Own" => "hosting.md", + "Using Docker" => "docker.md", + "Comment Bot" => "commentbot.md", + "Web UI" => "webui.md", + ], + # strict = true, # TODO: uncomment this line +) -deploydocs(repo="github.com/JuliaRegistries/Registrator.jl.git") +deploydocs(repo = "github.com/JuliaRegistries/Registrator.jl.git") diff --git a/test/runtests.jl b/test/runtests.jl index 6ff7784fc9..8de1f904b4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,15 +1,43 @@ +using Distributed +using Mocking using Test +using Dates: DateTime +using Logging: Logging +using HTTP: HTTP +using Sockets: Sockets + +using GitForge: GitForge, get_user +using GitForge: GitForge, GitHub, GitLab +using GitForge.GitHub: GitHub, GitHubAPI, NoToken, Token + +using Registrator: Registrator +using Registrator.CommentBot: make_trigger, parse_comment +using Registrator.WebUI: @gf +using Registrator.WebUI: isauthorized, AuthFailure, AuthSuccess, User + +const UI = Registrator.WebUI + +include("util.jl") + @testset "Registrator" begin + @testset "server" begin + include("server.jl") + end -include("server.jl") + @testset "webui/gitutils" begin + include("webui/gitutils.jl") + end -# Travis CI gets rate limited easily unless we have access to an API key. -if get(ENV, "TRAVIS", "") == "true" && !haskey(ENV, "GITHUB_API_TOKEN") - @info "Skipping web tests on Travis CI (credentials are unavailable)" -else - include("webui.jl") -end -include("webui/gitutils.jl") + @testset "webui" begin + if !haskey(ENV, "GITHUB_TOKEN") + msg = string( + "Note: we highly recommend that you run these tests with a ", + "`GITHUB_TOKEN` that has read-only access.", + ) + @warn msg + end + include("webui.jl") + end end diff --git a/test/server.jl b/test/server.jl index 86b7d3dacf..4ad3047d2d 100644 --- a/test/server.jl +++ b/test/server.jl @@ -1,9 +1,3 @@ -using Registrator.CommentBot: make_trigger, parse_comment - -using Test - -@testset "Server" begin - @testset "Trigger comment" begin trigger = make_trigger(Dict("trigger" => "@JuliaRegistrator")) @test match(trigger, "@JuliaRegistrator hi") !== nothing @@ -31,5 +25,3 @@ end @test parse_comment("register branch=foo branch=bar") == (nothing, nothing) end - -end diff --git a/test/util.jl b/test/util.jl new file mode 100644 index 0000000000..b7b91f3fd1 --- /dev/null +++ b/test/util.jl @@ -0,0 +1,18 @@ +function start_server( + port::Integer, + logger::Logging.AbstractLogger = Logging.current_logger(), + ) + # Start the server. + # TODO: Stop the server when the corresponding test set is done. + server_task = @async begin + Logging.with_logger(logger) do + UI.start_server(Sockets.localhost, port) + end + end + if Base.VERSION >= v"1.7-" + errormonitor(server_task) + end + @info "Starting the server..." + sleep(10) + return server_task +end diff --git a/test/webui.jl b/test/webui.jl index 42c139d9b7..8eb2c1c6f1 100644 --- a/test/webui.jl +++ b/test/webui.jl @@ -1,13 +1,3 @@ -using Registrator: Registrator -using Registrator.WebUI: @gf -using GitForge: GitForge, get_user -using GitForge.GitHub: GitHub, GitHubAPI, NoToken, Token -using HTTP: HTTP -using Sockets: Sockets -using Distributed - -const UI = Registrator.WebUI - empty!(UI.CONFIG) merge!(UI.CONFIG, Dict( "ip" => "localhost", @@ -15,8 +5,9 @@ merge!(UI.CONFIG, Dict( "registry_url" => "https://github.com/JuliaRegistries/General", "server_url" => "http://localhost:4000", "github" => Dict{String, Any}( - # We need a token to avoid rate limits on Travis. - "token" => get(ENV, "GITHUB_API_TOKEN", ""), + # Note: we highly recommend that you run these tests with a `GITHUB_TOKEN` + # that has read-only access. + "token" => get(ENV, "GITHUB_TOKEN", ""), "client_id" => "", "client_secret" => "", ), @@ -99,11 +90,7 @@ end restoreconfig!() end - # Start the server. - # TODO: Stop it when this test set is done. - task = @async UI.start_server(Sockets.localhost, 4000) - @info "Waiting for server to start..." - sleep(10) # Wait for server to be up + start_server(4000) @testset "404s" begin for r in values(UI.ROUTES) @@ -170,20 +157,49 @@ end @test resp.status == 400 @test occursin("Branch was not provided", String(resp.body)) - body = "package=https://github.com/JuliaLang/NotARealRepo&ref=master" - resp = HTTP.post(url; body=body, cookies=cookies, status_exception=false) - @test resp.status == 400 - @test occursin("Repository was not found", String(resp.body)) + example_github_repo = get(ENV, "GITHUB_REPOSITORY", "JuliaRegistries/Registrator.jl") - body = "package=http://github.com/JuliaLang/Example.jl&ref=master" + body = "package=http://github.com/$(example_github_repo)&ref=master" resp = HTTP.post(url; body=body, cookies=cookies, status_exception=false) @test resp.status == 400 @test occursin("Unauthorized to release this package", String(resp.body)) - body = "package=git@github.com:JuliaLang/Example.jl.git&ref=master" + body = "package=git@github.com:$(example_github_repo).git&ref=master" resp = HTTP.post(url; body=body, cookies=cookies, status_exception=false) @test resp.status == 400 @test occursin("Unauthorized to release this package", String(resp.body)) + + @testset "Repo that does not exist" begin + registrator_test_verbose_str = get(ENV, "JULIA_REGISTRATOR_TEST_VERBOSE", "false") + registrator_test_verbose = parse(Bool, registrator_test_verbose_str) + if registrator_test_verbose + logger = Logging.current_logger() + else + logger = Logging.NullLogger() + end + + # We start up a separate server just for this test. + # The reason that we have a separate server here is that we know that + # during this test, the server will print a very long warning because + # the GitHub API request returns 404. This warning is expected. However, + # it is quite verbose and makes the test logs harder to read. So, by + # default, for this server, we suppress the logs. + # + # If you want to show the logs for this server, set the `JULIA_REGISTRATOR_TEST_VERBOSE` + # environment variable to `true`. + start_server(4001, logger) + UI.CONFIG["port"] = 4001 + UI.CONFIG["server_url"] = "http://localhost:4001" + + url = UI.CONFIG["server_url"] * UI.ROUTES[:REGISTER] + body = "package=https://github.com/JuliaLang/NotARealRepo&ref=master" + resp = HTTP.post(url; body=body, cookies=cookies, status_exception=false) + @test resp.status == 400 + response_body = String(resp.body) + @test occursin("Repository was not found", response_body) + + restoreconfig!() + end end end diff --git a/test/webui/gitutils.jl b/test/webui/gitutils.jl index 71be1f46d7..05f26f5f88 100644 --- a/test/webui/gitutils.jl +++ b/test/webui/gitutils.jl @@ -1,9 +1,3 @@ -using Dates: DateTime -using Registrator.WebUI: isauthorized, AuthFailure, AuthSuccess, User -using GitForge: GitForge, GitHub, GitLab - -using Mocking - Mocking.activate() function patch_gitforge(body::Function; is_collaborator=false, is_member=false) @@ -13,14 +7,12 @@ function patch_gitforge(body::Function; is_collaborator=false, is_member=false) @patch GitForge.is_member(args...) = GitForge.Result{Bool}(is_member, nothing, nothing, stacktrace()) ] - + apply(patches) do return body() end end -@testset "gitutils" begin - @testset "isauthorized" begin @test isauthorized("username", "reponame") == AuthFailure("Unkown user type or repo type") @@ -106,5 +98,3 @@ end end end end - -end \ No newline at end of file From 8137037ab62f666eea64ec5b194ea5c09a113261 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Sat, 27 Aug 2022 08:33:56 -0400 Subject: [PATCH 2/2] Update .codecov.yml --- .codecov.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.codecov.yml b/.codecov.yml index db2472009c..a4e9ef8ebb 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1 +1,11 @@ -comment: off +comment: false # Disable the comment that is posted on pull requests. +coverage: + status: + patch: + default: + only_pulls: true # Only show the `codecov/patch` commit status on pull requests. + project: + default: + only_pulls: true # Only show the `codecov/project` commit status on pull requests. +github_checks: + annotations: false # Disable the annotations in the "Files Changed" view of a pull request.