Skip to content

Commit

Permalink
better gh actions
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Feb 14, 2024
1 parent cd75b35 commit 5baad79
Show file tree
Hide file tree
Showing 34 changed files with 1,143 additions and 1,003 deletions.
43 changes: 41 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
#
# NOTE: This workflow is overkill for most R packages and
# check-standard.yaml is likely a better choice.
# usethis::use_github_action("check-standard") will install it.
on:
push:
branches: [main, master]
Expand All @@ -12,20 +16,33 @@ jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})
name: ${{ matrix.config.os }} (${{ matrix.config.r }}) ${{ matrix.config.custom }}

strategy:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}

# Use older ubuntu to maximise backward compatibility
- {os: ubuntu-20.04, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-20.04, r: 'release'}
- {os: ubuntu-20.04, r: 'release', custom: 'gcc 4.8'}
- {os: ubuntu-20.04, r: 'oldrel-1'}
- {os: ubuntu-20.04, r: 'oldrel-2'}
- {os: ubuntu-20.04, r: 'oldrel-3'}
- {os: ubuntu-20.04, r: 'oldrel-4'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -35,6 +52,28 @@ jobs:
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- name : Install compiler version
# We check on this old compiler specifically to support CentOS 7,
# which uses this gcc version. RStudio products support CentOS 7 through
# June 2024.
# https://github.com/r-lib/cpp11/pull/78
# https://www.rstudio.com/about/platform-support/
# Ubuntu 20.04 technically dropped support for gcc 4.8, so we have to
# add old archives back in manually to install it
# https://github.com/r-lib/cpp11/pull/279
if: matrix.config.custom == 'gcc 4.8'
run: |
echo "deb http://dk.archive.ubuntu.com/ubuntu/ xenial main" | sudo tee -a /etc/apt/sources.list
echo "deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe" | sudo tee -a /etc/apt/sources.list
sudo apt update
sudo apt-get install -y g++-4.8 libgfortran-*
mkdir ~/.R/
echo $'CXX1X=g++-4.8\nCXX11=g++-4.8\nCC=gcc-4.8 -std=c99\nCXX=g++-4.8 -std=gnu++11' >> ~/.R/Makevars
- name: Install macOS system dependencies
if: runner.os == 'macOS'
run: brew install --cask xquartz

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
branches: main
pull_request:
branches:
- main

name: format_check

jobs:
format_check:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2

- name: Install ClangFormat
run: sudo apt-get install -y clang-format-14

- name: Run ClangFormat
run: make format clang_format=clang-format-14

- name: Check for a non-empty diff
run: git diff-files -U --exit-code
79 changes: 79 additions & 0 deletions .github/workflows/pr-commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
issue_comment:
types: [created]

name: Commands

jobs:
document:
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }}
name: document
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::roxygen2
needs: pr-document

- name: Document
run: roxygen2::roxygenise()
shell: Rscript {0}

- name: commit
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com"
git add man/\* NAMESPACE
git commit -m 'Document'
- uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

style:
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }}
name: style
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: r-lib/actions/setup-r@v2

- name: Install dependencies
run: install.packages("styler")
shell: Rscript {0}

- name: Style
run: styler::style_pkg()
shell: Rscript {0}

- name: commit
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com"
git add \*.R
git commit -m 'Style'
- uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
39 changes: 39 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-22.04
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Install cpp11armadillotest
run: |
options(warn = 2)
pak::pkg_install("pachadotdev/cpp11armadillo", dependencies = TRUE)
pak::local_install_dev_deps("cpp11armadillotest", dependencies = TRUE)
install.packages("cpp11armadillotest", repos = NULL, INSTALL_opts = "--install-tests", type = "source")
shell: Rscript {0}

- name: Test coverage
run: covr::codecov(quiet = FALSE)
shell: Rscript {0}
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
test:
@Rscript -e 'devtools::clean_dll(); devtools::test(".")'

clean:
@Rscript -e 'devtools::clean_dll()'

document:
@Rscript -e 'devtools::document()'

site:
@Rscript -e 'pkgdown::build_site()'

install:
@Rscript -e 'devtools::install()'

clang_format=`which clang-format-14`

format: $(shell find . -name '*.h') $(shell find . -name '*.hpp') $(shell find . -name '*.cpp')
@${clang_format} -i $?
30 changes: 15 additions & 15 deletions dev/04_pairwise_correlation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Bubble sort distance between the input array and the sorted array

uint64_t insert_sort_(double* arr, size_t len) {
uint64_t insert_sort_(double *arr, size_t len) {
size_t max_j, i;
uint64_t swap_count = 0;

Expand All @@ -37,11 +37,11 @@ uint64_t insert_sort_(double* arr, size_t len) {
return swap_count;
}

static uint64_t merge_(double* from, double* to, size_t middle, size_t len) {
static uint64_t merge_(double *from, double *to, size_t middle, size_t len) {
size_t buf_index, left_len, right_len;
uint64_t swaps;
double* left;
double* right;
double *left;
double *right;

buf_index = 0;
swaps = 0;
Expand Down Expand Up @@ -74,7 +74,7 @@ static uint64_t merge_(double* from, double* to, size_t middle, size_t len) {
return swaps;
}

uint64_t merge_sort_(double* x, double* buf, size_t len) {
uint64_t merge_sort_(double *x, double *buf, size_t len) {
uint64_t swaps;
size_t half;

Expand All @@ -99,7 +99,7 @@ uint64_t merge_sort_(double* x, double* buf, size_t len) {

// Count ties

static uint64_t count_ties_(double* data,
static uint64_t count_ties_(double *data,
size_t len) { /* Assumes data is sorted.*/
uint64_t sum_counts = 0, tie_count = 0;
size_t i;
Expand Down Expand Up @@ -130,7 +130,7 @@ static uint64_t count_ties_(double* data,
// arr1 <- arr1[perm]
// arr2 <- arr2[perm]

double kendall_n_log_n_(const double* arr1, const double* arr2, size_t len) {
double kendall_n_log_n_(const double *arr1, const double *arr2, size_t len) {
uint64_t m1 = 0, m2 = 0, tie_count, swap_count, n_pair;
int64_t s;
size_t i;
Expand All @@ -143,7 +143,7 @@ double kendall_n_log_n_(const double* arr1, const double* arr2, size_t len) {
if (arr1[i - 1] == arr1[i]) {
tie_count++;
} else if (tie_count > 0) {
double* arr2_copy = new double[tie_count + 1];
double *arr2_copy = new double[tie_count + 1];
copy(arr2 + i - tie_count - 1, arr2 + i, arr2_copy);
insert_sort_(arr2_copy, tie_count + 1);
m1 += tie_count * (tie_count + 1) / 2;
Expand All @@ -154,7 +154,7 @@ double kendall_n_log_n_(const double* arr1, const double* arr2, size_t len) {
}
}
if (tie_count > 0) {
double* arr2_copy = new double[tie_count + 1];
double *arr2_copy = new double[tie_count + 1];
copy(arr2 + i - tie_count - 1, arr2 + i, arr2_copy);
insert_sort_(arr2_copy, tie_count + 1);
m1 += tie_count * (tie_count + 1) / 2;
Expand All @@ -163,9 +163,9 @@ double kendall_n_log_n_(const double* arr1, const double* arr2, size_t len) {
tie_count++;
}

double* arr2_sorted = new double[len];
double *arr2_sorted = new double[len];
copy(arr2, arr2 + len, arr2_sorted);
swap_count = merge_sort_(arr2_sorted, const_cast<double*>(arr1), len);
swap_count = merge_sort_(arr2_sorted, const_cast<double *>(arr1), len);

m2 = count_ties_(arr2_sorted, len);
s -= (m1 + m2) + 2 * swap_count;
Expand All @@ -181,17 +181,17 @@ double kendall_n_log_n_(const double* arr1, const double* arr2, size_t len) {

// Wrapper to R

[[cpp11::register]] double pairwise_cor_(const doubles& y,
const doubles& yhat) {
[[cpp11::register]] double pairwise_cor_(const doubles &y,
const doubles &yhat) {
size_t len_y = y.size();
size_t len_yhat = yhat.size();

if (len_y != len_yhat) {
stop("y and yhat must be the same length");
}

const double* y_data = REAL(y);
const double* yhat_data = REAL(yhat);
const double *y_data = REAL(y);
const double *yhat_data = REAL(yhat);

double cor = kendall_n_log_n_(y_data, yhat_data, len_y);

Expand Down
Loading

0 comments on commit 5baad79

Please sign in to comment.