Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup workflows #2

Merged
merged 63 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
3918b32
Update
walkowif May 15, 2024
7603c7d
Update
walkowif May 15, 2024
01c7ddd
Update
walkowif May 15, 2024
5a55bbc
Update
walkowif May 15, 2024
caf7a35
Update
walkowif May 15, 2024
357b297
Update
walkowif May 15, 2024
9a75fae
Update
walkowif May 15, 2024
2afaa9e
Update
walkowif May 15, 2024
7cf90b6
Update
walkowif May 15, 2024
4f97b7c
Update
walkowif May 15, 2024
0130477
Update
walkowif May 15, 2024
d98567b
Update
walkowif May 15, 2024
b93d996
Update
walkowif May 15, 2024
d13fb24
Update
walkowif May 15, 2024
bb03840
Update
walkowif May 15, 2024
e697b68
Update
walkowif May 15, 2024
93d8cec
Update
walkowif May 21, 2024
fdcf33b
Update
walkowif May 21, 2024
07f0815
Update
walkowif May 21, 2024
9e6a0d4
Update
walkowif May 21, 2024
e733666
Update
walkowif May 21, 2024
fbb5757
Update
walkowif May 21, 2024
a2dd35f
Update
walkowif May 21, 2024
09e5dd4
Update
walkowif May 21, 2024
cae6d43
Empty
walkowif May 21, 2024
45817d2
Update
walkowif May 21, 2024
47b6b1f
Update
walkowif May 21, 2024
aa670c9
Empty
walkowif May 21, 2024
7065f54
Empty
walkowif May 21, 2024
4d83660
Update
walkowif May 21, 2024
763b2c9
Update
walkowif May 22, 2024
36f89c4
Update
walkowif May 22, 2024
04fc181
Update
walkowif May 22, 2024
fc85dac
Update
walkowif May 23, 2024
91f2c05
Update
walkowif May 23, 2024
3beb5f9
Update
walkowif May 23, 2024
a1d982d
Update
walkowif May 23, 2024
05c077b
Update
walkowif May 23, 2024
c80254c
Update
walkowif May 23, 2024
b1f73cf
Update
walkowif May 23, 2024
116e274
Update
walkowif May 23, 2024
9d59f46
Update
walkowif May 23, 2024
36acdad
Update
walkowif May 23, 2024
862e70a
Update
walkowif May 23, 2024
1b0915f
Update
walkowif May 23, 2024
1fe72e6
Empty test
May 24, 2024
cd801db
Add instructions to README
walkowif May 24, 2024
aba8540
Merge branch 'setup-workflows' of github.com:user-workshop-cicd/r.pac…
walkowif May 24, 2024
41b2a28
Empty
May 27, 2024
f801af4
Add git installation instructions for Windows
walkowif May 27, 2024
c59f497
Empty
May 27, 2024
4db5cf9
Update readme
walkowif May 27, 2024
59eb530
Remove local configuration instructions
walkowif Jun 11, 2024
cf99c3a
Test step output
walkowif Jun 11, 2024
cf53ed2
Update
walkowif Jun 11, 2024
42dfd58
Update simple.yaml
walkowif Jun 11, 2024
94032ce
Update .github/workflows/simple.yaml
walkowif Jun 11, 2024
6ef0ce3
Comment steps
walkowif Jun 11, 2024
5518e08
Remove any::rcmdcheck
walkowif Jun 11, 2024
3381cc1
Uncomment steps
walkowif Jun 11, 2024
8b71f3f
Fix yaml
walkowif Jun 11, 2024
6c536d1
Print all R variables
walkowif Jun 11, 2024
0cec831
Update .github/workflows/simple.yaml
walkowif Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
^r\.package\.example\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^.github$
36 changes: 36 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Check 🛠

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- main
push:
branches:
- main

# This reusable workflow from insightsengineering/r.pkg.template will run once a PR to main branch is created.
jobs:
pawelru marked this conversation as resolved.
Show resolved Hide resolved
job-setup:
name: Should we run R CMD check?
runs-on: ubuntu-latest
outputs:
check_out: ${{ steps.check.outputs.run_r_cmd_check }}
steps:
- name: To check or not to check?
id: check
run: |
echo "run_r_cmd_check=false" >> $GITHUB_OUTPUT

