-
Notifications
You must be signed in to change notification settings - Fork 3
152 lines (149 loc) · 5.55 KB
/
docker-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Docker Image CI
on:
push:
branches: [ 'main' ]
pull_request:
branches: [ 'main' ]
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
run: |
sudo rm -rf \
/usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \
/usr/lib/jvm || true
# - 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: Render README.md
run: |
docker exec -w /home/rstudio/scdrake_source scdrake_test \
Rscript -e 'rmarkdown::render("README.Rmd")'
set +e
git diff --exit-code README.md
exit_code=$?
set -e
# If exit code is > 0, then there are changes and README.md was not commited
test $exit_code -eq 0 || (echo "README.Rmd has changed, but an updated version of README.md was not included in this commit" && false)
- name: Test image
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 test results
if: always()
run: |
sudo docker cp scdrake_test:/home/rstudio/scdrake_test_summary /
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: scdrake_test_summary
path: /scdrake_test_summary/
- 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}', 'main') }}
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
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=min
- name: Remove devel mode from _pkgdown.yml
if: github.event_name == 'release'
run: |
docker exec -w /home/rstudio/scdrake_source scdrake_test \
bash -c 'sed -i "/development:/d" _pkgdown.yml; sed -i "/mode: devel/d" _pkgdown.yml'
- name: Build pkgdown site
run: |
docker exec -w /home/rstudio/scdrake_source scdrake_test \
Rscript -e "pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)"
- name: Deploy to GitHub pages (stable docs)
if: github.event_name == 'release'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
- name: Deploy to GitHub pages (devel docs)
if: github.event_name == 'push'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs/dev
target-folder: dev
- 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 }}