Created
January 28, 2020 10:18
-
-
Save andychongyz/dc750044f2989cca4344b8fc66b43283 to your computer and use it in GitHub Desktop.
knapsack rspec github flow
This file contains hidden or 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: rspec | |
| on: [push] | |
| env: | |
| SHOPIFY_API_KEY: ${{ secrets.SHOPIFY_API_KEY }} | |
| SHOPIFY_API_SECRET: ${{ secrets.SHOPIFY_API_SECRET }} | |
| REACT_APP_RETAILER_CLIENT_URL: ${{ secrets.REACT_APP_RETAILER_CLIENT_URL }} | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: "" | |
| POSTGRES_DB: postgres | |
| jobs: | |
| # This setup job is to install the dependencies and cache them for the following matrix job | |
| setup: | |
| name: Setup environment | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:10.8 | |
| ports: | |
| # will assign a random free host port | |
| - 5432/tcp | |
| # needed because the postgres container does not provide a healthcheck | |
| options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | |
| steps: | |
| - name: Checkout to repo | |
| uses: actions/checkout@master | |
| - name: Set up Ruby 2.6 | |
| uses: actions/setup-ruby@v1 | |
| with: | |
| ruby-version: 2.6.5 | |
| - name: Set up JS env | |
| uses: actions/setup-node@v1 | |
| with: | |
| node-version: '10.x' | |
| - name: Cache ruby gems | |
| uses: actions/cache@v1 | |
| with: | |
| path: vendor/bundle | |
| key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gems- | |
| - name: Cache npm packages | |
| uses: actions/cache@v1 | |
| with: | |
| path: ~/.npm | |
| key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| # required to compile pg ruby gem | |
| - name: Install PostgreSQL client | |
| run: sudo apt-get install libpq-dev | |
| - name: Build | |
| env: | |
| # use localhost for the host here because we have specified a container for the job. | |
| # If we were running the job on the VM this would be postgres | |
| PGHOST: localhost | |
| PGUSER: postgres | |
| RAILS_ENV: test | |
| run: | | |
| npm install --ignore-scripts | |
| gem install bundler | |
| bundle config path vendor/bundle | |
| bundle install --jobs 4 --retry 3 | |
| rspec: | |
| needs: setup | |
| name: Rspec | |
| runs-on: ubuntu-latest | |
| # If you need DB like PostgreSQL then define service below. | |
| # Example for Redis can be found here: | |
| # https://github.com/actions/example-services/tree/master/.github/workflows | |
| services: | |
| postgres: | |
| image: postgres:10.8 | |
| ports: | |
| # will assign a random free host port | |
| - 5432/tcp | |
| # 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: | |
| image: redis | |
| ports: | |
| - 6379/tcp | |
| options: --entrypoint redis-server | |
| # https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # Set N number of parallel jobs you want to run tests on. | |
| # Use higher number if you have slow tests to split them on more parallel jobs. | |
| # Remember to update ci_node_index below to 0..N-1 | |
| # Currently using only 1 node, as the number of test is little for parallelism to make a significant impact. | |
| ci_node_total: [2] | |
| # set N-1 indexes for parallel jobs | |
| # When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc | |
| ci_node_index: [0, 1] | |
| steps: | |
| - name: Checkout to repo | |
| uses: actions/checkout@master | |
| - name: Set up Ruby 2.6 | |
| uses: actions/setup-ruby@v1 | |
| with: | |
| ruby-version: 2.6.5 | |
| - name: Set up JS env | |
| uses: actions/setup-node@v1 | |
| with: | |
| node-version: '10.x' | |
| - name: Cache ruby gems | |
| uses: actions/cache@v1 | |
| with: | |
| path: vendor/bundle | |
| key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gems- | |
| - name: Cache npm packages | |
| uses: actions/cache@v1 | |
| with: | |
| path: ~/.npm | |
| key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| # required to compile pg ruby gem | |
| - name: Install PostgreSQL client | |
| run: sudo apt-get install libpq-dev | |
| - name: Build and create DB | |
| env: | |
| # use localhost for the host here because we have specified a container for the job. | |
| # If we were running the job on the VM this would be postgres | |
| PGHOST: localhost | |
| PGUSER: postgres | |
| PGPORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port | |
| RAILS_ENV: test | |
| run: | | |
| npm install --ignore-scripts | |
| gem install bundler | |
| bundle config path vendor/bundle | |
| bundle install --jobs 4 --retry 3 | |
| bin/rails db:setup | |
| - name: Run rspec tests | |
| env: | |
| PGHOST: localhost | |
| PGUSER: postgres | |
| PGPORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port | |
| RAILS_ENV: test | |
| CI_NODE_TOTAL: ${{ matrix.ci_node_total }} | |
| CI_NODE_INDEX: ${{ matrix.ci_node_index }} | |
| run: | | |
| bundle exec rake knapsack:rspec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment