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
name: C++ Build (Сборка проекта) | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Set up Docker Buildx | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
# Cache Docker layers | |
- name: Cache Docker layers | |
id: cache-docker-layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-docker-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-docker- | |
# Build Docker image | |
- name: Build Docker image | |
run: | | |
docker buildx build --cache-from=type=local,src=/tmp/.buildx-cache --cache-to=type=local,dest=/tmp/.buildx-cache,mode=max -t my-cpp-image -f docker/image/Dockerfile . | |
# Run Docker container | |
- name: Run Docker Compose | |
run: | | |
docker compose up --abort-on-container-exit --exit-code-from bmstu | |
# Save Docker layer cache | |
- name: Save Docker layer cache | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: docker-layer-cache | |
path: /tmp/.buildx-cache | |
run_tests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download Docker layer cache | |
id: download-docker-layer-cache | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-docker-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-docker- | |
- name: Load Docker image from cache | |
run: | | |
docker buildx build --load --cache-from=type=local,src=/tmp/.buildx-cache -t my-cpp-image -f docker/image/Dockerfile . | |
- name: Run custom script "run.sh" | |
run: | | |
docker run --rm -v $(pwd):/workspace -w /workspace my-cpp-image bash docker/run_tasks/run.sh |