CI, Python and projects

The last part takes the course outside one machine. A pipeline starts with the concepts and the two hosted services, then adds the cache, RuboCop, reports, images, releases, audits, secrets, a matrix, artifacts, security scans and a deploy. The comparison part writes the same programs in Python, and the projects put the whole course together: a log analyzer, a link checker, a CSV converter, a gem, a pipeline and two capstones.

13.1 What a CI pipeline is The idea behind continuous integration: the commands you run by hand, run on a fresh machine for every push, with stages, caches and artifacts. Open 13.2 Ruby in GitHub Actions A GitHub Actions workflow for a Ruby project: setup-ruby with bundler-cache, the test job, and the same two commands run by hand. Open 13.3 Ruby in GitLab CI A GitLab CI pipeline for a Ruby project: the ruby image, a cached bundle path, the test job, and the same commands run locally. Open 13.4 Rake as the pipeline runner Give the pipeline one entry point: a rake ci task with the test task as a prerequisite, listed by rake -T and called by both CI files. Open 13.5 Bundler and the cache Put the gems inside the project with bundle config set path vendor/bundle, see what bundler wrote, and cache the right folder in a pipeline. Open 13.6 RuboCop in the pipeline The first RuboCop run fails on the course project, so fix the config, the code and the Gemfile until the lint task passes, then gate the pipeline on it. Open 13.7 Test reports a pipeline can read Write Minitest results as JUnit XML with minitest-reporters, read the file the pipeline shows, and keep it as a build artifact. Open 13.8 Ruby in Docker images Package the project in a slim Ruby image: copy the Gemfile first, install the bundle without the development group, and run the tests inside the image. Open 13.9 Build and release a gem Turn the project into a gem: a version constant, a gemspec, gem build, a local install, and the push that publishes it. Open 13.10 Auditing dependencies Find outdated gems with bundle outdated and known vulnerabilities with bundler-audit, and make the audit a step of the pipeline. Open 13.11 Secrets in a pipeline Keep tokens out of the repository: masked CI variables, reading a secret without printing it, and the same variable in GitHub Actions and GitLab CI. Open 13.12 One job, several Ruby versions A CI matrix over two or three Ruby versions, how to read it back from the YAML, and a local check of the version a script needs. Open 13.13 Artifacts against caches A cache saves seconds on the next run, an artifact carries a result out of this one: the bundle cache, the test report, and both keys in one job. Open 13.14 Automated releases Release from a tag: keep the version in one file, check the tag against it with a Rake task, and let a tag-only job build and publish. Open 13.15 Making a pipeline fast Measure a Ruby pipeline before changing it: time the install and the tests, then split jobs, run them in parallel and fail fast for the right reasons. Open 13.16 Security scans Three cheap scans for a Ruby project: the advisory database for gems, a scan for hardcoded secrets, and Brakeman for a Rails application, with the exit codes that matter. Open 13.17 Deploying from a pipeline A health check script, a deploy job behind a manual gate, and the checks that tell a pipeline whether the new version is really up. Open 13.18 Ruby tools a pipeline runs Fastlane, Jekyll, Chef and Vagrant are Ruby programs that show up in pipelines; check their current versions on RubyGems and see what each one does. Open 13.19 A pipeline for a CLI gem Turn the course project into a command line gem, build and install it, and wire one pipeline that tests, lints, builds and releases on a tag. Open 13.20 A pipeline for a web API A tiny WEBrick API with a health route, a local run and health check, and the pipeline that tests it, builds an image and deploys behind a gate. Open 13.21 The same program in Ruby and Python A small program written twice, once in Ruby and once in Python, run side by side: blocks against indentation, interpolation against f-strings, truthiness. Open 13.22 Text and files in both Read a log, count the errors and write a report, once in Ruby and once in Python, with both real outputs and a short comparison of the file APIs. Open 13.23 HTTP and JSON in both One GET and one JSON parse against a local endpoint, in Ruby and in Python, with both outputs and a comparison of the standard library clients. Open 13.24 A CLI in both The same small command line tool with OptionParser and argparse: options, defaults, help text, error messages and exit codes compared. Open 13.25 Minitest against pytest The same class tested with Minitest and with pytest: assertions, test discovery, report lines and fixtures compared on real runs. Open 13.26 Gems against pip Package the same small library twice: a Gemfile, gemspec and lock file against a pyproject.toml, a virtual environment and an editable pip install. Open 13.27 Threads in both Four threads that wait on input, once in Ruby and once in Python: the GVL and the GIL, what threads are good for, and how the two runtimes compare on a timer. Open 13.28 The same task, measured One arithmetic loop timed in Ruby and in Python, the same algorithm in both, with an honest reading of what a single benchmark can and cannot say. Open 13.29 Capstone: todo CLI Build a small todo CLI with OptionParser, a JSON file store, and Minitest coverage. Open 13.30 Capstone: JSON API Build a tiny JSON API with WEBrick routes and handlers, then test it with Net HTTP. Open 13.31 Performance Measure with Benchmark, freeze string literals, cut garbage, and profile before optimizing. Open 13.32 Project: a log analyzer A small tool that reads an access log, counts the top paths and the status codes, prints a table or JSON, and has a test for the counting. Open 13.33 Project: a link checker A concurrent link checker for a list of URLs: threads, a deterministic report, and an exit code a pipeline can use, tested against a local server. Open 13.34 Project: CSV to JSON converter Read a CSV, check its headers, write pretty JSON, fail cleanly when a column is missing, and cover both paths with a test. Open 13.35 Project: package the CLI as a gem Turn the todo command into a gem: a version constant, a library, an executable, a gemspec, gem build, a local install and the commands it answers. Open 13.36 Project: a pipeline for your own project Take the log analyzer from lesson 13.32, give it a Rakefile that builds the gem, run the whole pipeline locally, and wire the same task into a workflow with a badge. Open

Lessons