decko-commons/decko

View on GitHub
.semaphore/semaphore.yml

Summary

Maintainability
Test Coverage
version: v1.0
name: Decko Standard
agent:
  machine:
    type: e1-standard-2
    os_image: ubuntu2004
global_job_config:
  env_vars:
    - name: BUNDLE_PATH
      value: "~/bundle/"
    - name: DECKO_REPO_PATH
      value: "~/decko"
    - name: CARD_LOAD_STRATEGY
      value: tmp_files

  secrets:
    - name: s3-credentials
    - name: code-climate-decko
  prologue:
    commands:
      # INSTALL DECKO CODE AND DEPENDENCIES
      - checkout # semaphore does git checkout and cds into decko
      - sem-version ruby 3.0.2
      - gem update --system

      - git submodule init

      # SETUP ALIAS(ES)
      - alias be='bundle exec'

      # INSTALL CODE CLIMATE REPORTER
      - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
      - chmod +x ./cc-test-reporter

      # TWEAK ENVIRONMENTAL VARIABLES
      # ...that are too complex for the env_vars config.

      # without the following, code climate uses git to get git details.
      # Semaphore uses the merge sha for PRS, so this leads to coverage report failures.
      - if [ $SEMAPHORE_GIT_PR_SHA ]; then export GIT_COMMIT_SHA=$SEMAPHORE_GIT_PR_SHA; fi;
      - export S3_PATH="s3://deckodev-test/$SEMAPHORE_PROJECT_NAME/$SEMAPHORE_GIT_BRANCH/coverage/$SEMAPHORE_WORKFLOW_ID/"

blocks:
  - name: Smoke
    task:
      env_vars:
        - name: CARD_LOAD_STRATEGY
          value: eval
      prologue:
        commands:
          # occasionally clear:
          # - cache delete bundle-gems-baseline
          - cache restore bundle-gems-baseline
          - GLCHECK=`checksum Gemfile.lock`
          - cache restore bundle-gems-$GLCHECK
          - bundle install
          - cache store bundle-gems-$GLCHECK ~/bundle
          - cache store bundle-gems-baseline ~/bundle

          - sem-service start mysql

      jobs:
        - name: New Shark and Monkey Decks
          commands:
            # NEW SHARK DECK
            - be decko new shark
            - cd shark
            - be decko setup

            - cd .. # note: faster than making a separate job.

            # NEW MONKEY DECK
            - be decko new monkey --monkey
            - cd monkey
            - be decko setup

  - name: Unit Tests (Postgres)
    run:
      when: "branch = 'main'"
    task:
      prologue:
        commands:
          - sem-service start postgres
          - psql -U postgres -h localhost -c "CREATE USER platypus WITH PASSWORD 'developer';"
          - psql -U postgres -h localhost -c "ALTER USER platypus WITH SUPERUSER;"
          - git submodule update
          - cache restore bundle-gems-$(checksum Gemfile.lock)
          - ./cc-test-reporter before-build
          - bundle install

      jobs:
        - name: RSpec Postgres
          commands:
            - be decko new platypus --platypus -d postgresql
            - cd platypus
            - env RAILS_ENV=test bundle exec decko setup # --test
            - be decko rspec -s -- --format RspecJunitFormatter --out junit.xml --format documentation

      epilogue:
        always:
          commands:
            - test-results publish junit.xml
        on_pass:
          commands:
            - cd -
            - ./cc-test-reporter format-coverage --output "coverage/codeclimate.$SEMAPHORE_JOB_ID.json" -t simplecov
            - aws s3 cp "coverage/codeclimate.$SEMAPHORE_JOB_ID.json" $S3_PATH

  - name: Unit Tests (MySql)
    run:
      when: "branch != 'main'"
    task:
      prologue:
        commands:
          - sem-service start mysql
          - git submodule update
          - cache restore bundle-gems-$(checksum Gemfile.lock)
          - ./cc-test-reporter before-build
          - bundle install

      jobs:
        - name: RSpec MySql
          commands:
            - be decko new platypus --platypus
            - cd platypus
            - env RAILS_ENV=test bundle exec decko setup # --test
            - be decko rspec -s -- --format RspecJunitFormatter --out junit.xml --format documentation
      epilogue:
        always:
          commands:
            - test-results publish junit.xml
        on_pass:
          commands:
            - cd -
            - ./cc-test-reporter format-coverage --output "coverage/codeclimate.$SEMAPHORE_JOB_ID.json" -t simplecov
            - aws s3 cp "coverage/codeclimate.$SEMAPHORE_JOB_ID.json" $S3_PATH

  - name: Integration Tests
    task:
      secrets:
        - name: decko-cypress
        - name: publish-cucumber
      prologue:
        commands:
          - sem-service start mysql
          - git submodule update
          - cache restore bundle-gems-$(checksum Gemfile.lock)
          - be decko new platypus --platypus
          - cd platypus
          - env RAILS_ENV=test bundle exec decko setup # --test

      jobs:
        - name: Cypress
          commands:
            - RAILS_ENV=cypress bundle exec decko server -p 5002 &
            - cd ~/decko/decko/spec
            - rm -rf node_modules
            - yarn install --frozen-lockfile
            - yarn run cypress run --record --reporter junit --reporter-options "mochaFile=/home/semaphore/reports/cypress-output-[hash].xml"

            - pkill -2 -f puma
#        - name: Cucumber
#          commands:
#            - RAILS_ENV=cucumber bundle exec decko cucumber -- --format pretty --format junit --out /home/semaphore/reports --publish

      epilogue:
        always:
          commands:
            - test-results publish /home/semaphore/reports/*.xml
            - cd ~/decko
            - ./cc-test-reporter format-coverage --output "coverage/codeclimate.$SEMAPHORE_JOB_ID.json" -t simplecov
            - aws s3 cp "coverage/codeclimate.$SEMAPHORE_JOB_ID.json" $S3_PATH
            - artifact push job ~/decko/decko/spec/cypress/screenshots
            - artifact push job ~/decko/decko/spec/cypress/videos


  # NOTE: the code climate reporting cannot be handled in after_pipeline, because
  # after_pipeline does not make secrets available - efm 2022-10-12
  - name: Coverage Report
    task:
      jobs:
        - name: CodeClimate Coverage
          commands:
            - aws s3 sync $S3_PATH coverage/
            - ./cc-test-reporter sum-coverage --output - --parts $(ls -1 coverage/ | wc -l) coverage/codeclimate.*.json > coverage/codeclimate.json
            - ./cc-test-reporter upload-coverage

after_pipeline:
  task:
    jobs:
      - name: Publish Results
        commands:
          - test-results gen-pipeline-report