Skip to content

Commit

Permalink
Merge pull request #360 from nimblehq/release/5.2.0
Browse files Browse the repository at this point in the history
Release 5.2.0
  • Loading branch information
malparty authored Sep 9, 2022
2 parents f75c90d + f5ff9df commit bc4a61c
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 98 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test_variants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
run: |
export BRANCH_TAG=${{ env.BRANCH_TAG }}-${{ matrix.variant }}
cd $APP_NAME
docker compose pull test || true
docker-compose pull test || true
- name: Build docker image
run: |
Expand All @@ -98,7 +98,7 @@ jobs:
run: |
export BRANCH_TAG=${{ env.BRANCH_TAG }}-${{ matrix.variant }}
cd $APP_NAME
docker compose push test
docker-compose push test
- name: Test template
run: |
Expand Down
58 changes: 0 additions & 58 deletions .template/addons/github/.github/workflows/review_code.yml.tt

This file was deleted.

85 changes: 74 additions & 11 deletions .template/addons/github/.github/workflows/test.yml.tt
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
name: Test

on: push
on:
pull_request:
push:
branches:
- develop
- main

env:
DANGER_GITHUB_API_TOKEN: ${{ github.token }}
DOCKER_REGISTRY_HOST: ${{ secrets.DOCKER_REGISTRY_HOST }}
DOCKER_REGISTRY_USERNAME: ${{ github.repository_owner }}
DOCKER_REGISTRY_TOKEN: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
DOCKER_IMAGE: ${{ github.repository }}
NODE_VERSION: 16

# Set the default docker-compose file
COMPOSE_FILE: docker-compose.test.yml
Expand All @@ -21,7 +28,7 @@ jobs:
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v3

- name: Set env BRANCH_TAG
uses: nimblehq/[email protected]
Expand All @@ -35,20 +42,20 @@ jobs:

- name: Pull Docker image
if: ${{ env.BRANCH_TAG != 'latest' && env.BRANCH_TAG != 'development' }}
run: docker compose pull test || true
run: docker-compose pull test || true

- name: Build Docker image
run: bin/docker-prepare && docker compose build
run: bin/docker-prepare && docker-compose build

- name: Push Docker image
run: docker compose push test
run: docker-compose push test

unit_tests:
name: Unit tests
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v3

- name: Set env BRANCH_TAG
uses: nimblehq/[email protected]
Expand All @@ -61,17 +68,23 @@ jobs:
password: ${{ env.DOCKER_REGISTRY_TOKEN }}

- name: Pull Docker image
run: docker compose pull test || true
run: docker-compose pull test || true

- name: Run unit tests
run: docker compose run test bundle exec rspec --exclude-pattern "spec/systems/**/*_spec.rb" --profile
run: docker-compose run test bundle exec rspec --exclude-pattern "spec/systems/**/*_spec.rb" --profile

- name: Upload tests coverage artifact
uses: actions/upload-artifact@v3
with:
name: coverage
path: coverage

system_tests:
name: System tests
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v3

- name: Set env BRANCH_TAG
uses: nimblehq/[email protected]
Expand All @@ -84,14 +97,64 @@ jobs:
password: ${{ env.DOCKER_REGISTRY_TOKEN }}

- name: Pull Docker image
run: docker compose pull test || true
run: docker-compose pull test || true

- name: Run system tests
run: docker compose run test bundle exec rspec spec/systems --profile
run: docker-compose run test bundle exec rspec spec/systems --profile

- name: Upload system tests screenshots artifact
uses: actions/upload-artifact@v2
if: ${{ failure() }}
with:
name: system_tests_screenshots
path: tmp/screenshots/*

automated_code_review:
name: Run Danger
needs: unit_tests
runs-on: ubuntu-latest
timeout-minutes: 5
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download tests coverage artifact
uses: actions/download-artifact@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow: test.yml
workflow_conclusion: success
name: coverage
path: coverage

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'

- name: Cache Node modules
id: node-modules-cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-nodemodules-

- name: Yarn install
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: yarn

- name: Run Undercover
run: bundle exec undercover-report

- name: Run Danger
run: bundle exec danger
6 changes: 3 additions & 3 deletions .template/addons/semaphore/.semaphore/semaphore.yml.tt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ agent:
os_image: ubuntu1804
auto_cancel:
running:
when: "branch != 'master'"
when: "branch != 'main'"

global_job_config:
env_vars:
Expand All @@ -28,7 +28,7 @@ blocks:
- name: Build
commands:
- >-
if ([ $SEMAPHORE_GIT_BRANCH != 'master' ] && [ $SEMAPHORE_GIT_BRANCH != 'development' ]);
if ([ $SEMAPHORE_GIT_BRANCH != 'main' ] && [ $SEMAPHORE_GIT_BRANCH != 'development' ]);
then (echo "Pulling built image for the branch"; docker compose pull test || true);
else (echo "Skipping docker pull");
fi || true
Expand Down Expand Up @@ -67,4 +67,4 @@ promotions:
- name: Production
pipeline_file: promotion-production.yml
auto_promote:
when: "branch = 'master' AND result = 'passed'"
when: "branch = 'main' AND result = 'passed'"
1 change: 0 additions & 1 deletion .template/spec/addons/base/github/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
it 'creates Github actions workflows' do
expect(file('.github/workflows/deploy_heroku.yml')).to exist
expect(file('.github/workflows/publish_wiki.yml')).to exist
expect(file('.github/workflows/review_code.yml')).to exist
expect(file('.github/workflows/test_production_build.yml')).to exist
expect(file('.github/workflows/test.yml')).to exist
end
Expand Down
1 change: 1 addition & 0 deletions .template/variants/web/.stylelintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules/**
/app/assets/builds/**
/vendor/**
/coverage/**
11 changes: 0 additions & 11 deletions .template/variants/web/spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@

# https://github.com/rails/rails/pull/30876
Capybara.register_driver(:headless_chrome) do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
# This enables access to logs with `page.driver.manage.get_log(:browser)`
loggingPrefs: {
browser: 'ALL',
client: 'ALL',
driver: 'ALL',
server: 'ALL'
}
)

options = Selenium::WebDriver::Chrome::Options.new

# Sets default window size in case the smaller default size is not enough
Expand All @@ -41,7 +31,6 @@
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: capabilities,
options: options
)
end
Expand Down
19 changes: 18 additions & 1 deletion Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,24 @@ reek.lint
suggester.suggest

# Report your Ruby app test suite code coverage in Danger.
simplecov.report 'coverage/coverage.json'
# Copied from the report method to fix the wrong method called on line:31
# https://github.com/marcelofabri/danger-simplecov_json/blob/master/lib/simplecov_json/plugin.rb#L31
# rubocop:disable Style/GuardClause, Style/SignalException
coverage_path = 'coverage/coverage.json'
if File.exist? coverage_path
coverage_json = JSON.parse(File.read(coverage_path), symbolize_names: true)
metrics = coverage_json[:metrics]
percentage = metrics[:covered_percent]
lines = metrics[:covered_lines]
total_lines = metrics[:total_lines]

formatted_percentage = format('%.02f', percentage)
# Use markdown instead of message
markdown("Code coverage is now at **#{formatted_percentage}% (#{lines}/#{total_lines} lines)**")
else
fail('Code coverage data not found')
end
# rubocop:enable Style/GuardClause, Style/SignalException

# Report missing test coverage of new changes in Danger
undercover.report
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ create_api:
build:
cd $(APP_NAME) && \
bin/docker-prepare && \
docker compose -f docker-compose.test.yml build
docker-compose -f docker-compose.test.yml build

build_production:
cd $(APP_NAME) && \
bin/docker-prepare && \
docker compose build
docker-compose build

test_variant_app:
cd $(APP_NAME) && \
docker compose -f docker-compose.test.yml run test
docker-compose -f docker-compose.test.yml run test

base_addon_spec = spec/addons/base/**/*_spec.rb
web_addon_spec = spec/addons/variants/web/**/*_spec.rb
Expand All @@ -40,9 +40,9 @@ api_spec = spec/variants/api/**/*_spec.rb

test_template:
cd $(APP_NAME) && \
docker compose -f docker-compose.test.yml up --detach db redis && \
docker compose -f docker-compose.test.yml run test bash -c "./bin/inject_port_into_nginx.sh && nginx -c /etc/nginx/conf.d/default.conf -t" && \
docker compose -f docker-compose.test.yml run --detach test bin/start.sh && \
docker-compose -f docker-compose.test.yml up --detach db redis && \
docker-compose -f docker-compose.test.yml run test bash -c "./bin/inject_port_into_nginx.sh && nginx -c /etc/nginx/conf.d/default.conf -t" && \
docker-compose -f docker-compose.test.yml run --detach test bin/start.sh && \
cd ../.template && \
bundle install; \
if [ $(VARIANT) = web ]; then \
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ with building complex applications over the years.
In order to use the template, initialize a new app with the following parameters:

```sh
rails new <app_name> -m https://raw.githubusercontent.com/nimblehq/rails-templates/master/template.rb
rails new <app_name> -m https://raw.githubusercontent.com/nimblehq/rails-templates/main/template.rb
```

Supported template options:
Expand All @@ -36,13 +36,13 @@ Supported template options:
To apply the template on an existing application, run following rails command:

```sh
rails app:template LOCATION=https://raw.githubusercontent.com/nimblehq/rails-templates/master/template.rb
rails app:template LOCATION=https://raw.githubusercontent.com/nimblehq/rails-templates/main/template.rb

# To apply on an api application
rails app:template LOCATION=https://raw.githubusercontent.com/nimblehq/rails-templates/master/template.rb API=true
rails app:template LOCATION=https://raw.githubusercontent.com/nimblehq/rails-templates/main/template.rb API=true

# To apply a specific addon
rails app:template LOCATION=https://raw.githubusercontent.com/nimblehq/rails-templates/master/template.rb ADDON=<addon name>
rails app:template LOCATION=https://raw.githubusercontent.com/nimblehq/rails-templates/main/template.rb ADDON=<addon name>
```

Available Addons:
Expand Down
3 changes: 3 additions & 0 deletions bin/docker-assets-precompile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# And it requires the envs as we always use `ENV.fetch` to setup the variables
#
# Related issue: https://github.com/rails/rails/issues/32947
# TODO: https://github.com/nimblehq/rails-templates/issues/326

require 'yaml'

Expand All @@ -16,6 +17,8 @@ rails_env = ENV.fetch('RAILS_ENV', 'production')
if rails_env == 'production'
env_keys = YAML.load_file('config/application.yml')['docker_build'].keys
env_keys.each { |name| ENV[name] = 'dummy_value' }

ENV['DATABASE_URL'] = 'postgres://postgres:postgres@postgres:5432/postgres'
end

exit system('bin/rails i18n:js:export && bin/rails assets:precompile')
2 changes: 1 addition & 1 deletion config/initializers/backtrace_silencers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Add backtrace silencer
# Default silencer is removing backtrace involving engines files
# Our silencer also checks for engines directory
# Ref: https://github.com/rails/rails/blob/master/railties/lib/rails/backtrace_cleaner.rb
# Ref: https://github.com/rails/rails/blob/main/railties/lib/rails/backtrace_cleaner.rb
Rails.backtrace_cleaner.add_silencer do |line|
!(Rails::BacktraceCleaner::APP_DIRS_PATTERN.match?(line) || /^engines/.match?(line))
end

0 comments on commit bc4a61c

Please sign in to comment.