forked from carpentries-incubator/scons-novice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
123 lines (118 loc) · 4.51 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
123 lines (118 loc) · 4.51 KB
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
workflow:
rules: # Do not create pipelines for tag updates
- if: $CI_COMMIT_TAG
when: never
- when: always
stages:
- environment
- test
- deploy
before_script:
- project_name='scons-novice'
# Assume AEA server
- aea_compute_path="/projects/aea_compute"
- scratch_path="/scratch/${USER}"
- ci_environment_path="${aea_compute_path}"
- echo ${aea_compute_path}
- echo ${scratch_path}
- echo ${ci_environment_path}
- if [[ ! -d ${aea_compute_path} ]]; then exit 1; fi
- if [[ ! -d ${scratch_path} ]]; then exit 1; fi
- if [[ ! -d ${ci_environment_path} ]]; then exit 1; fi
# Prep module command and load system module(s)
- aea_modulefiles="${aea_compute_path}/modulefiles"
- module use ${aea_modulefiles}
# Start with an AEA environment to put Conda on PATH
- environment_choices="aea-nightly aea-quarterly aea-release"
- for env in ${environment_choices}; do if [[ -d "${aea_compute_path}/${env}" ]]; then base_environment=${env}; break; fi; done
- echo ${base_environment}
- if [[ -z ${base_environment} ]]; then exit 1; fi
- module load ${base_environment}
# Activate CI environment if available. If not, rely on environment job running before other jobs.
- project_environment="${project_name}-dev"
- environment_path="${ci_environment_path}/${project_environment}"
- echo ${environment_path}
- if [[ -d ${environment_path} ]]; then conda activate ${environment_path}; fi
- conda info
environment:
stage: environment
variables:
GIT_STRATEGY: clone
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "main"
script:
# Job variables
- echo ${base_environment}
- echo ${environment_path}
- echo ${aea_modulefiles}
- if [[ -z ${base_environment} ]]; then exit 1; fi
- if [[ -z ${environment_path} ]]; then exit 1; fi
- if [[ -z ${aea_modulefiles} ]]; then exit 1; fi
- echo ${CI_MERGE_REQUEST_ID}
- echo ${CI_COMMIT_BEFORE_SHA}
- echo ${CI_COMMIT_BRANCH}
# Always build from the base/aea compute environment with boa/libmamba
- if [[ ${CONDA_PREFIX} == ${environment_path} ]]; then conda deactivate; fi
# Don't rebuild environment for merge request pipelines unless the environment is missing
- if [[ -d "${environment_path}" ]]; then exists=true; else exists=false; fi
- if [[ $CI_MERGE_REQUEST_ID ]] && ${exists}; then exit 0; fi
# Don't rebuild environment for main unless the environment file has changed or the environment doesn't exist
- files=$(git diff --name-only ${CI_COMMIT_SHA} ${CI_COMMIT_BEFORE_SHA}) || true
- if [[ $CI_COMMIT_BRANCH == "main" ]]; then production=true; else production=false; fi
- if [[ "${files}" == *"environment.yml"* ]]; then modified=true; else modified=false; fi
- if ${production} && ${exists} && ! ${modified}; then exit 0; fi
# Re-build the Conda environment on changes to environment files
- conda env create --prefix ${environment_path} --file environment.yml --solver=libmamba --force
# Build the R-packages
- conda activate ${environment_path}
- PROJECT_TMPDIR="/scratch/$USER/${project_name}/workbench"
- mkdir -p ${PROJECT_TMPDIR}
- TMPDIR=${PROJECT_TMPDIR} R -e 'install.packages(c("sandpaper", "varnish", "pegboard", "tinkr"), repos = list(carpentries="https://carpentries.r-universe.dev/", CRAN="https://cloud.r-project.org"))'
# Remove write permissions from group to avoid accidental environment changes
- chmod -R 755 ${environment_path}
tags:
- shell
- aea
- linux
test:
stage: test
variables:
GIT_STRATEGY: clone
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- R -e 'sandpaper::build_lesson(preview = FALSE)'
- unzip episodes/files/scons-lesson.zip
- cd scons-lesson
- lesson_directories=(../episodes/files/code/*/)
- echo ${lesson_directories[@]}
- for directory in ${lesson_directories[@]}; do cp $directory/* .; scons . --clean && scons .; done
tags:
- shell
- aea
- linux
# It MUST be called pages
pages:
stage: deploy
variables:
GIT_STRATEGY: clone
dependencies: []
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_BRANCH == "main"
script:
- rm -rf public && mkdir -p public
- R -e 'sandpaper::build_lesson(preview = FALSE)'
- cp -r site/docs/* public
artifacts:
paths:
# It MUST be called public
- public
tags:
- shell
- aea
- linux