Last active
June 14, 2023 18:37
-
-
Save isabelatravaglia/ef453ff1c41cb31bde378376bd0d11f4 to your computer and use it in GitHub Desktop.
GHA test workflow - Using GHA service containers
This file contains hidden or 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: Test with service containers | |
on: [push] | |
jobs: | |
test: | |
env: | |
RAILS_ENV: test | |
NODE_ENV: test | |
runs-on: ubuntu-latest # runner | |
services: | |
database: | |
image: postgres | |
env: | |
POSTGRES_PASSWORD: postgres | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
chrome: | |
image: selenium/standalone-chrome-debug | |
ports: | |
- 4444:4444 | |
- 5900:5900 | |
volumes: | |
- /dev/shm:/dev/shm | |
steps: | |
- name: Output services network | |
id: network | |
run: | | |
echo ::set-output name=services_network::${{ job.container.network }} | |
echo ${{ job.container.network }} | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
with: | |
version: latest | |
install: true | |
- name: Prepare Tags | |
id: tags | |
run: | | |
TAG=$(echo $GITHUB_SHA | head -c7) | |
IMAGE="dev/test" | |
echo ::set-output name=tagged_image::${IMAGE}:${TAG} | |
echo ::set-output name=tag::${TAG} | |
- name: Cache main image layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-main-cache | |
key: ${{ runner.os }}-buildx-main-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx-main- | |
- name: Build code | |
uses: docker/build-push-action@v2 | |
with: | |
push: false | |
file: .ci-services/Dockerfile-services.ci | |
load: true | |
cache-from: type=local,src=/tmp/.buildx-main-cache | |
cache-to: type=local,mode=max,dest=/tmp/.buildx-main-cache-new | |
tags: ${{ steps.tags.outputs.tagged_image }} | |
- name: Run Tests | |
run: | | |
TEST_IMAGE_TAG=${{ steps.tags.outputs.tagged_image }} SERVICES_NETWORK=${{ steps.network.outputs.services_network }} docker-compose -f .ci-services/docker-compose.test.services.yml run test | |
# Temp fix for growing cache | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-main-cache | |
mv /tmp/.buildx-main-cache-new /tmp/.buildx-main-cache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Amazing! Managed to get integration tests set-up on GHA with
redis
,mysql
andscireum/s3-ninja
in about 30 minutes. Thank you! 🙇