Skip to content

Commit 2994ed1

Browse files
authored
Documentation (#12)
* expand README * add vignette
1 parent 88fa804 commit 2994ed1

File tree

14 files changed

+123
-45
lines changed

14 files changed

+123
-45
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
^codemeta\.json$
1212
^\.pre-commit-config\.yaml$
1313
^inst/action$
14+
^doc$
15+
^Meta$

.github/workflows/test-octolog.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
print("I accidentally logged my: secret_gh_token")
5555
octo_echo_off()
5656
57-
readLines("DESCRIPTION") %>%
57+
readLines("README.md") %>%
5858
encode_string(join = TRUE) %>%
5959
octo_set_output("desc")
6060
@@ -85,6 +85,7 @@ jobs:
8585
print(Sys.getenv("MULTI_LINE2"))
8686
octo_inform("We can use outputs from previous steps in other steps using the step id.")
8787
octo_inform("Multiline strings will be automatically converted from their escaped form.")
88-
cat('${{steps.step1.outputs.desc }}')
88+
89+
cat('${{steps.step1.outputs.desc}}')
8990
shell: Rscript {0}
9091

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
docs
2+
inst/doc
3+
/doc/
4+
/Meta/

DESCRIPTION

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
Package: octolog
2-
Title: Better Github Action Logging
2+
Title: Better 'Github Action' Logging
33
Version: 0.0.0.9000
44
Authors@R:
55
person("Jacob", "Wujciak-Jens", , "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0002-7281-3989"))
7-
Description: Provides an API for Github workflow commands and
8-
makes it possible to signal conditions from within R that will create
9-
annotations when used within Github Actions but raise normal R
10-
conditions when used interactively.
7+
Description: Provides an API for 'Github' <https://github.com> workflow
8+
commands and makes it possible to signal conditions from within R that
9+
will create annotations when used within 'Github Actions'
10+
<https://github.com/features/actions> but raise normal R conditions
11+
when used interactively.
1112
License: MIT + file LICENSE
1213
URL: https://github.com/assignUser/octolog,
1314
https://assignuser.github.io/octolog/
@@ -22,13 +23,16 @@ Imports:
2223
utils,
2324
withr
2425
Suggests:
26+
knitr,
2527
covr,
2628
mockery (>= 0.4.2.9000),
27-
testthat (>= 3.0.0)
29+
testthat (>= 3.0.0),
30+
rmarkdown
31+
Remotes:
32+
r-lib/mockery
2833
Config/testthat/edition: 3
2934
Config/testthat/parallel: true
30-
Remotes:
31-
r-lib/mockery
3235
Encoding: UTF-8
3336
Roxygen: list(markdown = TRUE)
3437
RoxygenNote: 7.1.2
38+
VignetteBuilder: knitr

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# octolog 0.0.0.9000
2+
3+
* Added a `NEWS.md` file to track changes to the package.

README.Rmd

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
---
2-
output: github_document
2+
output:
3+
github_document: default
34
---
45

56
<!-- README.md is generated from README.Rmd. Please edit that file -->
67

78
# octolog
89

