Closed a-t-0 closed 2 years ago
The following test from test_run_ci_on_github_repo.bats
can be used to test if it works:
# TODO: write test that verifies this works on a new clean/empty repo.
# TODO: make this run after the loop over github branches.
@test "Test pushing GitHub commit build status to repo with build statusses is successful." {
local github_username="a-t-0"
local github_repo_name="sponsor_example"
local github_branch_name="main"
local github_commit_sha="85ad4b39fe9c9af893b4d7b35a76a595a8e680d5"
copy_commit_build_status_to_github_status_repo "$github_username" "$github_repo_name" "$github_branch_name" "$github_commit_sha" "success"
# TODO: write asserts
# Assert svg file is created correctly
assert_equal $(file_exists "$MIRROR_LOCATION/GitHub/$GITHUB_STATUS_WEBSITE_GLOBAL"/"$github_repo_name"/"$github_branch_name""/build_status.svg") "FOUND"
# Assert GitHub commit build status txt file is created correctly
assert_equal $(file_exists "$MIRROR_LOCATION/GitHub/$GITHUB_STATUS_WEBSITE_GLOBAL"/"$github_repo_name"/"$github_branch_name""/$github_commit_sha.txt") "FOUND"
# Assert GitHub commit build status txt file contains the right data.
assert_equal $(cat "$MIRROR_LOCATION/GitHub/$GITHUB_STATUS_WEBSITE_GLOBAL"/"$github_repo_name"/"$github_branch_name""/$github_commit_sha.txt") "success"
push_commit_build_status_in_github_status_repo_to_github "$github_username"
assert_success
# Delete GitHub build status repository after test.
sudo rm -r "$MIRROR_LOCATION/GitHub/$GITHUB_STATUS_WEBSITE_GLOBAL"
assert_file_not_exist "$MIRROR_LOCATION/GitHub/$GITHUB_STATUS_WEBSITE_GLOBAL"
}
However, most likely a dedicated test would be better.
Since there is no need to create a new repository, there is also no need to delete any repository. This means a GitHub deploy key with push access to GitHub should be sufficient to complete the objective. This objective is to push the build status to the GitHub build status repo.
The tests to get the build statuses and to determine whether those build statuses are pushed correctly, already exist. So the thing that is being built and tested here is the automatic creation of a deploy key for a particular Github repository. That repository is in this case hard-coded in: src/hardcoded_variables.txt
. It has the name:
GITHUB_STATUS_WEBSITE_GLOBAL=gitlab-ci-build-statuses
Solution:
[x] Verify the GITHUB_STATUS_WEBSITE_GLOBAL=gitlab-ci-build-statuses
repository exists.
./install_gitlab.sh -s -r
again.[x] Ensure no deploy key exists:
[x] Assert no deploy key exists
[x] Get the https://github.com/a-t-0/get-gitlab-runner-registration-token repository.
[ ] Pass it an argument that lets it know it should not get the GitLab runner token, but create a GitHub deploy token instead.
[ ] Let that code open the GItHub website at: github.com/$GLOBAL_GITHUB_USERNAME/$GITHUB_STATUS_WEBSITE_GLOBAL
.
[ ] Let it login
[ ] Verify if the deploy key is able to push to the repository:
test_boolean_false.txt
test_boolean_true.txt
test_boolean_false.txt
Either set up ssh-access, or generate a personal access token (Ideally for a particular repository) to allow:
[ ] Repo creation access.
A test to test this functionality could/should:
Issue: If you do not want to create a personal access token that can delete GitHub repositories, you cannot repeatedly recreate the same repository anew (without deleting it manually).
Option A.:
A temporary solution could be to create a test-organisation and to allow it to fill up to 100 repos with name:
testname0,testname1,...99
before throwing an error asking the user to manually delete the repos. (perhaps aided with a command to delete them all at once). Disadvantage:Option B.:
Disadvantage:
Advantage:
Option C.: Use specific deploy key to push to specific repository. Create that automatically instead. Assumption: can delete repo with deploy key. Status: unknown. Assumption: can create new repo with deploy key. Status: unknown.
Disadvantage:
Advantage:
Option D.: Automatically create personal access token to allow creating repo and pushing to repo. Then automatically create deploy key to delete that specific repository.
Advantage:
Disadvantage: