diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd50c41..e98e988 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,6 +98,7 @@ jobs: zip -r simplecov.zip coverage; RESPONSE=$(curl -X POST https://flaky.xyz/api/reports/simplecov \ -F "part=@simplecov.zip" \ + -F "branch=${{ github.head_ref || github.ref_name }}" \ -H "Authorization: Bearer ${{ secrets.FLAKY_XYZ_TOKEN }}"); echo $RESPONSE; echo "MARKDOWN=$(echo $RESPONSE | jq -r '.markdown')" >> $GITHUB_OUTPUT; diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..02507e9 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +precommit: + rubocop + rails test test/** diff --git a/README.md b/README.md index 8ae9fd2..c293a04 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ This is a project to simplify collection and analysis of CI results. - [x] Be able to upload and see SimpleCov HTML reports. - [ ] Update instructions with the working version from the monorepo. -- [ ] Report Rspec test coverage along the time. +- [ ] Report Rspec test coverage along the time, per-branch. - [ ] Be able to upload and see Sorbet's Spoom HTML reports. - [ ] Report Sorbet typing along the time. -- [ ] Be able to track failing specs, and analyze which could be flaky in need of some help. +- [ ] Be able to track failing specs, and analyze which could be flaky in need of some extra attention. ## Development environment @@ -68,6 +68,7 @@ your-existing-test-action-on-github: -F "part=@simplecov.zip" \ -F "expected_parts=1" \ -F "run_identifier=${{ github.run_id }}" \ + -F "branch=${{ github.head_ref || github.ref_name }}" \ -H "Authorization: Bearer ${{ secrets.FLAKY_XYZ_TOKEN }}"); echo "MARKDOWN=$(echo $RESPONSE | jq -r '.markdown')" >> $GITHUB_OUTPUT; diff --git a/app/controllers/api/reports_controller.rb b/app/controllers/api/reports_controller.rb index e4b4c83..e50b934 100644 --- a/app/controllers/api/reports_controller.rb +++ b/app/controllers/api/reports_controller.rb @@ -41,11 +41,13 @@ def report current_project.with_lock do # Prevent race-condition on many parts of the same run being uploaded close together. run_identifier = params[:run_identifier].presence || Time.zone.now.iso8601 + branch = params[:branch].presence || "main" record = Report.find_or_create_by!( organization: current_project.organization, project: current_project, kind: action_name, - run_identifier: + run_identifier:, + branch:, ) end end diff --git a/test/controllers/api/reports_controller_test.rb b/test/controllers/api/reports_controller_test.rb index 0f56feb..28abaf4 100644 --- a/test/controllers/api/reports_controller_test.rb +++ b/test/controllers/api/reports_controller_test.rb @@ -2,33 +2,44 @@ class Api::FilesControllerTest < ActionDispatch::IntegrationTest def setup - @organization = Organization.create!(handle: "test-organization") - @project = Project.create!(handle: "test-project", organization: @organization) - @token = @project.reset_api_auth! - end - - def teardown - Report.all.each(&:destroy) - Project.all.each(&:destroy) - Organization.all.each(&:destroy) - ActiveStorage::Blob.all.each(&:purge) - end + organization = Organization.create!(handle: "test-organization") + @project = Project.create!(handle: "test-project", organization:) + token = @project.reset_api_auth! - test "simplecov zip upload creates and processes Report" do - headers = { Authorization: "Bearer #{@token}" } - uploaded_file = fixture_file_upload( + @headers = { Authorization: "Bearer #{token}" } + @part = fixture_file_upload( Rails.root.join("test/fixtures/files/user_model_coverage.zip"), "application/zip" ) + end + test "simplecov zip upload creates and processes Report" do assert_equal(Report.count, 0) - post simplecov_api_reports_url, params: { part: uploaded_file }, headers: headers + params = { part: @part } + post simplecov_api_reports_url, params:, headers: @headers assert_response :created assert_equal(Report.count, 1) - assert_equal(Report.first.parts.count, 1) - assert_equal(Report.first.bundled_html.present?, true) - assert_equal(Report.first.formatted_coverage, "3.47%") + + report = Report.first + assert_equal(report.organization, @project.organization) + assert_equal(report.project, @project) + assert_equal(report.parts.count, 1) + assert_equal(report.bundled_html.present?, true) + assert_equal(report.formatted_coverage, "3.47%") + assert_equal(report.branch, "main") + end + + test "with custom run_identfier and branch" do + params = { part: @part, run_identifier: "custom-run", branch: "custom-branch" } + post simplecov_api_reports_url, params:, headers: @headers + + assert_response :created + assert_equal(Report.count, 1) + + report = Report.first + assert_equal(report.run_identifier, "custom-run") + assert_equal(report.branch, "custom-branch") end end