Skip to content

Commit

Permalink
save custom branch to report
Browse files Browse the repository at this point in the history
  • Loading branch information
evsasse committed Dec 23, 2024
1 parent 692eff8 commit 1de42a5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ jobs:
zip -r simplecov.zip coverage;
RESPONSE=$(curl -X POST https://flaky.xyz/api/reports/simplecov \
-F "[email protected]" \
-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;
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
precommit:
rubocop
rails test test/**
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -68,6 +68,7 @@ your-existing-test-action-on-github:
-F "[email protected]" \
-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;
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/api/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 29 additions & 18 deletions test/controllers/api/reports_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1de42a5

Please sign in to comment.