This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
301 lines (250 loc) · 11.3 KB
/
build.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# build and test PythonEmbedInR. Additionally deploys to S3 RAN server on GitHub release.
name: build
on:
push:
# we build/test all pushed branches, but not tags.
# we only push tags with releases, and we handle releases explicitly
branches:
- '**'
tags-ignore:
- '**'
pull_request:
release:
types:
- 'published'
jobs:
build:
runs-on: ${{ matrix.os }}
outputs:
package_version: ${{ steps.shared-env.outputs.package_version }}
r_minor_version: ${{ steps.shared-env.outputs.r_minor_version }}
strategy:
matrix:
os: [ubuntu-18.04, windows-2019, macos-mojave]
r: [4.1, 4.2]
steps:
- name: checkout
uses: actions/checkout@v2
- uses: actions/checkout@master
- name: setup-r
if: ${{matrix.os != 'macos-mojave'}}
uses: r-lib/actions/setup-r@v1
with:
r-version: ${{ matrix.r }}
- name: shared-env
id: shared-env
shell: bash
run: |
PACKAGE_NAME=PythonEmbedInR
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
PACKAGE_VERSION=$(grep "Version: " DESCRIPTION | awk '{print $2'})
# if this was triggered by a release and the release tag
# looks like semver then we use that for the package version.
RELEASE_TAG=${{ github.event.release.tag_name }}
if [[ $RELEASE_TAG =~ ^v?([[:digit:]\.]+)(-rc)? ]]; then
RELEASE_VERSION="${BASH_REMATCH[1]}.$GITHUB_RUN_NUMBER"
# a release version overrides the package version
# for purposes of creating artifacts
PACKAGE_VERSION=$RELEASE_VERSION
DATE=`date +%Y-%m-%d`
# replace DESCRIPTION with $VERSION & $DATE
# sed -i not portable on OSX so we wash through some temp files instead
sed "s|^Version: .*$|Version: $PACKAGE_VERSION|g" DESCRIPTION > DESCRIPTION.temp
sed "s|^Date: .*$|Date: $DATE|g" DESCRIPTION.temp > DESCRIPTION2.temp
rm DESCRIPTION
mv DESCRIPTION2.temp DESCRIPTION
rm DESCRIPTION.temp
fi
echo "BRANCH_VERSION=$BRANCH_VERSION" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
R_VERSION=${{matrix.r}}
R_MAJOR_VERSION=$(echo $R_VERSION | cut -f1 -d".")
R_MINOR_VERSION=$R_MAJOR_VERSION.$(echo $R_VERSION | cut -f2 -d".")
echo "R_VERSION=$R_VERSION" >> $GITHUB_ENV
echo "R_MAJOR_VERSION=$R_MAJOR_VERSION" >> $GITHUB_ENV
echo "R_MINOR_VERSION=$R_MINOR_VERSION" >> $GITHUB_ENV
# replace backslashes with forward slashes for windows.
# windows bash will handle forward slashes fine and this
# makes it easier to unify the path handling.
R_LIBS_USER_SANITIZED=$(echo $R_LIBS_USER | sed 's/\\/\//g')
echo "R_LIBS_USER=$R_LIBS_USER_SANITIZED" >> $GITHUB_ENV
echo "::set-output name=package_version::$PACKAGE_VERSION"
echo "::set-output name=r_minor_version::$R_MINOR_VERSION"
- name: setup-r-mac-mojave
if: ${{matrix.os == 'macos-mojave'}}
run: |
# on macos mojave we use a self-hosted runner we swap among the pre-installed R versions
rm -rf /Library/Frameworks/R.framework/Versions/Current
ln -s /Library/Frameworks/R.framework/Versions/$R_MINOR_VERSION /Library/Frameworks/R.framework/Versions/Current
R_LIBS_USER=${GITHUB_WORKSPACE}/R_LIBS
rm -rf $R_LIBS_USER
mkdir -p $R_LIBS_USER
echo "R_LIBS_USER=$R_LIBS_USER" >> $GITHUB_ENV
echo "R=R" >> $GITHUB_ENV
- name: install-R-lib-deps
shell: bash
run: |
# we prefer binary installs wherever available for speed,
# even if the binary is somewhat out of date.
# this also insulates us from compilation issues that might
# arise in upstream packages.
if [[ ${{ runner.os }} == 'Linux' ]]; then
INSTALL_TYPE='source'
else
INSTALL_TYPE='binary'
fi
echo "list.of.packages <- c('pack', 'R6', 'testthat', 'rjson', 'rlang');" >> installReqPkgs.R
echo "if(length(list.of.packages)) install.packages(list.of.packages, repos='http://cran.fhcrc.org', type=\"${INSTALL_TYPE}\", destdir=\"${R_LIBS_USER}\")" >> installReqPkgs.R
R --vanilla < installReqPkgs.R
- name: linux-build-package
if: ${{runner.os == 'Linux'}}
run: |
R CMD build ./
R CMD INSTALL ./ --library=$R_LIBS_USER --no-test-load
echo "ARTIFACT_EXTENSION=tar.gz" >> $GITHUB_ENV
- name: mac-build-package
if: ${{runner.os == 'macOS'}}
run: |
R CMD build ./
R CMD INSTALL --build ${PACKAGE_NAME}_${PACKAGE_VERSION}.tar.gz --library=$R_LIBS_USER --no-test-load
## Now fix the binaries, per SYNR-341:
# it's v 3.0 or greater, with just one platform
mkdir -p ${PACKAGE_NAME}/libs
cp $R_LIBS_USER/${PACKAGE_NAME}/libs/PythonEmbedInR.so ${PACKAGE_NAME}/libs
install_name_tool -change "/Library/Frameworks/R.framework/Versions/${R_MINOR_VERSION}/Resources/lib/libR.dylib" "/Library/Frameworks/R.framework/Versions/Current/Resources/lib/libR.dylib" ${PACKAGE_NAME}/libs/PythonEmbedInR.so
# update archive with modified binaries
for f in *.tgz
do
prefix="${f%.*}"
gunzip "$f"
# Note, >=3.0 there is only one platform
tar -rf "$prefix".tar ${PACKAGE_NAME}/libs/PythonEmbedInR.so
rm "$prefix".tar.gz
gzip "$prefix".tar
mv "$prefix".tar.gz "$prefix".tgz
done
echo "ARTIFACT_EXTENSION=tgz" >> $GITHUB_ENV
- name: windows-build-package
if: ${{runner.os == 'Windows'}}
shell: bash
run: |
R CMD build ./
R CMD INSTALL --build ${PACKAGE_NAME}_${PACKAGE_VERSION}.tar.gz --library=$R_LIBS_USER --no-test-load --merge-multiarch
echo "ARTIFACT_EXTENSION=zip" >> $GITHUB_ENV
- name: run-tests
shell: bash
run: |
echo ".libPaths(c('$R_LIBS_USER', .libPaths()));" > runTests.R
echo "setwd(sprintf('%s/tests', getwd()));" >> runTests.R
echo "source('testthat.R')" >> runTests.R
echo "library(PythonEmbedInR);" >> runTests.R
echo "detach(\"package:PythonEmbedInR\", unload=TRUE);" >> runTests.R
echo "library(PythonEmbedInR)" >> runTests.R
R --vanilla < runTests.R
- name: artifact-name
shell: bash
run: |
# we format our artifact names so we align to the same pattern
# used by the deploy gist written to work with jenkins.
ARTIFACT_NAME="${PACKAGE_NAME}_${PACKAGE_VERSION}.${ARTIFACT_EXTENSION}"
OS_LABEL=$(echo ${{runner.os}} | tr '[:upper:]' '[:lower:]')
if [[ "$OS_LABEL" == "macos" ]]; then
OS_LABEL="mac"
fi
UPLOAD_NAME="label=${OS_LABEL}-RVERS-$R_MINOR_VERSION"
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> $GITHUB_ENV
echo "UPLOAD_NAME=$UPLOAD_NAME" >> $GITHUB_ENV
- name: upload-artifact
uses: actions/upload-artifact@v2
with:
name: ${{env.UPLOAD_NAME}}
path: ${{env.ARTIFACT_NAME}}
deploy:
runs-on: ubuntu-18.04
needs: build
if: github.event_name == 'release'
outputs:
s3_ran: ${{ steps.deploy-to-target.outputs.s3_ran }}
steps:
- name: check-deployment-target
id: check-deployment-target
if: ${{github.event.action == 'published'}}
shell: bash
run: |
DEPLOY_TARGET=""
RELEASE_VERSION=""
RELEASE_TAG=${{ github.event.release.tag_name }}
if [[ $RELEASE_TAG =~ ^v?([[:digit:]\.]+)(-rc)? ]]; then
RELEASE_VERSION="${BASH_REMATCH[1]}"
echo $RELEASE_VERSION
if [[ -n "$RELEASE_VERSION" ]]; then
if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then
DEPLOY_TARGET="staging"
else
DEPLOY_TARGET="prod"
fi
fi
fi
echo "DEPLOY_TARGET=$DEPLOY_TARGET" >> $GITHUB_ENV
echo "::set-output name=deploy_target::$DEPLOY_TARGET"
- name: download-artifacts
uses: actions/download-artifact@v2
if: ${{steps.check-deployment-target.outputs.deploy_target != ''}}
with:
path: deploy_artifacts
- name: deploy-to-target
id: deploy-to-target
if: ${{steps.check-deployment-target.outputs.deploy_target != ''}}
shell: bash
run: |
# we use a gist to upload and the gist internally uses R so we need R on this runner.
# TODO maybe create a docker image to run this with R preloaded (and/or an action).
sudo apt-get -y update && sudo apt-get -y install r-base
export ARTIFACTS_DIR=deploy_artifacts
if [[ "$DEPLOY_TARGET" == "staging" ]]; then
export AWS_ACCESS_KEY_ID=${{secrets.S3_RAN_STAGING_AWS_ACCESS_KEY_ID}}
export AWS_SECRET_ACCESS_KEY=${{secrets.S3_RAN_STAGING_AWS_SECRET_ACCESS_KEY}}
export AWS_DEFAULT_REGION=us-east-1
export S3_RAN=staging-ran.synapse.org
elif [[ "$DEPLOY_TARGET" == "prod" ]]; then
export AWS_ACCESS_KEY_ID=${{secrets.S3_RAN_PROD_AWS_ACCESS_KEY_ID}}
export AWS_SECRET_ACCESS_KEY=${{secrets.S3_RAN_PROD_AWS_SECRET_ACCESS_KEY}}
export AWS_DEFAULT_REGION=us-east-1
export S3_RAN=ran.synapse.org
fi
curl -s https://raw.githubusercontent.com/Sage-Bionetworks/CI-Build-Tools/master/r-pkg/deploy.sh | bash
echo "::set-output name=s3_ran::$S3_RAN"
# on each of our matrix platforms, download the newly uploaded package from RAN
check-deploy:
needs:
[build, deploy]
strategy:
matrix:
os: [ubuntu-18.04, windows-2019, macos-mojave]
r: [4.1, 4.2]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master
- name: setup-r
if: ${{matrix.os != 'macos-mojave'}}
uses: r-lib/actions/setup-r@v1
with:
r-version: ${{ matrix.r }}
- name: setup-r-mac-mojave
if: ${{matrix.os == 'macos-mojave'}}
run: |
# on macos mojave we use a self-hosted runner we swap among the pre-installed R versions
R_MINOR_VERSION="${{ needs.build.outputs.r_minor_version }}"
rm -rf /Library/Frameworks/R.framework/Versions/Current
ln -s /Library/Frameworks/R.framework/Versions/$R_MINOR_VERSION /Library/Frameworks/R.framework/Versions/Current
- name: check-install
shell: bash
run: |
RAN="http://${{ needs.deploy.outputs.s3_ran }}"
VERSION_TO_CHECK="${{ needs.build.outputs.package_version }}"
PACKAGE="PythonEmbedInR"
echo "if (available.packages(repos='$RAN')['$PACKAGE','Version'] != '$VERSION_TO_CHECK') { quit(save = 'no', status = 1) }" > test.R
echo "try(remove.packages('$PACKAGE'), silent=T)" >> test.R
echo "install.packages('$PACKAGE', repos=c('$RAN', 'http://cran.fhcrc.org'))" >> test.R
echo "library('$PACKAGE')" >> test.R
R --vanilla < test.R