r-cmd:
name: R CMD Check 🧬
needs: job-setup
# Call a workflow from a given GitHub repository, from a given branch (or tag).
uses: insightsengineering/r.pkg.template/.github/workflows/build-check-install.yaml@main
if: >
needs.job-setup.outputs.check_out == 'true'
pawelru marked this conversation as resolved.
Show resolved Hide resolved
138 changes: 138 additions & 0 deletions .github/workflows/simple.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
name: Simple workflow

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- main
push:
branches:
- main

# For reference, this is how the final list of steps will look like:
# env:
# ENABLED_STEPS: |
# checkout_repository
# setup_r
# setup_dependencies
# get_package_name
# build_r_package
# run_r_cmd_check
# upload_artifact

# When asked to, please add the steps from the list above:
env:
ENABLED_STEPS: |
checkout_...
walkowif marked this conversation as resolved.
Show resolved Hide resolved
setup_...
setup_...
get_package_...
build_r_...
run_r_...
upload_...

jobs:
# First job.
hello-world-from-r:
name: Hello, world!
runs-on: ubuntu-latest
steps:
- name: Setup R 🔧
uses: r-lib/actions/setup-r@v2

- name: Hello world! 💬
run: cat(paste0("Hello ", Sys.getenv("NAME"), "! 👋"))
shell: Rscript {0}
env:
NAME: "Your name"

# Second job - by default jobs will run in parallel, unless some dependencies
# are introduced between them.
build-and-check:
name: Build R package
runs-on: ubuntu-latest
steps:
- name: Checkout repo 🛎
# We're using an official GitHub Action.
uses: actions/[email protected]
if: contains(env.ENABLED_STEPS, 'checkout_repository')
with:
# Action inputs (arguments/parameters).
# In this case we clone the repository to the directory called the same
# as the repository name.
path: ${{ github.event.repository.name }}

- name: Setup R 🔧
if: contains(env.ENABLED_STEPS, 'setup_r')
# We're using a third-party GitHub Action.
uses: r-lib/actions/setup-r@v2

- name: Setup R dependencies 🔧
# We're using a third-party GitHub Action.
uses: r-lib/actions/setup-r-dependencies@v2
if: contains(env.ENABLED_STEPS, 'setup_dependencies')
with:
extra-packages: any::rcmdcheck
pawelru marked this conversation as resolved.
Show resolved Hide resolved
working-directory: ${{ github.event.repository.name }}

# Get package name and version from DESCRIPTION so that we'll know
# what's the name of the tar.gz file with the built package.
# PKGBUILD environment variable is saved as an environment variable so this
# information can be accessed by subsequent steps.
walkowif marked this conversation as resolved.
Show resolved Hide resolved
- name: Get package name 📦
if: contains(env.ENABLED_STEPS, 'get_package_name')
run: |
PKGBUILD="$(Rscript -e 'cat(sprintf("%s_%s.tar.gz",(dcf <- read.dcf("DESCRIPTION"))[,"Package"], dcf[,"Version"]))')"
echo "PKGBUILD = $PKGBUILD"
echo "PKGBUILD=$PKGBUILD" >> $GITHUB_ENV
shell: bash
working-directory: ${{ github.event.repository.name }}

# Build a package stored in a directory called ${{ github.event.repository.name }}
# --no-manual --no-build-vignettes because this requires LaTeX.
- name: Build R package 🏗
if: contains(env.ENABLED_STEPS, 'build_r_package')
run: |
R CMD build --no-manual --no-build-vignettes ${{ github.event.repository.name }}
ls -l
shell: bash

# Check tar.gz package built in previous step.
# --no-manual --no-vignettes because this requires LaTeX.
- name: Run R CMD check 🏁
if: contains(env.ENABLED_STEPS, 'run_r_cmd_check')
run: |
R CMD check --no-manual --no-vignettes ${{ env.PKGBUILD }}
shell: bash
env:
_R_CHECK_TESTS_NLINES_: 0
_R_CHECK_VIGNETTES_NLINES_: 0
walkowif marked this conversation as resolved.
Show resolved Hide resolved

