. #1623
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: CI | |
on: | |
push: | |
# on: | |
# workflow_dispatch: | |
# pull_request: | |
# push: | |
# branches: [main] | |
permissions: | |
pull-requests: write | |
contents: write | |
env: | |
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | |
CI: true | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
REPO: ${{ github.repository }} | |
PARALLEL_TEST_FIRST_IS_1: true | |
DOCKER_BUILD_RECORD_UPLOAD: false | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Cache Docker layers | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.head_ref || github.ref_name }}-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx-${{ github.head_ref || github.ref_name }} | |
${{ runner.os }}-buildx-main | |
${{ runner.os }}-buildx- | |
- name: Build and export | |
uses: docker/build-push-action@v6 | |
with: | |
push: false | |
tags: api_base/test:latest | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
outputs: type=docker,dest=/tmp/api_base_test_image.tar | |
file: Dockerfile.dev | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: api base test image | |
path: /tmp/api_base_test_image.tar | |
retention-days: 1 | |
- # Temp fix | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
linters: | |
name: Linters | |
runs-on: ubuntu-latest | |
needs: docker | |
timeout-minutes: 10 | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: api base test image | |
path: /tmp | |
- name: Load image | |
run: | | |
docker load --input /tmp/api_base_test_image.tar | |
docker image ls -a | |
- name: Label PR | |
if: github.event.pull_request | |
uses: actions/labeler@v5 | |
with: | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Run Code Analysis | |
run: docker run api_base/test:latest bundle exec rails code:analysis | |
tests: | |
name: Tests | |
needs: docker | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
env: | |
RAILS_ENV: test | |
services: | |
db: | |
image: postgres:15 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_HOST_AUTH_METHOD: trust | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
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 | |
ci_node_total: [1] | |
# 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] | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: api base test image | |
path: /tmp | |
- name: Load image | |
run: | | |
docker load --input /tmp/api_base_test_image.tar | |
docker image ls -a | |
- 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 Database | |
run: docker run --network host -e RAILS_ENV=test api_base/test:latest bundle exec rake parallel:setup | |
# - 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 | |
- 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: docker run --network host -e PARALLEL_TESTS_CONCURRENCY=$PARALLEL_TESTS_CONCURRENCY -e KNAPSACK_CI_NODE_TOTAL=$KNAPSACK_CI_NODE_TOTAL -e KNAPSACK_CI_NODE_INDEX=$KNAPSACK_CI_NODE_INDEX -e RAILS_ENV=test -e HEADLESS=true -e CI=true -e CHROME_PATH=/usr/local/share/chrome_driver/chromedriver api_base/test:latest 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: Upload partial coverage | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: coverage | |
# path: "coverage/coverage.${{ matrix.ci_node_index }}.json" | |
# - 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@v4 | |
# 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@v4 | |
# 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 | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: coverage | |
# path: coverage/coverage.*.json | |
# - name: Report coverage | |
# run: | | |
# ./cc-test-reporter sum-coverage coverage/**/*.json | |
# ./cc-test-reporter upload-coverage | |
# - name: Setup Node | |
# uses: actions/setup-node@v4 | |
# with: | |
# node-version-file: '.nvmrc' | |
# cache: 'yarn' | |
# - 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@v4 | |
# 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 "[email protected]" | |
# 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 |