Skip to content

Commit

Permalink
Merge pull request #415 from nimblehq/release/5.6.0
Browse files Browse the repository at this point in the history
Release/5.6.0
  • Loading branch information
malparty authored Jun 22, 2023
2 parents 4a4349a + 5189ddb commit 2265237
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.iml
out
gen
.vscode
1 change: 1 addition & 0 deletions .gitignore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Ignore folder information and IDE-specific files
.DS_Store
.idea/*
.vscode
# Ignore the test coverage results from SimpleCov
/coverage
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Style/Documentation:
Enabled: false

Layout/LineLength:
Max: 120
Max: 130
Exclude:
- 'spec/**/*'
- 'config/**/*'
Expand Down
2 changes: 1 addition & 1 deletion .template/addons/github/.github/workflows/test.yml.tt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
if: ${{ failure() }}
with:
name: system_tests_screenshots
path: tmp/screenshots/*
path: tmp/screenshots/

automated_code_review:
name: Run Danger
Expand Down
20 changes: 15 additions & 5 deletions .template/spec/variants/web/package_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
it 'adds the script for bundling css' do
expect(subject['scripts']).to include('build:css')
end

it 'adds the script for bundling css in production' do
expect(subject['scripts']).to include('build:css-production')
end

it 'adds the script for bundling postcss' do
expect(subject['scripts']).to include('postcss')
expect(subject['scripts']).to include('build:postcss')
end
end

describe 'Dependencies' do
Expand All @@ -42,6 +51,12 @@
it 'adds esbuild dependencies' do
expect(subject['dependencies']).to include('esbuild')
end

it 'adds postcss dependencies' do
expect(subject['dependencies']).to include('postcss')
expect(subject['dependencies']).to include('postcss-cli')
expect(subject['dependencies']).to include('autoprefixer')
end
end

describe 'Development Dependencies' do
Expand All @@ -53,10 +68,5 @@
expect(subject['devDependencies']).to include('stylelint')
expect(subject['devDependencies']).to include('@nimblehq/stylelint-config-nimble')
end

it 'adds postcss 8 dependencies' do
expect(subject['devDependencies']).to include('postcss')
expect(subject['devDependencies']['postcss']).to eq('8.4.5')
end
end
end
15 changes: 15 additions & 0 deletions .template/variants/web/.gitignore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,23 @@
# Ignore asset builds
/app/assets/builds/*
!/app/assets/builds/.keep
# Ignore Node dependencies
/node_modules
# debug
yarn-debug.log*
yarn-error.log*
.yarn-integrity
# Ignore Byebug history.
.byebug_history
# Ignore master keys for decrypting credentials and more.
/config/credentials/*.key
# Ignore Gemfile.lock file in engines.
/engines/*/Gemfile.lock
IGNORE
end
1 change: 1 addition & 0 deletions .template/variants/web/Procfile.dev.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<<~PROCFILE
js: yarn build --watch
css: yarn build:css --watch
postcss: yarn build:postcss --watch
PROCFILE
end
1 change: 1 addition & 0 deletions .template/variants/web/app/javascript/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require('esbuild')
inject: ['app/javascript/global.js'],
bundle: true,
sourcemap: true,
minify: !watch,
outdir: 'app/assets/builds',
})
.then((ctx) => {
Expand Down
32 changes: 26 additions & 6 deletions .template/variants/web/package.json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,26 @@
JSON
end

unless File.exist?('postcss.config.js')
create_file 'postcss.config.js',
<<~POSTCSS
module.exports = {
plugins: [
require('autoprefixer'),
]
}
POSTCSS
end

# Install dependencies
run 'yarn add [email protected]'
run 'yarn add sass'
run 'yarn add esbuild'
run 'yarn add postcss postcss-cli autoprefixer'

run 'yarn add --dev @nimblehq/[email protected]'
run 'yarn add --dev stylelint'
run 'yarn add --dev @nimblehq/stylelint-config-nimble'
# TODO: Check again after removing Webpacker, need to use version 8
# https://github.com/bjankord/stylelint-config-sass-guidelines/issues/203#issuecomment-955620774
run 'yarn add --dev [email protected]'

# Setup scripts
run 'npm set-script eslint "eslint . --color"'
run 'npm set-script eslint:fix "eslint . --color --fix"'
Expand All @@ -33,13 +41,25 @@

source_stylesheet = 'app/assets/stylesheets/application.scss'
bundled_stylesheet = 'app/assets/builds/application.css'
bundled_stylesheet_options = [
bundled_stylesheet_base_options = [
'--no-source-map',
'--load-path=node_modules'
]
production_bundled_stylesheet_options = bundled_stylesheet_base_options + [
'--style=compressed'
]

run %(npm set-script build "node app/javascript/build.js")
run %(
npm set-script build:css-production \
"sass #{source_stylesheet} #{bundled_stylesheet} #{(production_bundled_stylesheet_options).join(' ')}"
)
run %(
npm set-script build:css \
"sass #{source_stylesheet} #{bundled_stylesheet} #{bundled_stylesheet_options.join(' ')}"
"sass #{source_stylesheet} #{bundled_stylesheet} #{bundled_stylesheet_base_options.join(' ')}"
)
run %(npm set-script postcss "postcss public/assets/*.css --dir public/assets --config ./")
run %(
npm set-script build:postcss \
"postcss app/assets/builds/*.css --dir app/assets/builds --config ./",
)
1 change: 1 addition & 0 deletions .template/variants/web/spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@

Capybara.javascript_driver = :chrome
Capybara.default_max_wait_time = CAPYBARA_TIMEOUT
Capybara.save_path = 'tmp/screenshots'
1 change: 1 addition & 0 deletions Gemfile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem 'mini_magick' # A ruby wrapper for ImageMagick or GraphicsMagick command lin
gem 'pagy' # A pagination gem that is very light and fast
gem 'discard' # Soft deletes for ActiveRecord
gem 'sidekiq' # background processing for Ruby
gem 'sassc' # bootsnap dependency
gem 'bootsnap', require: false # Reduces boot times through caching; required in config/boot.rb
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
# gem 'jbuilder' # Build JSON APIs with ease
Expand Down
27 changes: 27 additions & 0 deletions Makefile.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
include .env

.PHONY: dev env/setup env/teardown codebase codebase/fix

dev:
make install-dependencies
make env/setup
./bin/dev

env/setup:
./bin/envsetup.sh
rails db:prepare

env/teardown: # this command will delete data
./bin/envteardown.sh

install-dependencies:
bundle install
yarn install

codebase:
rubocop
yarn codebase

codebase/fix:
rubocop -a
yarn codebase:fix
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ Available Addons:
- `slim`
- `devise`

After the template finishes generating all the files, run the following command to start the rails server.

```sh
make dev
```

Read more about Rails Application Template in the [official Rails Guides](https://guides.rubyonrails.org/rails_application_templates.html).

## How to contribute
Expand Down Expand Up @@ -101,7 +107,7 @@ There are 2 template file types:
1. **`.tt` files**

This file is used for templating the whole new file.
In case if we want to create a new file that Rails does not generated.
In case if we want to create a new file that Rails has not generated.

2. **`.rb` files**

Expand Down
94 changes: 47 additions & 47 deletions README.md.tt
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,13 @@

- Install [Docker for Mac](https://docs.docker.com/docker-for-mac/install/)

- Setup and boot the Docker containers:

```sh
./bin/envsetup.sh
```

### Development

- Setup the databases:

- Postgres:

```sh
rake db:setup
```

- Run the Rails app
Run the Rails app:

```sh
./bin/dev
```
make dev
``

## Testing

Expand All @@ -47,12 +33,12 @@ Add the following build settings to run the tests in the Docker environment via

- Configure the environment variable `BRANCH_TAG` to tag Docker images per branch, e.g:

```sh
# a unique `BRANCH_TAG` value to tag the Docker image
# e.g $SEMAPHORE_BRANCH_ID or using the
# or using nimblehq/branch-tag-action@1 Github action
export BRANCH_TAG= # unique value for tagging Docker image
```
```sh
# a unique `BRANCH_TAG` value to tag the Docker image
# e.g $SEMAPHORE_BRANCH_ID or using the
# or using nimblehq/branch-tag-action@1 Github action
export BRANCH_TAG= # unique value for tagging Docker image
```

Each branch needs to have its own Docker image to avoid build settings disparities and leverage Docker image caching.

Expand All @@ -61,54 +47,68 @@ An alternative is to use a unique identifier such as PR_ID or BRANCH_ID on the C

- Pull the latest version the Docker image for the branch:

```sh
docker pull $DOCKER_IMAGE:$BRANCH_TAG || true
```
```sh
docker pull $DOCKER_IMAGE:$BRANCH_TAG || true
```

On each build, the CI environment does not contain yet a cached version of the image. Therefore, it is required to pull
it first to leverage the `cache_from` settings of Docker Compose which avoids rebuilding the whole Docker image on subsequent test builds.

- Build the Docker image:

```sh
./bin/docker-prepare && docker compose -f docker-compose.test.yml build
```
```sh
./bin/docker-prepare && docker compose -f docker-compose.test.yml build
```

Upon the first build, the whole Docker image is built from the ground up and tagged using `$BRANCH_TAG`.

- Push the latest version of the Docker image for this branch:

```sh
docker push $DOCKER_IMAGE:$BRANCH_TAG
```
```sh
docker push $DOCKER_IMAGE:$BRANCH_TAG
```

- Setup the test database:

```sh
docker compose -f docker-compose.test.yml run test bin/bundle exec rake db:test:prepare
```
```sh
docker compose -f docker-compose.test.yml run test bin/bundle exec rake db:test:prepare
```

### Test

- Run all tests:

```sh
# Docker way
docker compose -f docker-compose.test.yml run test
```sh
# Docker way
docker compose -f docker-compose.test.yml run test

# Non-Docker way
rspec
```
# Non-Docker way
rspec
```

- Run a specific test:

```sh
# Docker way
docker compose -f docker-compose.test.yml run test bin/bundle exec rspec [rspec-params]
```sh
# Docker way
docker compose -f docker-compose.test.yml run test bin/bundle exec rspec [rspec-params]

# Non-Docker way
rspec [rspec-params]
```
# Non-Docker way
rspec [rspec-params]
```

### Linting

- Run all lint:

```sh
make codebase
```

- Fix all lint:

```sh
make codebase/fix
```

### Automated Code Review Setup
- Add a bot (i.e. `team-nimblehq`) to this repository or to the organization. The bot requires permission level “Write” to be able to set a PR’s status.
Expand Down
2 changes: 1 addition & 1 deletion bin/docker-assets-precompile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ if rails_env == 'production'
ENV['DATABASE_URL'] = 'postgres://postgres:postgres@postgres:5432/postgres'
end

exit system('bin/rails i18n:js:export && bin/rails assets:precompile')
exit system('bin/rails i18n:js:export && bin/rails assets:precompile && yarn postcss')
3 changes: 3 additions & 0 deletions bin/envteardown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker compose -f docker-compose.dev.yml down
1 change: 1 addition & 0 deletions bin/template.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

copy_file 'bin/envsetup.sh', mode: :preserve
copy_file 'bin/envteardown.sh', mode: :preserve
copy_file 'bin/start.sh', mode: :preserve
copy_file 'bin/test.sh', mode: :preserve
copy_file 'bin/worker.sh', mode: :preserve
Expand Down
Loading

0 comments on commit 2265237

Please sign in to comment.