Git Product home page Git Product logo

test-collector-swift's Introduction

Buildkite Test Collector for Swift (Beta)

Official Buildkite Test Analytics collector for Swift test frameworks โœจ

โš’ Supported test frameworks: XCTest, and more coming soon.

๐Ÿ“ฆ Supported CI systems: Buildkite, GitHub Actions, CircleCI, Xcode Cloud, and others via the BUILDKITE_ANALYTICS_* environment variables.

๐Ÿ‘‰ Installing

Step 1

Create a test suite, and copy the API token that it gives you.

Swift Package Manager

To use the Buildkite Test Collector with a SwiftPM project, add this repository to the Package.swift manifest and add BuildkiteTestCollector to any test target requiring analytics:

let package = Package(
  name: "MyProject",
  dependencies: [
    .package(url: "https://github.com/buildkite/test-collector-swift", from: "0.4.0")
  ],
  targets: [
    .target(name: "MyProject"),
    .testTarget(
      name: "MyProjectTests",
      dependencies: [
        "MyProject",
        .product(name: "BuildkiteTestCollector", package: "test-collector-swift")
      ]
    )
  ]
)

Step 2

Set the BUILDKITE_ANALYTICS_TOKEN secret on your CI to the API token from earlier.

Step 3

If you're testing an Xcode project there's an extra step, Xcode doesn't pass environment variables from the process to the test runner so we need to manually map them. Open your test scheme or test plan(whichever you are using) and under the environment variable section add the following entry:

key: BUILDKITE_ANALYTICS_TOKEN

value: $(BUILDKITE_ANALYTICS_TOKEN)

The same key value pair can be specified in your main bundle's info.plist file if you would rather specify it there. Note variables in the environment take precedent over those in the info.plist file.

Step 3.5 (Optional)

The only required environment variable is the analytics token but if you're using one of the supported CI platforms they can pass extra information to the test-collector to enrich the reports. Things like commit messages, branch names, build numbers, etc. Open your test scheme or test plan again and add the following key value pairs depending on your CI platform.

Buildkite

Key: BUILDKITE_BUILD_ID, Value: $(BUILDKITE_BUILD_ID)
Key: BUILDKITE_BUILD_URL, Value: $(BUILDKITE_BUILD_URL)
Key: BUILDKITE_BRANCH, Value: $(BUILDKITE_BRANCH)
Key: BUILDKITE_COMMIT, Value: $(BUILDKITE_COMMIT)
Key: BUILDKITE_BUILD_NUMBER, Value: $(BUILDKITE_BUILD_NUMBER)
Key: BUILDKITE_JOB_ID, Value: $(BUILDKITE_JOB_ID)
Key: BUILDKITE_MESSAGE, Value: $(BUILDKITE_MESSAGE)

Circle CI

Key: CIRCLE_BUILD_NUM, Value: $(CIRCLE_BUILD_NUM)
Key: CIRCLE_WORKFLOW_ID, Value: $(CIRCLE_WORKFLOW_ID)
Key: CIRCLE_BUILD_URL, Value: $(CIRCLE_BUILD_URL)
Key: CIRCLE_BRANCH, Value: $(CIRCLE_BRANCH)
Key: CIRCLE_SHA1, Value: $(CIRCLE_SHA1)

GitHub Actions

Key: GITHUB_ACTION, Value: $(GITHUB_ACTION)
Key: GITHUB_REF_NAME, Value: $(GITHUB_REF_NAME)
Key: GITHUB_RUN_NUMBER, Value: $(GITHUB_RUN_NUMBER)
Key: GITHUB_RUN_ATTEMPT, Value: $(GITHUB_RUN_ATTEMPT)
Key: GITHUB_REPOSITORY, Value: $(GITHUB_REPOSITORY)
Key: GITHUB_RUN_ID, Value: $(GITHUB_RUN_ID)
Key: GITHUB_SHA, Value: $(GITHUB_SHA)
Key: GITHUB_WORKFLOW, Value: $(GITHUB_WORKFLOW)
Key: GITHUB_ACTOR, Value: $(GITHUB_ACTOR)

Xcode Cloud

Key: CI_COMMIT, Value: $(CI_COMMIT)
Key: CI_BUILD_NUMBER, Value: $(CI_BUILD_NUMBER)
Key: CI_BUILD_ID, Value: $(CI_BUILD_ID)
Key: CI_WORKFLOW, Value: $(CI_WORKFLOW)
Key: CI_BRANCH, Value: $(CI_BRANCH)
Key: CI_PULL_REQUEST_HTML_URL, Value: $(CI_PULL_REQUEST_HTML_URL)

The same key value pairs can be specified in your main bundle's info.plist file if you would rather specify them there. Note variables in the environment take precedent over those in the info.plist file.

Step 4

Push your changes to a branch, and open a pull request. After a test run has been triggered, results will start appearing in your analytics dashboard.

git checkout -b add-buildkite-test-analytics
git commit -am "Add Buildkite Test Analytics"
git push origin add-buildkite-test-analytics

๐Ÿ” Debugging

To enable debugging output, set the BUILDKITE_ANALYTICS_DEBUG_ENABLED environment variable to true. This also needs to be set in your test scheme or test plan if you're using an Xcode project.

The library uses the presence/absence of certain environment variables to determine which CI platform it's running on, if you turn on debugging you'll see the library looking and not finding some of these keys, this is intended behaviour. Failing to find the values for your CI platform would indicate an issue though.

๐Ÿ”œ Roadmap

See the GitHub 'enhancement' issues for planned features. Pull requests are always welcome, and weโ€™ll give you feedback and guidance if you choose to contribute ๐Ÿ’š

๐Ÿ‘ฉโ€๐Ÿ’ป Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/buildkite/test-collector-swift

๐Ÿ“œ License

The package is available as open source under the terms of the MIT License.

test-collector-swift's People

Contributors

iampatbrown avatar jamesw-ios avatar katiewright26 avatar amybiyuliu avatar bjhomer avatar mokagio avatar blaknite avatar juanitofatas avatar marcosgriselli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.