Created
March 31, 2022 11:03
-
-
Save GuillaumeOcculy/0942c4acb8ebc3b52545a0607440ea31 to your computer and use it in GitHub Desktop.
github action test.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test | |
# triggers on | |
on: | |
#push: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
test: | |
env: | |
RAILS_ENV: test | |
NODE_ENV: test | |
runs-on: ubuntu-latest | |
# NEW! Adds postgres service. Must come before `steps`. | |
services: | |
# How to use postgres | |
postgres: | |
# Docker Hub image | |
image: postgres | |
# Provide the password for postgres | |
env: | |
POSTGRES_PASSWORD: postgres | |
ports: | |
- 5432:5432 | |
# needed because the postgres container does not provide a healthcheck | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
# Redis | |
redis: | |
image: redis | |
ports: | |
- 6379/tcp | |
# Elasticsearch | |
elasticsearch: | |
image: elasticsearch:7.17.1 | |
ports: | |
- 9200/tcp | |
options: -e="discovery.type=single-node" | |
--health-cmd="curl http://localhost:9200/_cluster/health" | |
--health-interval=10s | |
--health-timeout=5s | |
--health-retries=10 | |
strategy: | |
matrix: | |
elasticsearch: [7.17.1] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Ruby # An action to install Ruby and gems | |
uses: ruby/setup-ruby@v1 # short for https://github.com/ruby/setup-ruby | |
with: | |
# runs 'bundle install' and caches installed gems automatically | |
bundler-cache: true | |
- name: Set up Node | |
uses: actions/setup-node@v2 | |
with: | |
node-version: "14" | |
- name: Get Yarn cache directory path | |
id: yarn-cache | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- name: Setup cache key and directory for node_modules cache | |
uses: actions/cache@v1 | |
with: | |
path: ${{ steps.yarn-cache.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
- name: Yarn install | |
run: yarn install --frozen-lockfile | |
- name: Bundle Install and Create DB | |
env: | |
RAILS_ENV: test | |
NODE_ENV: test | |
DB_PASSWORD: postgres | |
DB_PORT: ${{ job.services.postgres.ports[5432] }} | |
run: | # Pipe is important, adds line breaks | |
cp config/database.github.yml config/database.yml | |
gem install bundler --version 2.2.32 | |
bundle config path vendor/bundle | |
bundle install --jobs 4 --retry 3 --path vendor/bundle | |
bundle exec rails db:test:prepare | |
sudo apt-get install redis-server | |
sudo systemctl start redis | |
- uses: actions/cache@v2 | |
if: ${{ matrix.elasticsearch }} | |
with: | |
path: ~/elasticsearch | |
key: ${{ runner.os }}-elasticsearch-${{ matrix.elasticsearch }} | |
- uses: ankane/setup-elasticsearch@v1 | |
if: ${{ matrix.elasticsearch }} | |
with: | |
elasticsearch-version: ${{ matrix.elasticsearch }} | |
plugins: | | |
analysis-kuromoji | |
analysis-smartcn | |
analysis-stempel | |
analysis-ukrainian | |
- uses: actions/cache@v2 | |
with: | |
path: ~/elasticsearch | |
key: ${{ runner.os }}-elasticsearch-${{ matrix.elasticsearch-version }} | |
- run: curl -s localhost:9200 | |
- run: which elasticsearch | |
- name: Verify Elasticsearch connection from host and resetting read-only index and updating watermarks | |
env: | |
ELASTIC_SEARCH_URL: http://localhost:${{ job.services.elasticsearch.ports[9200] }} | |
run: | | |
echo $ELASTIC_SEARCH_URL | |
echo health | |
curl -fsSL "$ELASTIC_SEARCH_URL/_cat/health?h=status" | |
echo create index | |
curl -X PUT "$ELASTIC_SEARCH_URL/iot_log" -H 'Content-Type: application/json' -d'{ "settings" : { "index" : { } }}' | |
echo read_only_allow_delete | |
curl -X PUT "$ELASTIC_SEARCH_URL/_all/_settings" -H 'Content-Type: application/json' -d' {"index.blocks.read_only_allow_delete": null}' | |
echo watermarks | |
curl -X PUT "$ELASTIC_SEARCH_URL/_cluster/settings?pretty" -H 'Content-Type: application/json' -d' { "transient": { "cluster.routing.allocation.disk.watermark.low": "50gb", "cluster.routing.allocation.disk.watermark.high": "20gb", "cluster.routing.allocation.disk.watermark.flood_stage": "10gb", "cluster.info.update.interval": "1m"}}' | |
# echo forcemerge | |
# curl -X POST "$ELASTIC_SEARCH_URL/iot_log-000001/_forcemerge?pretty" | |
- name: Run tests | |
env: | |
RAILS_ENV: test | |
DB_PASSWORD: postgres | |
DB_PORT: ${{ job.services.postgres.ports[5432] }} | |
REDIS_PORT: ${{ job.services.redis.ports[6379] }} | |
ELASTIC_SEARCH_URL: http://localhost:${{ job.services.elasticsearch.ports[9200] }} | |
run: | | |
bundle exec rails test | |
bundle exec rails test:controllers | |
# bundle exec rails test test/controllers/companies_controller_test.rb:105 | |
bundle exec rails test:system |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment