Skip to content

Commit bc32fee

Browse files
committed
Update r_macos.yml
1 parent 2cfb4b6 commit bc32fee

File tree

1 file changed

+128
-10
lines changed

1 file changed

+128
-10
lines changed

.github/workflows/r_macos.yml

Lines changed: 128 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,101 @@
8585
# source flair_env/bin/activate
8686
# R CMD build --no-build-vignettes .
8787
# shell: bash
88+
# name: R-MacOS
89+
#
90+
# on:
91+
# push:
92+
# branches: [ "main" ]
93+
# pull_request:
94+
# branches: [ "main" ]
95+
#
96+
# permissions:
97+
# contents: read
98+
#
99+
# jobs:
100+
# build:
101+
# runs-on: macos-latest
102+
# strategy:
103+
# matrix:
104+
# r-version: ['4.4.0', '4.3.2']
105+
# fail-fast: false
106+
#
107+
# steps:
108+
# - uses: actions/checkout@v3
109+
#
110+
# - name: Update Homebrew
111+
# run: brew update
112+
#
113+
# - name: Install pandoc
114+
# run: |
115+
# for i in {1..3}
116+
# do
117+
# brew install pandoc && break || sleep 15
118+
# done
119+
#
120+
# - name: Install gfortran and configure Makevars
121+
# run: |
122+
# brew install gcc
123+
# mkdir -p ~/.R
124+
# touch ~/.R/Makevars
125+
# echo "FC=$(brew --prefix)/bin/gfortran" >> ~/.R/Makevars
126+
# echo "F77=$(brew --prefix)/bin/gfortran" >> ~/.R/Makevars
127+
# echo "FLIBS=-L$(brew --prefix)/lib/gcc/current -lgfortran -lquadmath -lm" >> ~/.R/Makevars
128+
# echo "LDFLAGS=-L$(brew --prefix)/lib/gcc/current" >> ~/.R/Makevars
129+
#
130+
# - name: Set up R ${{ matrix.r-version }}
131+
# uses: r-lib/actions/setup-r@v2
132+
# with:
133+
# r-version: ${{ matrix.r-version }}
134+
#
135+
# - name: Install R dependencies
136+
# run: |
137+
# # 基礎包安裝
138+
# Rscript -e 'install.packages(c("remotes", "rcmdcheck", "reticulate", "renv", "knitr", "rmarkdown", "lsa", "purrr", "testthat"), repos="https://cran.r-project.org")'
139+
#
140+
# # 根據 R 版本有條件地安裝 Matrix
141+
# Rscript -e '
142+
# if (getRversion() >= "4.4.0") {
143+
# install.packages("Matrix")
144+
# } else {
145+
# remotes::install_version("Matrix", version = "1.5.1", repos = "https://cran.r-project.org")
146+
# }
147+
# '
148+
#
149+
# # 安裝指定版本的 htmltools
150+
# Rscript -e 'remotes::install_version("htmltools", version = "0.5.8")'
151+
#
152+
# # 最後執行 renv::restore()
153+
# Rscript -e 'renv::restore()'
154+
#
155+
# - name: Set up Python
156+
# uses: actions/setup-python@v2
157+
# with:
158+
# python-version: '3.10.x'
159+
#
160+
# - name: Install Python virtualenv
161+
# run: pip install virtualenv
162+
#
163+
# - name: Create Python virtual environment
164+
# run: virtualenv flair_env
165+
#
166+
# - name: Install Python dependencies in virtual environment
167+
# run: |
168+
# source flair_env/bin/activate
169+
# pip install --upgrade pip
170+
# pip install scipy==1.12.0
171+
# pip install flair
172+
#
173+
# - name: Remove Python cache files
174+
# run: find . -name '*.pyc' -delete
175+
#
176+
# - name: Check (with virtual environment)
177+
# run: |
178+
# source flair_env/bin/activate
179+
# R CMD build --no-build-vignettes .
180+
# shell: bash
181+
182+
88183
name: R-MacOS
89184

90185
on:
@@ -101,7 +196,7 @@ jobs:
101196
runs-on: macos-latest
102197
strategy:
103198
matrix:
104-
r-version: ['4.4.0', '4.3.2']
199+
r-version: ['4.4.0', '4.2.3'] # 改為 4.2.3
105200
fail-fast: false
106201

107202
steps:
@@ -134,28 +229,49 @@ jobs:
134229

135230
- name: Install R dependencies
136231
run: |
137-
# 基礎包安裝
138-
Rscript -e 'install.packages(c("remotes", "rcmdcheck", "reticulate", "renv", "knitr", "rmarkdown", "lsa", "purrr", "testthat"), repos="https://cran.r-project.org")'
232+
# 首先安裝基礎包
233+
Rscript -e 'install.packages(c("remotes", "rcmdcheck", "reticulate", "renv"), repos="https://cran.r-project.org")'
139234
140-
# 根據 R 版本有條件地安裝 Matrix
235+
# 根據 R 版本安裝相應的 Matrix 版本
141236
Rscript -e '
142237
if (getRversion() >= "4.4.0") {
143-
install.packages("Matrix")
238+
remotes::install_version("Matrix", version = "1.5-3")
239+
} else if (getRversion() >= "4.2.0" && getRversion() < "4.3.0") {
240+
remotes::install_version("Matrix", version = "1.4-1")
144241
} else {
145-
remotes::install_version("Matrix", version = "1.5.1", repos = "https://cran.r-project.org")
242+
remotes::install_version("Matrix", version = "1.5-1")
146243
}
147244
'
148245
149-
# 安裝指定版本的 htmltools
246+
# 安裝其他依賴
247+
Rscript -e 'install.packages(c("knitr", "rmarkdown", "lsa", "purrr", "testthat"), repos="https://cran.r-project.org")'
248+
249+
# 安裝特定版本的 htmltools
150250
Rscript -e 'remotes::install_version("htmltools", version = "0.5.8")'
151251
152-
# 最後執行 renv::restore()
153-
Rscript -e 'renv::restore()'
252+
# renv 相關操作
253+
Rscript -e '
254+
tryCatch({
255+
renv::restore()
256+
}, error = function(e) {
257+
message("Error in renv::restore(): ", e$message)
258+
if (!requireNamespace("Matrix", quietly = TRUE)) {
259+
if (getRversion() >= "4.4.0") {
260+
install.packages("Matrix")
261+
} else if (getRversion() >= "4.2.0" && getRversion() < "4.3.0") {
262+
remotes::install_version("Matrix", version = "1.4-1")
263+
} else {
264+
remotes::install_version("Matrix", version = "1.5-1")
265+
}
266+
}
267+
})
268+
'
154269
155270
- name: Set up Python
156-
uses: actions/setup-python@v2
271+
uses: actions/setup-python@v4 # 更新到 v4
157272
with:
158273
python-version: '3.10.x'
274+
cache: 'pip'
159275

160276
- name: Install Python virtualenv
161277
run: pip install virtualenv
@@ -169,12 +285,14 @@ jobs:
169285
pip install --upgrade pip
170286
pip install scipy==1.12.0
171287
pip install flair
288+
deactivate
172289
173290
- name: Remove Python cache files
174291
run: find . -name '*.pyc' -delete
175292

176293
- name: Check (with virtual environment)
177294
run: |
178295
source flair_env/bin/activate
296+
set -e
179297
R CMD build --no-build-vignettes .
180298
shell: bash

0 commit comments

Comments
 (0)