Skip to content

Commit

Permalink
Add rspec-openapi gem and remove outdated rspec_api_documentation gem (
Browse files Browse the repository at this point in the history
…#472)

* Revert "Merge pull request #269 from rootstrap/feature/rspec-api-documentation-integration"

This reverts commit 84f3dbd, reversing
changes made to f01515f.

* Move featue-flags spec to /requests/admin

* Add rspec-openapi

* Initial doc

* Using seed 1993

* Freeze test data for docs

* Set docs with freezed data

* Freeze devise auth token

* Rubocop fixes

* Create update docs script. Add it to CI to check for missing doc changes

* Latest doc version

* Do not change password reset token in specs

* Fix code smell

* Test changes

* Make script trim whitespaces

* Add docs workflow. Make bin/update-docs parallel

* Remove docs from main CI

* Set when action runs

* Update label name

* Setup autolabeler

* Set new job for labeler

* Set new worflow for labeler

* Set condition for PR open

* New update doc

* Use new ruby script to update doc files

* Set rspec-openapi path to handle parallel specs

* Use new script and force to run with 8 cores

* Use bundle exec to run script

* Workflow fixes

* Remove trailing whitespace

* Run update-docs on push

* Update workflow

* Set cpu count for load schema

* Handle ocassional errors. Clean files always

* Fix parallel specs

* Clear whitespaces from doc file

* Remove update-docs bash file

* Update update-docs action

* Update README with doc

* Fix endpoint in spec

* Move CI docs to ci file

* Change labeler config

* Update labeler

* Fix labeler

* Move labeler to update docs action

* Update docs labeler test

* Use target

* Use token

* Run on merge with main or PR

* Fix labeler path

* Fix condition

* Small fixes

* README fixes

* Remove unused api blueprint file

* Clean up setup

* Add comment to initializer

* Rename action to check-docs

* Sort endpoints alphabetically

* Small improvements

* Update docs

* Make the default be parallelized

* Stop freezing time in specs, set dates with regex in doc file

* Update api_doc readme

* Freeze timestamps via regex and not specs

* Make doc check action run on pull_request and push on main

* Update Docs and README

* Use api_docs label

* Remove unnecessary configs

* Remove unnecessary permissions

* Freeze timestamps in update-docs

* Update rspec-openapi to v0.9

* Improve date freezing in script

* Improve api_docs readme

* Improve readme

* Only run openapi initializer in test

* Fix code climate for pull_request events

* Make the CI commit doc changes

* Rename update-docs script

* Make CI update docs with parallelization on main push

* Remove unnecessary canges to freeze test data

* Update README

* Remove changes from password spec

* Skip feature flags for openapi

* Update CI and docs

* Add push key to bypass branch protections

* Remove duplicate endpoints when merging docs

* Copy changes to docs and ci

* Remove duplicate permissions

* Document ignoring specs
  • Loading branch information
guillermoap authored Oct 24, 2023
1 parent d7a2f18 commit 911469a
Show file tree
Hide file tree
Showing 29 changed files with 1,082 additions and 888 deletions.
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SERVER_HOST=localhost
PASSWORD_RESET_URL=/
PASSWORD_RESET_URL=localhost
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
api_docs:
- 'spec/requests/api/**/*'
94 changes: 78 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
CI: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
PARALLEL_TEST_FIRST_IS_1: true

jobs:
linters:
Expand All @@ -29,9 +30,13 @@ jobs:
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Label PR
if: github.event.pull_request
uses: actions/labeler@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Code Analysis
run: |
bundle exec rake code:analysis
run: bundle exec rake code:analysis
tests:
name: Tests
runs-on: ubuntu-latest
Expand Down Expand Up @@ -65,13 +70,21 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set ENV for codeclimate (pull_request)
with:
fetch-depth: 0
- name: Set ENV for CodeClimate
if: github.event_name == 'pull_request'
run: |
git fetch --no-tags --prune --depth=1 origin +refs/heads/$GITHUB_HEAD_REF:refs/remotes/origin/$GITHUB_HEAD_REF
echo "GIT_BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV
echo "GIT_COMMIT_SHA=$(git rev-parse origin/$GITHUB_HEAD_REF)" >> $GITHUB_ENV
echo "PULL_REQUEST_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- name: Set ENV for API Docs
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
if [ $(git diff ${{ github.event.before }} ${{ github.event.after }} --name-only | grep 'spec/requests/api' | wc -l) -gt 0 ]; then
echo "OPENAPI=true" >> $GITHUB_ENV
fi
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
Expand All @@ -82,52 +95,101 @@ jobs:
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
- name: Setup Database
run: |
bundle exec rake parallel:load_schema
run: bundle exec rake parallel:load_schema
- name: Check for untracked changes in schema.rb
uses: rootstrap/check_untracked_changes@v1
with:
path: "./db/schema.rb"
- name: Get CPU info
id: cpu_info
run: |
echo "cpu_cores=$(nproc)" >> $GITHUB_ENV
run: echo "cpu_cores=$(nproc)" >> $GITHUB_ENV
- name: Run Tests
env:
KNAPSACK_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
KNAPSACK_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
PARALLEL_TESTS_CONCURRENCY: ${{ env.cpu_cores }}
run: |
bundle exec parallel_rspec -n $PARALLEL_TESTS_CONCURRENCY -e './bin/parallel_tests'
run: bundle exec parallel_rspec -n $PARALLEL_TESTS_CONCURRENCY -e './bin/parallel_tests'
- name: Check for missing annotations
run: bundle exec annotate
- name: Check for untracked changes in app and spec directories
uses: rootstrap/check_untracked_changes@v1
with:
path: "./app/ ./spec/"
- name: Report to CodeClimate
run: |
./cc-test-reporter format-coverage --output "coverage/coverage.${{ matrix.ci_node_index }}.json"
- name: Upload partial converage
run: ./cc-test-reporter format-coverage --output "coverage/coverage.${{ matrix.ci_node_index }}.json"
- name: Upload partial coverage
uses: actions/upload-artifact@v2
with:
name: coverage
path: "coverage/coverage.${{ matrix.ci_node_index }}.json"
coverage:
name: Coverage
- name: Merge API Docs from threads
env:
CI_NODE_INDEX: ${{ matrix.ci_node_index }}
if: ${{ env.OPENAPI }}
run: bundle exec ./bin/merge-api-docs.rb
- name: Upload partial API Docs
if: ${{ env.OPENAPI }}
uses: actions/upload-artifact@v2
with:
name: api_docs
path: "tmp/openapi${{ matrix.ci_node_index }}.yaml"
merge_results:
name: Merge Results
runs-on: ubuntu-latest
needs: tests
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
ssh-key: "${{ secrets.PUSH_KEY }}"
- name: Set ENV for CodeClimate
if: github.event_name == 'pull_request'
run: |
git fetch --no-tags --prune --depth=1 origin +refs/heads/$GITHUB_HEAD_REF:refs/remotes/origin/$GITHUB_HEAD_REF
echo "GIT_BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV
echo "GIT_COMMIT_SHA=$(git rev-parse origin/$GITHUB_HEAD_REF)" >> $GITHUB_ENV
echo "PULL_REQUEST_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- name: Set ENV for API Docs
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
if [ $(git diff ${{ github.event.before }} ${{ github.event.after }} --name-only | grep 'spec/requests/api' | wc -l) -gt 0 ]; then
echo "OPENAPI=true" >> $GITHUB_ENV
fi
- name: Setup Code Climate test-reporter
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
- name: download coverage reports
- name: Download coverage reports
uses: actions/download-artifact@v2
with:
name: coverage
path: coverage/coverage.*.json
- name: report coverage
- name: Report coverage
run: |
./cc-test-reporter sum-coverage coverage/**/*.json
./cc-test-reporter upload-coverage
- name: Setup Ruby
if: ${{ env.OPENAPI }}
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Download API Docs
if: ${{ env.OPENAPI }}
uses: actions/download-artifact@v2
with:
name: api_docs
path: tmp/
- name: Merge API Docs from nodes
env:
MOVE_TMP_FILES: true
if: ${{ env.OPENAPI }}
run: bundle exec ./bin/merge-api-docs.rb
- name: Commit & push API Docs
if: ${{ env.OPENAPI }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add "doc/openapi.yaml"
git commit -m "Update API Docs" || echo "No changes to commit"
git push origin main
2 changes: 0 additions & 2 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ detectors:
- _
UnusedParameters:
enabled: true
exclude:
- DeviseTokenAuth::TokenFactory#self.create
UnusedPrivateMethod:
enabled: false
UtilityFunction:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ group :development, :test do
gem 'factory_bot_rails', '~> 6.2'
gem 'pry-byebug', '~> 3.9', platform: :mri
gem 'pry-rails', '~> 0.3.9'
gem 'rspec_api_documentation', '~> 6.1.0'
end

group :development do
Expand Down Expand Up @@ -71,6 +70,7 @@ group :test do
gem 'parallel_tests', '~> 4.3'
gem 'pg_query', '~> 4.2.3'
gem 'prosopite', '~> 1.4.1'
gem 'rspec-openapi', '~> 0.9'
gem 'rspec-rails', '~> 6.0'
gem 'rspec-retry', github: 'rootstrap/rspec-retry', branch: 'add-intermittent-callback'
gem 'shoulda-matchers', '~> 5.3'
Expand Down
14 changes: 4 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ GEM
mini_portile2 (2.8.5)
minitest (5.20.0)
msgpack (1.7.2)
mustache (1.1.1)
net-imap (0.3.7)
date
net-protocol
Expand Down Expand Up @@ -398,10 +397,6 @@ GEM
railties (>= 5.2)
rexml (3.2.6)
rouge (4.1.3)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
Expand All @@ -410,6 +405,9 @@ GEM
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-openapi (0.9.0)
actionpack (>= 5.2.0)
rspec-core
rspec-rails (6.0.3)
actionpack (>= 6.1)
activesupport (>= 6.1)
Expand All @@ -419,10 +417,6 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
rspec_api_documentation (6.1.0)
activesupport (>= 3.0.0)
mustache (~> 1.0, >= 0.99.4)
rspec (~> 3.0)
rubocop (1.57.1)
base64 (~> 0.1.1)
json (~> 2.3)
Expand Down Expand Up @@ -561,9 +555,9 @@ DEPENDENCIES
rails (~> 7.0.8)
rails_best_practices (~> 1.20)
reek (~> 6.1, >= 6.1.1)
rspec-openapi (~> 0.9)
rspec-rails (~> 6.0)
rspec-retry!
rspec_api_documentation (~> 6.1.0)
rubocop (~> 1.57)
rubocop-factory_bot (~> 2.24)
rubocop-performance (~> 1.19)
Expand Down
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ This template comes with:
- Feature flags support with a UI for management.
- RSpec tests
- Code quality tools
- API documentation following https://apiblueprint.org/
- Docker support
- API documentation following https://www.openapis.org/
- RSpec API Doc Generator
- Docker support

## How to use

Expand All @@ -48,6 +48,7 @@ This template comes with:
1. You can now try your REST services!

## Dev scripts

This template provides a handful of scripts to make your dev experience better!

- bin/bundle to run any `bundle` commands.
Expand Down Expand Up @@ -93,7 +94,7 @@ To illustrate, `bin/rails console` will run the console in the docker container
- [Rails Best Practices](https://github.com/flyerhzm/rails_best_practices) for rails linting
- [Reek](https://github.com/troessner/reek) for ruby linting
- [RSpec](https://github.com/rspec/rspec) for testing
- [RSpec API Doc Generator](https://github.com/zipmark/rspec_api_documentation) for API documentation
- [RSpec OpenAPI](https://github.com/exoego/rspec-openapi) for API documentation
- [Rubocop](https://github.com/bbatsov/rubocop/) for ruby linting
- [Sendgrid](https://github.com/stephenb/sendgrid) for sending mails
- [Shoulda Matchers](https://github.com/thoughtbot/shoulda-matchers) adds other testing matchers
Expand All @@ -112,14 +113,9 @@ To illustrate, `bin/rails console` will run the console in the docker container

https://railsapibasers.docs.apiary.io/

With [RSpec API Doc Generator](https://github.com/zipmark/rspec_api_documentation) you can generate the docs after writing the acceptance specs.

Just run:

`./bin/docs `

An `apiary.apib` file will be generated at the root directory of the project.
With [RSpec API Doc Generator](https://github.com/exoego/rspec-openapi) you can generate the docs after writing requests specs.

See [api_documentation](./docs/api_documentation.md) docs for more info.

## Code quality

Expand All @@ -136,6 +132,7 @@ In order to use [New Relic](https://newrelic.com) to monitor your application re
To obtain an API key you must create an account in the platform.

## Configuring Code Climate

1. After adding the project to CC, go to `Repo Settings`
1. On the `Test Coverage` tab, copy the `Test Reporter ID`
1. Set the current value of `CC_TEST_REPORTER_ID` in the [circle-ci project env variables](https://circleci.com/docs/2.0/env-vars/#setting-an-environment-variable-in-a-project)
Expand Down
Loading

0 comments on commit 911469a

Please sign in to comment.