forked from exercism/ruby-test-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
458 additions
and
83 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,56 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
unit_tests: | ||
name: Unit tests | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
# Checkout using GitHub's checkout action | ||
- uses: actions/checkout@v3 | ||
- name: Checkout code | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | ||
|
||
# Setup Ruby - this needs to match the version in the Gemfile | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 | ||
- name: Setup Ruby | ||
uses: ruby/setup-ruby@22fdc77bf4148f810455b226c90fb81b5cbc00a7 | ||
with: | ||
ruby-version: 3.0.2 | ||
ruby-version: .ruby-version | ||
bundler-cache: true | ||
|
||
# Setup code climate | ||
- 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 | ||
./cc-test-reporter before-build | ||
# Run the tests | ||
- name: Run Ruby tests | ||
env: | ||
CAPTURE_CODE_COVERAGE: true | ||
run: | | ||
bundle exec rake test | ||
./cc-test-reporter format-coverage -t simplecov -o codeclimate.backend.json coverage/backend/.resultset.json | ||
# Publish the coverage to CodeClimate | ||
- name: Publish code coverage | ||
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | ||
env: | ||
GIT_BRANCH: ${GITHUB_REF/refs\/heads\//} | ||
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} | ||
run: | | ||
./cc-test-reporter upload-coverage -i codeclimate.*.json | ||
- name: Install gems | ||
run: bundle install | ||
|
||
- name: Run tests | ||
run: bundle exec rake test | ||
|
||
smoke_tests: | ||
name: Smoke tests | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 | ||
with: | ||
install: true | ||
|
||
- name: Build Docker image and store in cache | ||
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 | ||
with: | ||
context: . | ||
push: false | ||
load: true | ||
tags: exercism/ruby-test-runner | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
- name: Run Tests in Docker | ||
run: bin/run-tests-in-docker.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules/ | ||
tests/**/results.json |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ruby-3.0.2 | ||
ruby-3.2.2 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
FROM ruby:3.0.2-alpine | ||
FROM ruby:3.2.2-alpine3.18 AS build | ||
|
||
RUN apk update && apk upgrade && \ | ||
apk add --no-cache bash git openssh && \ | ||
apk add build-base gcc wget git | ||
apk add --no-cache git openssh build-base gcc wget git | ||
|
||
RUN wget -P /usr/local/bin https://github.com/exercism/tooling-webserver/releases/latest/download/tooling_webserver && \ | ||
chmod +x /usr/local/bin/tooling_webserver | ||
COPY Gemfile Gemfile.lock . | ||
|
||
WORKDIR /opt/test-runner | ||
|
||
COPY Gemfile Gemfile.lock ./ | ||
RUN gem install bundler:2.2.29 && \ | ||
RUN gem install bundler:2.4.18 && \ | ||
bundle config set without 'development test' && \ | ||
bundle install | ||
|
||
FROM ruby:3.2.2-alpine3.18 | ||
|
||
RUN apk add --no-cache bash | ||
|
||
WORKDIR /opt/test-runner | ||
|
||
COPY --from=build /usr/local/bundle /usr/local/bundle | ||
|
||
COPY . . | ||
|
||
ENTRYPOINT [ "sh", "/opt/test-runner/bin/run.sh" ] |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/bash | ||
|
||
git diff --name-status --staged | grep '^[MA]' | grep -o '\s\+.*rb' | xargs bundle exec rubocop --except Metrics --auto-correct --format quiet --force-exclusion Gemfile && \ | ||
git diff --name-status --staged | grep '^[MA]' | grep -o '\s\+.*rb' | xargs bundle exec rubocop --except Metrics --autocorrect --format quiet --force-exclusion Gemfile && \ | ||
git diff --name-status --staged | grep '^[MA]' | grep -o '\s\+.*rb' | xargs git add |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Synopsis: | ||
# Run the test runner on a solution using the test runner Docker image. | ||
# The test runner Docker image is built automatically. | ||
|
||
# Arguments: | ||
# $1: exercise slug | ||
# $2: path to solution folder | ||
# $3: path to output directory | ||
|
||
# Output: | ||
# Writes the test results to a results.json file in the passed-in output directory. | ||
# The test results are formatted according to the specifications at https://github.com/exercism/docs/blob/main/building/tooling/test-runners/interface.md | ||
|
||
# Example: | ||
# ./bin/run-in-docker.sh two-fer path/to/solution/folder/ path/to/output/directory/ | ||
|
||
# Stop executing when a command returns a non-zero return code | ||
set -e | ||
|
||
# If any required arguments is missing, print the usage and exit | ||
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then | ||
echo "usage: ./bin/run-in-docker.sh exercise-slug path/to/solution/folder/ path/to/output/directory/" | ||
exit 1 | ||
fi | ||
|
||
slug="$1" | ||
solution_dir=$(realpath "${2%/}") | ||
output_dir=$(realpath "${3%/}") | ||
|
||
# Create the output directory if it doesn't exist | ||
mkdir -p "${output_dir}" | ||
|
||
# Build the Docker image | ||
docker build --rm -t exercism/ruby-test-runner . | ||
|
||
# Run the Docker image using the settings mimicking the production environment | ||
docker run \ | ||
--rm \ | ||
--network none \ | ||
--read-only \ | ||
--mount type=bind,src="${solution_dir}",dst=/solution \ | ||
--mount type=bind,src="${output_dir}",dst=/output \ | ||
--mount type=tmpfs,dst=/tmp \ | ||
exercism/ruby-test-runner "${slug}" /solution /output |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Synopsis: | ||
# Test the test runner Docker image by running it against a predefined set of | ||
# solutions with an expected output. | ||
# The test runner Docker image is built automatically. | ||
|
||
# Output: | ||
# Outputs the diff of the expected test results against the actual test results | ||
# generated by the test runner Docker image. | ||
|
||
# Example: | ||
# ./bin/run-tests-in-docker.sh | ||
|
||
# Stop executing when a command returns a non-zero return code | ||
set -e | ||
|
||
# Build the Docker image | ||
docker build --rm -t exercism/ruby-test-runner . | ||
|
||
# Run the Docker image using the settings mimicking the production environment | ||
docker run \ | ||
--rm \ | ||
--network none \ | ||
--read-only \ | ||
--mount type=bind,src="${PWD}/tests",dst=/opt/test-runner/tests \ | ||
--mount type=tmpfs,dst=/tmp \ | ||
--volume "${PWD}/bin/run-tests.sh:/opt/test-runner/bin/run-tests.sh" \ | ||
--workdir /opt/test-runner \ | ||
--entrypoint /opt/test-runner/bin/run-tests.sh \ | ||
exercism/ruby-test-runner |
Oops, something went wrong.