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

Set up GitHub Actions CI on this repository #387

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
@@ -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.
98 changes: 98 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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 }}
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

[compat]
Documenter = "~0.23"
21 changes: 13 additions & 8 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -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")
44 changes: 36 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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
8 changes: 0 additions & 8 deletions test/server.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,5 +25,3 @@ end

@test parse_comment("register branch=foo branch=bar") == (nothing, nothing)
end

end
18 changes: 18 additions & 0 deletions test/util.jl
Original file line number Diff line number Diff line change
@@ -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
62 changes: 39 additions & 23 deletions test/webui.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
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",
"port" => 4000,
"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" => "",
),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
12 changes: 1 addition & 11 deletions test/webui/gitutils.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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")

Expand Down Expand Up @@ -106,5 +98,3 @@ end
end
end
end

end