Skip to content

Fixing issues with code coverage report generation and upload to Code Climate #343

Fixing issues with code coverage report generation and upload to Code Climate

Fixing issues with code coverage report generation and upload to Code Climate #343

Workflow file for this run

name: Build and Run Integration Test
on:
push:
branches:
- master
- caio/test-consolidate-dockerfiles
pull_request:
branches:
- develop
- dmou/test-consolidate-dockerfiles
permissions:
id-token: write
contents: read
jobs:
integration-test:
runs-on: ubuntu-latest
outputs:
image: ${{ steps.build-image.outputs.image }}
steps:
- uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: eu-west-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up configuration
run: |
touch .env.test
cp config/database.yml.example config/database.yml
cp config/sidekiq.yml.example config/sidekiq.yml
cp config/config.yml.example config/config.yml
cp config/cookies.txt.example config/cookies.txt
bin/get_env_vars.sh
chmod -R a+w .
- name: Docker Buildx (build)
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ github.event.repository.name }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker buildx build \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache-new" \
--load \
--tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
--file ./Dockerfile ./
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Run container
id: run-container
run: |
docker compose -f docker-test.yml up -d pender
- name: Set up PR Tests
id: setup-tests
run: |
docker compose -f docker-test.yml exec -T -e DEPLOY_ENV=ci pender test/setup-parallel
- name: Run PR Tests
id: run-tests
env:
TEST_RETRY_COUNT: 5
continue-on-error: true
run: |
docker compose -f docker-test.yml exec -e TEST_RETRY_COUNT=$TEST_RETRY_COUNT -e DEPLOY_ENV=ci -T pender bundle exec rake "parallel:test[3]"
docker compose -f docker-test.yml exec -e TEST_RETRY_COUNT=$TEST_RETRY_COUNT -e DEPLOY_ENV=ci -T pender bundle exec rake parallel:spec
- name: Upload coverage to CodeClimate
id: upload-coverage
env:
GIT_SHA: ${{ github.sha }}
GIT_COMMITED_AT: ${{ github.event.head_commit.timestamp }}
run: |
docker compose -f docker-test.yml exec -T pender cat tmp/performance.csv
docker compose -f docker-test.yml exec -T pender ls -l coverage/
docker cp pender-pender-1:/app/pender/tmp/performance.csv performance.csv
docker cp pender-pender-1:/app/pender/coverage/.resultset.json test/.resultset.json
# pulled from test/test-coverage
printf '#!/bin/bash\ngo run /tmp/go/src/github.com/codeclimate/test-reporter/main.go $@\n' > test/cc-test-reporter && chmod +x test/cc-test-reporter
export GOPATH=/tmp/go
go env -w GO111MODULE=off
mkdir -p /tmp/go/src/github.com/codeclimate
git clone -b 0.10.3 https://github.com/codeclimate/test-reporter /tmp/go/src/github.com/codeclimate/test-reporter
cd test
echo '------ .resultset.json START ------'
cat .resultset.json # Debugging
echo '------- .resultset.json END -------'
GIT_COMMIT_SHA=$GIT_SHA GIT_COMMITTED_AT=$GIT_COMMITTED_AT ./cc-test-reporter format-coverage .resultset.json --input-type simplecov --output codeclimate.json
cat codeclimate.json
# cat codeclimate.json | sed 's/\/app\///g' | ./cc-test-reporter upload-coverage -r $cc_test_reporter_id --input -
- name: Reset cache
id: reset-cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache