Skip to content

Commit 94ca8e8

Browse files
committed
Adding tests and refactor pkgdown action
1 parent 534f91b commit 94ca8e8

File tree

3 files changed

+120
-12
lines changed

3 files changed

+120
-12
lines changed

.github/workflows/pkgdown.yaml

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,27 @@ on:
1111

1212
name: pkgdown
1313

14+
# Sets permissions of the GITHUB_TOKEN
15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
pull-requests: write
20+
actions: read
21+
22+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
23+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
24+
concurrency:
25+
group: "pages"
26+
cancel-in-progress: false
27+
1428
jobs:
15-
pkgdown:
29+
build:
1630
runs-on: ubuntu-latest
17-
# Only restrict concurrency for non-PR jobs
18-
concurrency:
19-
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
2031
env:
2132
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
2233
steps:
23-
- uses: actions/checkout@v4
34+
- uses: actions/checkout@v6
2435

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

@@ -39,10 +50,39 @@ jobs:
3950
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
4051
shell: Rscript {0}
4152

42-
- name: Deploy to GitHub pages 🚀
43-
if: github.event_name != 'pull_request'
44-
uses: JamesIves/github-pages-deploy-action@v4.4.1
53+
# Upload artifact for GitHub Pages deployment (only for pushes to main/master)
54+
- name: Upload Pages artifact
55+
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
56+
uses: actions/upload-pages-artifact@v3
4557
with:
46-
clean: false
47-
branch: gh-pages
48-
folder: docs
58+
path: docs
59+
60+
# Upload artifact for PR preview (only for pull requests)
61+
- name: Upload PR artifact
62+
if: github.event_name == 'pull_request'
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: pkgdown-site
66+
path: docs
67+
68+
# Post comment with link to artifact on PRs
69+
- name: Post artifact link to PR
70+
if: github.event_name == 'pull_request'
71+
uses: CDCgov/cfa-actions/post-artifact@v1.2.0
72+
with:
73+
artifact-name: pkgdown-site
74+
gh-token: ${{ secrets.GITHUB_TOKEN }}
75+
message: 'Thank you for your contribution @${{ github.actor }} :rocket:! The pkgdown site preview is ready for review :point_right: [Download here]({ artifact-url }) :point_left:!'
76+
77+
# Deployment job - only runs on pushes to main/master
78+
deploy:
79+
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
80+
environment:
81+
name: github-pages
82+
url: ${{ steps.deployment.outputs.page_url }}
83+
runs-on: ubuntu-latest
84+
needs: build
85+
steps:
86+
- name: Deploy to GitHub Pages
87+
id: deployment
88+
uses: actions/deploy-pages@v4

inst/tinytest/test_defm.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ init_defm(mymodel)
1212

1313
ans <- defm_mle(mymodel)
1414

15+
# Checking texreg fancy
16+
expect_stdout({
17+
print(texreg_fancy(
18+
ans, texreg::screenreg,
19+
skip_intercept = TRUE
20+
))
21+
}, "Model 1")
22+
23+
expect_stdout({
24+
print(summary_table(ans))
25+
},
26+
"pvalues"
27+
)
28+
1529
# Fitting individual models for each outcome
1630
ans_alcohol <- glm(
1731
alcohol ~ Hispanic, data = valentesns,

inst/tinytest/test_sim_defm.R

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ id <- cbind(rep(1L:n_id, each = n_T))
88
Y <- matrix(0L, nrow = n_T * n_id, ncol = n_Y)
99
X <- matrix(rnorm(n_K * n_T * n_id), ncol = n_K)
1010

11+
# ------------------------------------------------------------------------------
12+
# new_defm
13+
# ------------------------------------------------------------------------------
14+
1115
expect_error({
1216
d_model_formula <- new_defm(id = id, Y = Y, X = X, order = 1)
1317
})
@@ -40,6 +44,10 @@ td_logit_intercept(
4044

4145
init_defm(d_model_formula)
4246

47+
# ------------------------------------------------------------------------------
48+
# Stats
49+
# ------------------------------------------------------------------------------
50+
4351
expect_silent({
4452
Y_stats <- get_stats(d_model_formula)
4553
})
@@ -57,4 +65,50 @@ expect_stdout(
5765
)
5866

5967
expect_equal(get_Y_names(d_model_formula), colnames(Y_sim))
60-
expect_equal(get_X_names(d_model_formula), colnames(X))
68+
expect_equal(get_X_names(d_model_formula), colnames(X))
69+
70+
# ------------------------------------------------------------------------------
71+
# Motif census
72+
# ------------------------------------------------------------------------------
73+
expect_stdout({
74+
print(motif_census(d_model_formula, c(0,1)))
75+
}, "census for variable")
76+
77+
78+
# ------------------------------------------------------------------------------
79+
# Log odds
80+
# ------------------------------------------------------------------------------
81+
expect_silent({
82+
lo <- logodds(d_model_formula, c(-1, -.5, .5, 1), i=1, j=1)
83+
})
84+
85+
86+
# ------------------------------------------------------------------------------
87+
# Counters
88+
# ------------------------------------------------------------------------------
89+
expect_stdout({
90+
print(get_counters(d_model_formula))
91+
}, "Counters \\(4\\)")
92+
93+
expect_stdout({
94+
print(get_counters(d_model_formula)[1])
95+
}, "Counter[:]")
96+
97+
98+
set_counter_info(
99+
counter = get_counters(d_model_formula)[1],
100+
new_name = "lame", new_desc = "whatever"
101+
)
102+
103+
tmp <- get_counters(d_model_formula)[1] |>
104+
as.list()
105+
106+
expect_equal(
107+
list(name = "lame", description = "whatever"),
108+
tmp[[1]]
109+
)
110+
111+
# ------------------------------------------------------------------------------
112+
# Misc
113+
# ------------------------------------------------------------------------------
114+
expect_inherits(as.list(get_counters(d_model_formula)), "list")

0 commit comments

Comments
 (0)