generated from pharmaverse/admiraltemplate
-
Notifications
You must be signed in to change notification settings - Fork 4
135 lines (116 loc) · 5.43 KB
/
push-docker-image.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
---
name: Deploy Docker Image
on:
workflow_dispatch: # give possibility to run it manually
schedule:
- cron: '0 0 * * Wed,Sun' # Run every day at midnight UTC
permissions: write-all
env:
REGISTRY: ghcr.io
R_REPOS: "https://cran.r-project.org"
OLD_RELEASE: "4.3"
concurrency:
group: deploy-docker-image-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
get_old_release:
runs-on: ubuntu-latest
outputs:
oldrel: ${{ steps.oldrelease.outputs.oldrelease }}
steps:
- name: get old release
id: oldrelease
run:
echo "oldrelease=${{ env.OLD_RELEASE }}" >> $GITHUB_OUTPUT
deploy-image:
runs-on: ubuntu-latest
needs: [ "get_old_release" ]
strategy:
fail-fast: false # if one of the job "deploy-image" fails, the other parallel jobs will just continue
matrix:
tags: ["devel", "latest", "${{ needs.get_old_release.outputs.oldrel }}"]
# Token permissions
permissions:
contents: read
packages: write
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Print message
run: |
echo "updating docker image for R version ${{ matrix.tags }}"
- name: Set image specs
id: image_specs
run: |
package_name=$(grep "Package:" DESCRIPTION | awk '{print $NF}')
if [ "${{ matrix.tags }}" == "latest" ]; then image_name="$package_name-release"; else image_name="$package_name-${{ matrix.tags }}"; fi
if [ "${{ matrix.tags }}" == "devel" ]; then R_REPOS="https://packagemanager.posit.co/cran/__linux__/focal/latest"; fi
echo "r_repos=$R_REPOS" >> $GITHUB_OUTPUT
r_version="${{ matrix.tags }}"
if [ "$r_version" == "${{ env.OLD_RELEASE }}" ]; then image_name="$package_name-oldrel"; fi # TODO: del temporary -test suffix for testing
echo "image_name=$image_name" >> $GITHUB_OUTPUT
- name: Call deploy docker image action ${{ matrix.tags }}
uses: insightsengineering/r-image-creator@install_suggests_deps
with:
image-name: "${{ steps.image_specs.outputs.image_name }}"
tag-latest: true
base-image: "rocker/rstudio:${{ matrix.tags }}"
sysdeps: qpdf,libxt-dev,curl,npm,libicu-dev,libcurl4-openssl-dev,libssl-dev,make,zlib1g-dev,libfontconfig1-dev,libfreetype6-dev,libfribidi-dev,libharfbuzz-dev,libjpeg-dev,libpng-dev,libtiff-dev,pandoc,libxml2-dev,libgit2-dev,libgit2-dev,jq
description-file: "https://raw.githubusercontent.com/pharmaverse/admiral/main/DESCRIPTION"
repository-owner: ${{ github.repository_owner }}
repo-user: ${{ github.actor }}
repo-token: "${{ secrets.GITHUB_TOKEN }}"
repos: ${{ steps.image_specs.outputs.r_repos }}
packages: "DT,R.cache,R.methodsS3,R.oo,R.utils,backports,cellranger,collections,covr,crosstalk,cyclocomp,diffdf,git2r,hunspell,languageserver,lazyeval,lintr,progress,readxl,rematch,renv,rex,spelling,staged.dependencies,styler,xmlparsedata"
store_deps:
name: Store Deps
runs-on: ubuntu-latest
needs: [ "get_old_release", "deploy-image" ]
container:
image: "ghcr.io/pharmaverse/admiralci-${{ matrix.tags }}:latest"
strategy:
fail-fast: false # if one of the job "deploy-image" fails, the other parallel jobs will just continue
matrix:
tags: ["devel", "latest", "${{ needs.get_old_release.outputs.oldrel }}"]
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Store deps into csv file - image ${{ matrix.tags }}
id: store_deps
run: |
installed_packages <- as.data.frame(installed.packages())
r_version <- "${{ matrix.tags }}"
if (r_version == "${{ needs.get_old_release.outputs.oldrel }}"){
r_version <- "oldrelease"
}
content <- sprintf("r_version=%s\n", r_version)
output_file <- Sys.getenv("GITHUB_OUTPUT")
write(content, file = output_file, append = TRUE)
write.csv(installed_packages, sprintf("/workspace/deps-%s.csv", r_version), row.names = FALSE)
shell: Rscript {0}
- name: Upload deps.csv artifact
uses: actions/upload-artifact@v4
with:
name: deps
path: "/workspace/deps-${{ steps.store_deps.outputs.r_version }}.csv"
- name: Delete current release existing artifacts
uses: mknejp/delete-release-assets@v1
with:
token: ${{ github.token }}
tag: "latest"
fail-if-no-assets: false
assets: |
Dependencies.list.of.docker.image.admiralci-${{ steps.store_deps.outputs.r_version }}.csv
- name: Upload SBOM to release 🔼
uses: svenstaro/upload-release-action@v2
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
file: "/workspace/deps-${{ steps.store_deps.outputs.r_version }}.csv"
asset_name: "Dependencies list of docker image admiralci-${{ steps.store_deps.outputs.r_version }}.csv"
tag: "latest"
overwrite: true
# refacto todo: image-name, sysdeps on get-renv-list job
# note: in case of 403 error when pushing to ghcr : link current repo to the given package registry - https://github.com/docker/build-push-action/issues/687
# (got to https://github.com/<user name>?tab=packages to go to packages settings) and there https://github.com/users/<user name>/packages/container/admiralci-4.0/settings