-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 changed file
with
91 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Docker Image CI | ||
|
||
on: | ||
push: | ||
branches: [ 'dev' ] | ||
pull_request: | ||
branches: [ 'dev' ] | ||
release: | ||
types: [published] | ||
|
||
env: | ||
IMAGE: jirinovo/scdrake-test | ||
TEST_TAG: test | ||
|
||
jobs: | ||
docker: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Debug | ||
run: | | ||
echo "github.ref -> ${{ github.ref }}" | ||
echo "github.ref_type -> ${{ github.ref_type }}" | ||
echo "github.ref_name -> ${{ github.ref_name }}" | ||
echo "github.event.release.tag_name -> ${{ github.event.release.tag_name }}" | ||
- name: Check that tag matches package version in DESCRIPTION | ||
if: github.event_name == 'release' | ||
run: | | ||
pkg_version="$(grep -P '^Version: \d+\.\d+\.\d+$' DESCRIPTION | cut -d' ' -f2)" | ||
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: Build and export to Docker | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
load: true | ||
tags: ${{ env.IMAGE }}:${{ env.TEST_TAG }} | ||
- 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 | ||
run: | | ||
docker exec -it -u rstudio -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 | ||
- name: Remove test image | ||
run: | | ||
docker stop scdrake_test | ||
docker rmi ${{ env.IMAGE }}:${{ env.TEST_TAG }} | ||
- 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}', 'dev') }} | ||
type=semver,pattern={{version}} | ||
- name: Build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
# platforms: linux/amd64,linux/arm64 | ||
platforms: linux/amd64 | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
- 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 }} |