From 64e014320120bd1bb65a71dade67184ce528569f Mon Sep 17 00:00:00 2001 From: Gary Passero Date: Tue, 1 Nov 2022 08:59:40 -0400 Subject: [PATCH] Add ci and cd (#1) * Go green * Add CI/CD for GitHub actions --- .github/workflows/cd.yml | 40 +++++++++++++++++++++ .github/workflows/ci.yml | 46 ++++++++++++++++++++++++ Gemfile.lock | 58 +++++++++++++++++++++++++++++++ automatic_namespaces.gemspec | 30 +++++++--------- spec/automatic_namespaces_spec.rb | 4 --- 5 files changed, 156 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/ci.yml create mode 100644 Gemfile.lock diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..7d9308f --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,40 @@ +name: CD + +on: + # This ensures we only run CD after the CI workflow has completed on the main branch. + workflow_run: + workflows: [CI] + types: [completed] + branches: [main] +jobs: + deploy: + runs-on: ubuntu-latest + # We only want to run this if CI completes *sucessfully*, see more here: + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-a-workflow-based-on-the-conclusion-of-another-workflow + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - uses: actions/checkout@8230315d06ad95c617244d2f265d237a1682d445 + - name: Tag and Push Gem + id: tag-and-push-gem + # This action basically runs `bundle exec rake release` if there is not an existing tag in GitHub + # for the current version of the gem, found in the `gemspec`. + uses: discourse/publish-rubygems-action@2d713f2092b4f02da811f4b591a10b6b56f0780e + env: + # This is provided to GitHub Actions automatically – you do not need to add this secret. + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + # These are used when the CD workflow pushes new tags to your repository. + # Using tags helps people using your gem easily see changes between versions. + # To get this value, try: `git config --get user.email` + GIT_EMAIL: gpassero@gmail.com + # To get this value, try: `git config --get user.name` + GIT_NAME: Gary Passero + # Get this from rubygems.org and add it as a secret to your repository. + RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}} + - name: Create GitHub Release + # This creates a new release at https://github.com/rubyatscale/alexevanczuk-example-gem/releases, + # which serves as an automatically generated changelog. + run: gh release create v${{steps.tag-and-push-gem.outputs.gem_version}} --generate-notes + # We only create a release if the previous step has published a new version. + if: ${{ steps.tag-and-push-gem.outputs.new_version == 'true' }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0d60564 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,46 @@ +name: CI + +# This runs every time a new commit is pushed to GitHub. +on: [push] + +jobs: + rspec: + runs-on: ubuntu-latest + # We run our `rspec` tests on many versions of Ruby to ensure compatibility. + strategy: + matrix: + ruby: + - 2.7 + # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0' + - '3.0' + - 3.1 + - head + env: + BUNDLE_GEMFILE: Gemfile + name: "RSpec tests: Ruby ${{ matrix.ruby }}" + steps: + # This is an action from the public marketplace. We reference a specific commit as a security measure, + # but there are many ways to reference an action: + # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-versioned-actions + - uses: actions/checkout@8230315d06ad95c617244d2f265d237a1682d445 + - name: Set up Ruby ${{ matrix.ruby }} + uses: ruby/setup-ruby@eae47962baca661befdfd24e4d6c34ade04858f7 + with: + # This caches the gems that bundle installs so subsequent runs can be faster. + # It is what allows us to not run `gem install bundler` and `bundle install` in subsequent steps. + bundler-cache: true + ruby-version: ${{ matrix.ruby }} + - name: Run tests + run: bundle exec rspec + rubocop: + runs-on: ubuntu-latest + name: Rubocop + steps: + - uses: actions/checkout@8230315d06ad95c617244d2f265d237a1682d445 + - name: Set up Ruby + uses: ruby/setup-ruby@eae47962baca661befdfd24e4d6c34ade04858f7 + with: + bundler-cache: true + ruby-version: head + - name: Run style checks + run: bundle exec rubocop \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..c367a9c --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,58 @@ +PATH + remote: . + specs: + automatic_namespaces (0.1.0) + +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + diff-lcs (1.5.0) + json (2.6.2) + parallel (1.22.1) + parser (3.1.2.1) + ast (~> 2.4.1) + rainbow (3.1.1) + rake (13.0.6) + regexp_parser (2.6.0) + rexml (3.2.5) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.0) + rubocop (1.38.0) + json (~> 2.3) + parallel (~> 1.10) + parser (>= 3.1.2.1) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.23.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.23.0) + parser (>= 3.1.1.0) + ruby-progressbar (1.11.0) + unicode-display_width (2.3.0) + +PLATFORMS + arm64-darwin-21 + x86_64-linux + +DEPENDENCIES + automatic_namespaces! + rake (~> 13.0) + rspec (~> 3.0) + rubocop (~> 1.21) + +BUNDLED WITH + 2.3.19 diff --git a/automatic_namespaces.gemspec b/automatic_namespaces.gemspec index 5b25381..72fdb4d 100644 --- a/automatic_namespaces.gemspec +++ b/automatic_namespaces.gemspec @@ -7,29 +7,23 @@ Gem::Specification.new do |spec| spec.version = AutomaticNamespaces::VERSION spec.authors = ["Gary Passero"] spec.email = ["gpassero@gmail.com"] - - spec.summary = "TODO: Write a short summary, because RubyGems requires one." - spec.description = "TODO: Write a longer description or delete this line." - spec.homepage = "TODO: Put your gem's website or public repo URL here." + spec.summary = "Modify autoloading to assume all files within a directory belong in a namespace" + spec.homepage = "https://github.com/gap777/automatic_namespaces" spec.license = "MIT" spec.required_ruby_version = ">= 2.6.0" - spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" - - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here." - spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." + if spec.respond_to?(:metadata) + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/alexevanczuk/my_example_gem" + spec.metadata["changelog_uri"] = "https://github.com/alexevanczuk/my_example_gem/releases" + spec.metadata["allowed_push_host"] = "https://rubygems.org" + else + raise "RubyGems 2.0 or newer is required to protect against " \ + "public gem pushes." + end # Specify which files should be added to the gem when it is released. - # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = Dir.chdir(__dir__) do - `git ls-files -z`.split("\x0").reject do |f| - (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) - end - end - spec.bindir = "exe" - spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.files = Dir["README.md", "lib/**/*"] # Uncomment to register a new dependency of your gem # spec.add_dependency "example-gem", "~> 1.0" diff --git a/spec/automatic_namespaces_spec.rb b/spec/automatic_namespaces_spec.rb index de49ae7..07d2dbf 100644 --- a/spec/automatic_namespaces_spec.rb +++ b/spec/automatic_namespaces_spec.rb @@ -4,8 +4,4 @@ it "has a version number" do expect(AutomaticNamespaces::VERSION).not_to be nil end - - it "does something useful" do - expect(false).to eq(true) - end end