910
<!-- badges: start -->
11+
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
1012
[![R-CMD-check](https://github.com/assignUser/octolog/workflows/R-CMD-check/badge.svg)](https://github.com/assignUser/octolog/actions)
11-
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
13+
[![pkgcheck](https://github.com/assignUser/octolog/actions/workflows/pkgcheck.yaml/badge.svg)](https://github.com/assignUser/octolog/actions/workflows/pkgcheck.yaml)
1214
[![Codecov test coverage](https://codecov.io/gh/assignUser/octolog/branch/main/graph/badge.svg)](https://app.codecov.io/gh/assignUser/octolog?branch=main)
1315
<!-- badges: end -->
1416

15-
Octolog makes it easy to create conditions that create annotations in Github Action workflows and use the other [workflow commands](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions) that are available.
17+
Octolog provides a complete[^1] API for Github [workflow commands](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions) that makes it easy to create powerful Github Actions that create readable logs.
18+
19+
and makes it possible to signal conditions from within R that will create annotations when used within Github Actions but raise normal R conditions
20+
when used interactively.
21+
![Annotations on files of a PR](man/figures/error.png)
22+
23+
[^1]: The only exception is [`save-state`](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#sending-values-to-the-pre-and-post-actions) which can only be used in JavaScript actions.
1624

1725
## Installation
1826

@@ -23,19 +31,14 @@ pak::pak("assignUser/octolog")
2331
devtools::install_github("assignUser/octolog")
2432
```
2533

26-
## Example
27-
28-
Octolog provides drop-in replacements for `cli::cli_warn` and friends:
34+
## What are *Github Actions*?
35+
[Github Actions](https://github.com/features/actions) is a powerful,free[^2] [CI](https://devguide.ropensci.org/ci.html) service integrated into every repository on Github. You can use actions created by other users (e.g. the very popular [r-lib/actions](https://github.com/r-lib/actions) collection of R related actions) or create your own customized workflow that fits your needs.
2936

30-
```{r example}
31-
library(octolog)
37+
[^2]: For public repositories.
3238

33-
Sys.setenv(GITHUB_ACTIONS = "FALSE")
34-
octo_warn(c("An important warning!", i = "And a tipp how to avoid this warning."))
39+
## Example
3540

36-
Sys.setenv(GITHUB_ACTIONS = "TRUE")
37-
octo_warn(c("An important warning!", i = "And a tipp how to avoid this warning."))
38-
```
41+
The best way to see how {octolog} works, is in an actual [workflow](https://github.com/assignUser/octolog/actions/workflows/test-octolog.yaml). For more information please see the [website](assignUser.github.io/octolog) and the vignette [LINK ME]().
3942

4043
## Code of Conduct
4144

README.md

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@
55

66
<!-- badges: start -->
77

8+
[![Project Status: Active – The project has reached a stable, usable
9+
state and is being actively
10+
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
811
[![R-CMD-check](https://github.com/assignUser/octolog/workflows/R-CMD-check/badge.svg)](https://github.com/assignUser/octolog/actions)
9-
[![Lifecycle:
10-
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
12+
[![pkgcheck](https://github.com/assignUser/octolog/actions/workflows/pkgcheck.yaml/badge.svg)](https://github.com/assignUser/octolog/actions/workflows/pkgcheck.yaml)
1113
[![Codecov test
1214
coverage](https://codecov.io/gh/assignUser/octolog/branch/main/graph/badge.svg)](https://app.codecov.io/gh/assignUser/octolog?branch=main)
1315
<!-- badges: end -->
1416

15-
Octolog makes it easy to create conditions that create annotations in
16-
Github Action workflows and use the other [workflow
17+
Octolog provides a complete[^1] API for Github [workflow
1718
commands](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions)
18-
that are available.
19+
that makes it easy to create powerful Github Actions that create
20+
readable logs.
21+
22+
and makes it possible to signal conditions from within R that will
23+
create annotations when used within Github Actions but raise normal R
24+
conditions when used interactively. ![Annotations on files of a
25+
PR](man/figures/error.png)
1926

2027
## Installation
2128

@@ -27,30 +34,32 @@ pak::pak("assignUser/octolog")
2734
devtools::install_github("assignUser/octolog")
2835
```
2936

30-
## Example
31-
32-
Octolog provides drop-in replacements for `cli::cli_warn` and friends:
33-
34-
``` r
35-
library(octolog)
36-
37-
Sys.setenv(GITHUB_ACTIONS = "FALSE")
38-
octo_warn(c("An important warning!", i = "And a tipp how to avoid this warning."))
39-
```
37+
## What are *Github Actions*?
4038

41-
## Warning: An important warning!
42-
## ℹ And a tipp how to avoid this warning.
39+
[Github Actions](https://github.com/features/actions) is a
40+
powerful,free[^2] [CI](https://devguide.ropensci.org/ci.html) service
41+
integrated into every repository on Github. You can use actions created
42+
by other users (e.g. the very popular
43+
[r-lib/actions](https://github.com/r-lib/actions) collection of R
44+
related actions) or create your own customized workflow that fits your
45+
needs.
4346

44-
``` r
45-
Sys.setenv(GITHUB_ACTIONS = "TRUE")
46-
octo_warn(c("An important warning!", i = "And a tipp how to avoid this warning."))
47-
```
47+
## Example
4848

49-
## ::warning ::An important warning!%0Aℹ And a tipp how to avoid this warning.
49+
The best way to see how {octolog} works, is in an actual
50+
[workflow](https://github.com/assignUser/octolog/actions/workflows/test-octolog.yaml).
51+
For more information please see the
52+
[website](assignUser.github.io/octolog) and the vignette [LINK ME]().
5053

5154
## Code of Conduct
5255

5356
Please note that the octolog project is released with a [Contributor
5457
Code of
5558
Conduct](https://assignuser.github.io/octolog/CODE_OF_CONDUCT.html). By
5659
contributing to this project, you agree to abide by its terms.
60+
61+
[^1]: The only exception is
62+
[`save-state`](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#sending-values-to-the-pre-and-post-actions)
63+
which can only be used in JavaScript actions.
64+
65+
[^2]: For public repositories.

man/figures/README-pressure-1.png

-7.13 KB
Binary file not shown.

man/figures/annotations.png

80.7 KB
Loading

man/figures/error.png

24.8 KB
Loading

man/figures/masking.png

17.3 KB
Loading

man/figures/summary.png

14.2 KB
Loading

vignettes/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.html
2+
*.R

vignettes/octolog.Rmd

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: "Introduction to octolog"
3+
output: rmarkdown::html_vignette
4+
vignette: >
5+
%\VignetteIndexEntry{Introduction to octolog}
6+
%\VignetteEngine{knitr::rmarkdown}
7+
%\VignetteEncoding{UTF-8}
8+
---
9+
10+
Getting started with octolog is easy, just replace the *{cli}* conditions functions with their octolog counterpart:
11+
12+
* `cli::cli_inform` $\rightarrow$ `octolog::octo_inform`
13+
* `cli::cli_warn` $\rightarrow$ `octolog::octo_warn`
14+
* `cli::cli_abort` $\rightarrow$ `octolog::octo_abort`
15+
16+
In an interactive session you will not see a difference, as the calls are passed through to {cli} but if your code throws conditions within a Github Action (detected via the environment variable `GITHUB_ACTIONS = "true"`) the behaviour will change. The conditions will be signaled in a way that will make them stand out in the log, appear in the action summary and create annotations[^1] on affected files.
17+
18+
![Annotations on files of a PR.](../man/figures/annotations.png)
19+
20+
You can throw *errors* that do not kill the R session when using `octo_abort()` by setting the optional argument `.fail_fast = FALSE`. This can be useful if you want a workflow to fail (e.g. to block a PR) by throwing an error but do not want to stop the R process.
21+
22+
![Annotations in the workflow summary. ](../man/figures/summary.png)
23+
24+
[^1]: Annotations only work on pull requests.
25+
26+
## Workflow commands
27+
28+
In addition to signaling conditions, Github Actions provide a number of [workflow commands](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions) to interact with the runner and following actions steps. Octolog provides a complete API[^2] for the workflow commands, please see the [function reference](https://jacob.wujciak.de/octolog/reference/index.html) and the official documentation for an overview. To see the workflow commands in practice you can check out the [example workflow](https://github.com/assignUser/octolog/actions/workflows/test-octolog.yaml) or the real world use case of the [pkgcheck action](https://github.com/ropensci-review-tools/pkgcheck-action).
29+
30+
[^2]: The only exception is [`save-state`](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#sending-values-to-the-pre-and-post-actions) which can only be used in JavaScript actions.
31+
32+
## Security
33+
34+
**In doubt always refer to the [official documentation](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions) and [security hardening guide](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions) and test the behaviour to make sure the functions behave as you expect!**
35+
36+
There are commands that can have an impact on the security of your repository if they are not or wrongly used. As their official documentation is a bit lacking in parts this section will add some additional remarks.
37+
38+
### Masking
39+
40+
Masking values directly (`octo_mask_value`) and masking environment variables and their values (`octo_mask_envvar`) differs in unexpected and undocumented ways.
41+
42+
![Difference in masking values and environment variables. ](../man/figures/masking.png)
43+
44+
Values masked with `octo_mask_value` will be replaced with "\*\*\*"" immediately but environment variables will only be masked in the ***next*** `step:` of the action!
45+
46+
### Stopping command parsing
47+
48+
If you have to log untrusted user input (like commit messages, issue titles ...) you can prevent the execution of workflow commands using `octo_stop_commands`.Internally the function creates a token based on cryptographically secure random bytes from {openssl}, this makes it impossible for a third party to guess the token before submitting their changes (e.g. to a PR) to enable the execution of their untrusted commands. This is not intended to protect against other R code. Due to R's metaprogramming capabilities it is not possible to protect the token within the same R session.
49+
50+
***NEVER*** run untrusted code using an action trigger that gives write access to your repository like "pull_request_target". See this article about [*pwn requests*](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) for more in-depth information.
51+

0 commit comments

Comments
 (0)