Skip to content

Commit

Permalink
Adds testing
Browse files Browse the repository at this point in the history
  • Loading branch information
danschmidt5189 committed Dec 4, 2024
1 parent 45f558e commit 6311df2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 50 deletions.
47 changes: 41 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ jobs:
run: |
echo "build_url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" >> "$GITHUB_OUTPUT"
build:
test:
if: github.event_name != 'release'

needs: setup

env:
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml

outputs:
imageid: ${{ steps.image }}

permissions:
packages: write
contents: read
Expand All @@ -35,10 +41,10 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Construct image tags and labels
id: meta
- id: meta
name: Construct image tags and labels
uses: docker/metadata-action@v5
with:
images: |
Expand All @@ -57,8 +63,9 @@ jobs:
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push Docker image
uses: docker/build-push-action@v3
- id: image
name: Build the docker image
uses: docker/build-push-action@v6
with:
context: .
push: false
Expand All @@ -70,3 +77,31 @@ jobs:
GIT_SHA=${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}

- name: Set the application image
run: |
echo DOCKER_APP_IMAGE=${{ steps.image.outputs.imageid }} >> "$GITHUB_ENV"
- name: Start the stack
run: |
docker compose up --build --detach
sleep 10
docker compose exec app assets:precompile db:setup
- name: Run RSpec tests
run: |
docker compose exec -e RAILS_ENV=test app rake
- name: Extract service logs
if: ${{ always() }}
run: |
mkdir -p tmp/artifacts
docker compose logs > tmp/artifacts/docker-compose.log
docker compose cp app:/opt/app/artifacts/ tmp/
- name: Upload testing artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: test-results
path: tmp/artifacts
29 changes: 1 addition & 28 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,7 @@ task setup: %w[db:setup]
# Check (setup + coverage)

desc 'Set up, check test coverage'
task :check do
raise "Can't run specs; expected RAILS_ENV=\"test\", was #{Rails.env.inspect}" unless Rails.env.test?

require 'solr_wrapper'
Rake::Task[:setup].invoke
SolrWrapper.wrap(persist: true, solr_options: { force: true }) do |solr|
solr.with_collection(name: 'geodata-test', dir: "#{Rails.root}/config/solr") do

# Rake::Task[:coverage].invoke
# Rake::Task['solr:restart'].invoke
Rake::Task['geoblacklight:index:seed'].invoke
# Rake::Task[:prepare_solr].invoke
Rake::Task[:spec].invoke
end
end
end

# desc 'Set up, check test coverage'
# task :check do
# raise "Can't run specs; expected RAILS_ENV=\"test\", was #{Rails.env.inspect}" unless Rails.env.test?

# Rake::Task[:setup].invoke
# # Rake::Task[:coverage].invoke
# # Rake::Task['solr:restart'].invoke
# # Rake::Task['geoblacklight:index:seed'].invoke
# #Rake::Task[:prepare_solr].invoke
# Rake::Task[:spec].invoke
# end
task check: %w[setup geoblacklight:index:seed spec]

# clear rspec/rails default :spec task
Rake::Task[:default].clear if Rake::Task.task_defined?(:default)
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---

services:
adminer: !reset

app:
build: !reset
image: ${DOCKER_APP_IMAGE}
ports: !reset
volumes: !reset

db:
ports: !reset

solr:
ports: !reset
23 changes: 7 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
---

services:
adminer:
image: adminer
restart: always
ports:
- 8080:8080

app:
build:
context: .
target: ${DOCKER_APP_BUILD_TARGET:-development}
args:
- BUILD_TIMESTAMP=${BUILD_TIMESTAMP}
- BUILD_URL=https://github.com/${GITHUB_REPOSITORY:-berkeleylibrary/geodata}/actions/runs/${GITHUB_RUN_ID:-development}
- DOCKER_TAG=${BUILD_IMAGE}
- GIT_BRANCH=${GIT_REF_NAME}
- GIT_COMMIT=${GIT_SHA}
- GIT_URL=${GIT_REPOSITORY_URL}
tags:
- ghcr.io/berkeleylibrary/geodata:${DOCKER_APP_TAG}
target: development
depends_on:
- db
- solr
Expand All @@ -26,12 +23,6 @@ services:
volumes:
- ./:/opt/app:delegated

adminer:
image: adminer
restart: always
ports:
- 8080:8080

db:
image: postgres:12.2
restart: always
Expand Down

0 comments on commit 6311df2

Please sign in to comment.