change Docker cache mode #23
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: Docker Image CI | |
on: | |
push: | |
branches: [ 'docker-ci-test' ] | |
pull_request: | |
branches: [ 'docker-ci-test' ] | |
release: | |
types: [published] | |
env: | |
IMAGE: jirinovo/scdrake | |
TEST_TAG: test | |
jobs: | |
docker-build-test-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Get scdrake package version from DESCRIPTION | |
run: | | |
pkg_version=$(grep -P '^Version: \d+\.\d+\.\d+$' DESCRIPTION | cut -d' ' -f2) | |
echo "pkg_version=$pkg_version" >> $GITHUB_ENV | |
echo "scdrake package version: $pkg_version" | |
- name: Check that tag matches package version in DESCRIPTION | |
if: github.event_name == 'release' | |
run: | | |
echo "pkg_version: $pkg_version" | |
test -n "$pkg_version" || (echo "'Version:' not found in DESCRIPTION" && false) | |
test "v$pkg_version" == "${{ github.event.release.tag_name }}" \ | |
|| (echo "'Version: $pkg_version' in DESCRIPTION does not match current git tag ('${{ github.event.release.tag_name }}')" && false) | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Free Disk Space (Ubuntu) | |
uses: jlumbroso/free-disk-space@main | |
with: | |
tool-cache: false | |
android: true | |
dotnet: true | |
haskell: true | |
large-packages: false | |
docker-images: false | |
swap-storage: true | |
- name: Build and export test image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
build-args: | | |
"SCDRAKE_VERSION=${{ env.pkg_version }}" | |
load: true | |
tags: ${{ env.IMAGE }}:${{ env.TEST_TAG }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=min | |
- name: Run test image | |
run: | | |
docker run -d \ | |
--name scdrake_test \ | |
-v $(pwd):/home/rstudio/scdrake_source \ | |
-e USERID=$(id -u) \ | |
-e GROUPID=$(id -g) \ | |
${{ env.IMAGE }}:${{ env.TEST_TAG }} | |
- name: Test image | |
id: testImage | |
run: | | |
docker exec -w /home/rstudio/scdrake_source scdrake_test \ | |
r --interactive -L /usr/local/lib/R/site-library -t dev/run_tests.R \ | |
--no-test-pipeline \ | |
--output-dir /home/rstudio/scdrake_test_summary | |
- name: Copy and compress test results | |
if: steps.testImage.outcome == 'failure' | |
run: | | |
docker cp scdrake_test:/home/rstudio/scdrake_test_summary / | |
tar czf /scdrake_test_summary.tar.gz /scdrake_test_summary | |
- name: Upload test results | |
if: steps.testImage.outcome == 'failure' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: scdrake_test_summary | |
path: /scdrake_test_summary.tar.gz | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.IMAGE }} | |
tags: | | |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'docker-ci-test') }} | |
type=semver,pattern={{version}} | |
- name: Build and push image to Docker Hub | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
build-args: | | |
"SCDRAKE_VERSION=${{ env.pkg_version }}" | |
# platforms: linux/amd64,linux/arm64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Rollback release | |
if: github.event_name == 'release' && failure() | |
uses: author/action-rollback@stable | |
with: | |
tag: ${{ github.event.release.tag_name }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |