From b6eb3b2efb8dd4f408702d034dad8fc0e19c35d6 Mon Sep 17 00:00:00 2001 From: Samuel Giles Date: Sat, 11 Mar 2023 19:06:28 +0000 Subject: [PATCH] Update CI to work outside of `github.com/bellroy` --- .github/workflows/ci.yml | 92 +++++-------------- .rubocop.yml | 66 ------------- Gemfile | 2 +- bin/rspec | 27 ++++++ bin/rubocop | 27 ++++++ nix/sources.json | 14 --- nix/sources.nix | 194 --------------------------------------- run_ci.sh | 7 -- shell.nix | 20 ---- spec/spec_helper.rb | 13 +-- 10 files changed, 81 insertions(+), 381 deletions(-) create mode 100755 bin/rspec create mode 100755 bin/rubocop delete mode 100644 nix/sources.json delete mode 100644 nix/sources.nix delete mode 100755 run_ci.sh delete mode 100644 shell.nix diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63dc19d..2eb374d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,74 +1,24 @@ ---- name: Continuous Integration -env: - SLACK_CHANNEL_ID: C0317P7C9C2 -on: - push: - branches-ignore: - - refs/tags/*_staging - - refs/tags/*_production + +on: push + +permissions: + contents: read + jobs: - build: - runs-on: ubuntu-20.04 + test: + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: ['3.1'] steps: - - name: Checkout branch - # Pin to v3.1.0 SHA - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - - name: Extract branch name - shell: bash - run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT - id: extract_branch - - name: Cache gems - # Pin to 3.0.11 SHA - uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 - with: - path: vendor/bundle - key: "${{ runner.OS }}-gem-cache-${{ hashFiles('**/*.gemspec') - }}" - restore-keys: "${{ runner.OS }}-gem-cache-\n" - # Pin to the v18 SHA - - uses: "cachix/install-nix-action@daddc62a2e67d1decb56e028c9fa68344b9b7c2a" - with: - extra_nix_config: | - post-build-hook = /etc/nix/upload-to-cache.sh - substituters = https://cache.nixos.org/ - trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= - nix_path: nixpkgs=channel:nixos-22.05 - install_url: https://releases.nixos.org/nix/nix-2.7.0/install - - name: Run CI through nix-shell - env: - GEMFURY_DEPLOY_TOKEN: ${{ secrets.GEMFURY_DEPLOY_TOKEN }} - run: nix-shell --run "chmod 755 ./run_ci.sh && ./run_ci.sh" - - name: Post to Slack if build fails - if: failure() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/stable') - # Pin to the v1.23.0 SHA - uses: slackapi/slack-github-action@007b2c3c751a190b6f0f040e47ed024deaa72844 - env: - SLACK_BOT_TOKEN: "${{ secrets.BELLROY_SLACK_TOKEN }}" - with: - channel-id: "${{ env.SLACK_CHANNEL_ID }}" - payload: | - { - "text": "* ${{ github.repository }} BUILD FAILURE*", - "attachments": [ - { - "fallback": "Failure summary", - "color": "ff0000", - "fields": [ - { - "title": "Branch", - "value": "${{ steps.extract_branch.outputs.branch}}" - }, - { - "title": "Who broke it", - "value": "${{ github.actor }}" - }, - { - "title": "Build output", - "value": "https://github.com/${{ github.repository }}/commit/${{ github.sha }}/checks", - "short": false - } - ] - } - ] - } + - uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + - name: Run RSpec tests + run: bin/rspec + - name: Check for Rubocop offenses + run: bin/rubocop --format github diff --git a/.rubocop.yml b/.rubocop.yml index 2af7e1d..e69de29 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,66 +0,0 @@ ---- -Documentation: - Enabled: false -Rails: - Enabled: true -AllCops: - Include: - - app/**/*.rb - - lib/**/*.rb - - spec/**/*.rb - Exclude: - - app/assets/**/* - - bin/**/* - - client/node_modules/**/* - - config/**/* - - coverage/**/* - - data/**/* - - db/**/* - - db_*/**/* - - dw/**/* - - log/**/* - - phrase/**/* - - public/**/* - - tmp/**/* - - vendor/**/* - TargetRubyVersion: 2.5 -Metrics/LineLength: - Max: 100 -Layout/MultilineMethodCallIndentation: - EnforcedStyle: indented -Style/PercentLiteralDelimiters: - PreferredDelimiters: - "%w": "[]" -RSpec/ExampleLength: - Enabled: false - Max: 10 -RSpec/MultipleExpectations: - Enabled: false - Max: 10 -RSpec/NestedGroups: - Enabled: false - Max: 10 -RSpec/MessageExpectation: - Enabled: false -RSpec/MissingExampleGroupArgument: - Enabled: false -require: -- rubocop-performance -- rubocop-rspec -- test_prof/rubocop -Metrics/BlockLength: - Enabled: false -RSpec/MessageSpies: - Enabled: false -RSpec/ExpectInHook: - Enabled: false -RSpec/AggregateFailures: - Enabled: true - Include: - - spec/**/*.rb -Rails/InverseOf: - Enabled: false -Rails/Present: - Enabled: false -Rails/TimeZone: - Enabled: false diff --git a/Gemfile b/Gemfile index 526de59..292f155 100644 --- a/Gemfile +++ b/Gemfile @@ -17,5 +17,5 @@ end group :test do gem 'ffaker' - gem 'simplecov' + gem 'rspec-github', require: false end diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 0000000..757e79b --- /dev/null +++ b/bin/rspec @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..2b1fa1f --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rubocop' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rubocop", "rubocop") diff --git a/nix/sources.json b/nix/sources.json deleted file mode 100644 index 2bcb623..0000000 --- a/nix/sources.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "nixpkgs": { - "branch": "nixos-22.05", - "description": "Nix packages collection", - "homepage": "https://github.com/NixOS/nixpkgs", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "1935dd8fdab8e022a9d958419663162fd840014c", - "sha256": "1z0nkqpwahlaz362lcdx5qcdvwdzr5a3bdfirjgbf9jg37rsbwl2", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/1935dd8fdab8e022a9d958419663162fd840014c.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/nix/sources.nix b/nix/sources.nix deleted file mode 100644 index 9a01c8a..0000000 --- a/nix/sources.nix +++ /dev/null @@ -1,194 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - if spec ? ref then spec.ref else - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; - submodules = if spec ? submodules then spec.submodules else false; - submoduleArg = - let - nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; - emptyArgWithWarning = - if submodules == true - then - builtins.trace - ( - "The niv input \"${name}\" uses submodules " - + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " - + "does not support them" - ) - {} - else {}; - in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; - in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import {} - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/run_ci.sh b/run_ci.sh deleted file mode 100755 index 8234a28..0000000 --- a/run_ci.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -set -e -rm -f Gemfile.lock -bundle config gem.fury.io $GEMFURY_DEPLOY_TOKEN -bundle install -bundle exec srb tc -METRICS=1 bundle exec rspec spec diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 9551777..0000000 --- a/shell.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ sources ? import ./nix/sources.nix }: -let - nixpkgs = import sources.nixpkgs { }; -in -nixpkgs.mkShell { - name = "bellroy-gem-env"; - buildInputs = with nixpkgs; [ - bundler - libnotify - niv - pkg-config - readline - ruby_2_7 - zlib - ] - ++ (if stdenv.hostPlatform.isDarwin then [ libiconv darwin.apple_sdk.frameworks.CoreServices ] else [ ]); - shellHook = '' - bundle config --local path "$PWD/vendor/bundle" - ''; -} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e2952c5..a4c2763 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,14 +1,6 @@ # typed: strict # frozen_string_literal: true -if !ENV['METRICS'].nil? || !ENV['COVERAGE'].nil? - require 'simplecov' - SimpleCov.at_exit do - SimpleCov.result.format! - end - SimpleCov.start -end - require 'pry' require 'bundler/setup' @@ -16,6 +8,11 @@ # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = '.rspec_status' + if ENV['GITHUB_ACTIONS'] == 'true' + require 'rspec/github' + config.add_formatter RSpec::Github::Formatter + end + RSpec::Expectations.configuration.on_potential_false_positives = :nothing # Disable RSpec exposing methods globally on `Module` and `main` # config.disable_monkey_patching!