- name: Get tar.gz file name
if: contains(env.ENABLED_STEPS, 'upload_artifact')
pawelru marked this conversation as resolved.
Show resolved Hide resolved
id: tar-gz
# Use our custom action.
uses: user-workshop-cicd/action-example@setup-action
with:
filename-beginning: ${{ github.event.repository.name }}

# Upload tar.gz package as an artifact so it can be downloaded.
- name: Upload package build ⤴
if: contains(env.ENABLED_STEPS, 'upload_artifact')
uses: actions/upload-artifact@v4
with:
# Output of the custom action from the previous step
# are inputs of this action.
path: ${{ steps.tar-gz.outputs.full-filename }}
name: ${{ steps.tar-gz.outputs.full-filename }}
pawelru marked this conversation as resolved.
Show resolved Hide resolved

call-reusable-workflow:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if this one is necessary since we are also doing reusable workflow in check.yaml (with insightsengineering/r.pkg.template/.github/workflows/build-check-install.yaml)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking that build-check-install might be too overwhelming/complicated, that's why I thought about a trivial workflow which would still illustrate the idea of reusability and passing/using the inputs.

name: Reusable workflow ♻️
uses: user-workshop-cicd/r.pkg.template/.github/workflows/sample-reusable-workflow.yaml@sample-reusable-workflow
with:
name: Octocat
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,77 @@
# r.package.example

An example package for the workshop.

## Prepare your local environment for the workshop excercises

### Install `git` and SSH client

#### Windows
On Windows you can install `git` together with SSH client from https://git-scm.com/download/win.

Below you can find suggested installation customizations, but feel free to customize according to your preferences.

1. Select Components → you can unselect `Windows Explorer integration` and `Scalar (Git add-on to manage large-scale repositories)`.
1. Choosing the default editor used by Git → `Use the Nano editor by default`.
1. Adjusting the name of the initial branch in new repositories → `Override the default branch name for new repositories` with `main`.
1. Adjusting your PATH environment → `Use Git from Git Bash only`.
1. Use bundled OpenSSH (default).
1. Use the OpenSSL library (default).
1. Configure the line ending conversions → `Checkout as-is, commit as-is`.
1. Use MinTTY (default).
1. Fast-forward or merge (default).
1. Git Credential Manager (default).
1. Enable file system caching (default).
1. No experimental options.

#### Ubuntu or Docker container
On Ubuntu, you can install them like this. If you know how to use Docker, you can run these commands in `ubuntu` image.
```bash
apt-get update && apt-get install -yq openssh-client git
```

### Setup write access to GitHub

Create an SSH key pair.
```bash
ssh-keygen -P '' -t rsa -b 4096 -C "$(whoami)@$(hostname)" -f ~/.ssh/$(whoami)-github
eval $(ssh-agent) && ssh-add ~/.ssh/$(whoami)-github
cat ~/.ssh/$(whoami)-github.pub
```

The result will look like this:
```
ssh-rsa AAAA...
```

Copy this and paste to https://github.com/settings/ssh/new.

Add any title, and leave key type equal to authentication key.

### Clone the sample repository

Clone the `r.package.example` repository. Replace `<url>` with an URL similar to this one: `[email protected]:user-workshop-cicd/r.package.example.git`, but `user-workshop-cicd` should be replaced with your GitHub username.

```bash
mkdir user-workshop
cd user-workshop
git clone <url>
cd r.package.example
git status
```

The output should look like:
```
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
```

Configure your name and email address - this will be required to push commits.

You may consider using obfuscated e-mail address like `<github-username>@example.com`, and `<github-username>` as `Your Name`.
```
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
```
2 changes: 1 addition & 1 deletion tests/testthat/test-hello.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ test_that("hello_cli() works", {

test_that("fix me!!!", {
expect_equal(1, 2)
})
})