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

Update to workflows for 2024 #29

Merged
merged 11 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 0 additions & 25 deletions .Rprofile
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,4 @@

source("renv/activate.R")

# Tidy code function
tidy_code <- function() {
source("global.r")
tidy_code_function()
}

# Function to run tests
run_tests_locally <- function() {
Sys.unsetenv("http_proxy")
Sys.unsetenv("https_proxy")
source("global.r")
# message("================================================================================")
# message("== testthat ====================================================================")
# message("")
# testthat::test_dir("tests/testthat")
# message("")
message("================================================================================")
message("== shinytest ===================================================================")
message("")
shinytest2::test_app()
message("")
message("================================================================================")
}

# Install commit-hooks locally
statusWriteCommit <- file.copy(".hooks/pre-commit.R", ".git/hooks/pre-commit", overwrite = TRUE)
42 changes: 42 additions & 0 deletions .github/workflows/automated-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on:
push:
branches:
- main

pull_request:

name: Automated tests

jobs:
automatedTests:
runs-on: ubuntu-latest

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

steps:
- uses: actions/checkout@v4

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

- name: Install git2r dependencies
run: sudo apt-get install -y libgit2-dev

- name: Cache renv packages
id: cache-renv
uses: actions/cache@v4
with:
path: cache-renv
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}
restore-keys: |
${{ runner.os }}-renv-

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

- name: Run tests
shell: Rscript {0}
run: |
shinytest2::test_app()

39 changes: 11 additions & 28 deletions .github/workflows/deploy-shiny.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,34 @@ on:
branches:
- main
- development
pull_request:


name: deploy-shiny

jobs:
deployShiny:
runs-on: ${{ matrix.config.os }}

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

strategy:
fail-fast: false
matrix:
config:
# Running on mac as it's quicker to build
- {os: macOS-latest, r: 'release'}
runs-on: ubuntu-latest

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
RENV_PATHS_ROOT: ~/.local/share/renv
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

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

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

- name: Set env vars (dev)
if: endsWith(github.ref, '/development')
run: |
echo "SHINYAPP_NAME='dev-KS4-ready-reckoners'" >> $GITHUB_ENV
echo "SHINYAPP_NAME='dev-ks4-ready-reckoners'" >> $GITHUB_ENV
- name: Set env vars (prod)
if: endsWith(github.ref, '/main')
run: |
echo "SHINYAPP_NAME='KS4-ready-reckoners'">> $GITHUB_ENV
echo "SHINYAPP_NAME='ks4-ready-reckoners'">> $GITHUB_ENV

- name: Cache R packages
if: runner.os != 'Windows'
Expand All @@ -49,14 +40,6 @@ jobs:
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Cache renv packages
uses: actions/cache@v1
with:
path: ${{ env.RENV_PATHS_ROOT }}
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}
restore-keys: |
${{ runner.os }}-renv-

- name: Restore renv snapshot
shell: Rscript {0}
run: |
Expand All @@ -67,15 +50,15 @@ jobs:
shell: Rscript {0}
run: |
if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv")
renv::install("rsconnect@0.8.29")
renv::install("rsconnect")

# Tokens are stored as secrets in GitHub to make sure only DfE analysts can publish apps in our shiny.io area
# Navigate to Settings > Secrets to add and view secrets. These can also be things like admin login and passwords for SQL databases.
# Get in touch with the Stats Development team if you need to add the below secrets to publish to shinyapps.io

- name: Push to shiny.io
if: github.event_name != 'pull_request'
run: >
Rscript
-e "rsconnect::setAccountInfo(name = 'department-for-education', token = '${{secrets.SHINYAPPS_TOKEN}}', secret = '${{secrets.SHINYAPPS_SECRET}}')"
-e "rsconnect::deployApp(appName=${{env.SHINYAPP_NAME}})"

-e "rsconnect::deployApp(appName=${{env.SHINYAPP_NAME}}, forceUpdate = TRUE)"
59 changes: 59 additions & 0 deletions .github/workflows/lintr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '20 3 * * 0'

name: lintr

permissions:
contents: read

jobs:
lintr:
runs-on: ${{ matrix.config.os }}

name: Run lintr scanning

strategy:
fail-fast: false
matrix:
config:
# Running on mac as it's quicker to build
- {os: macOS-latest, r: 'release'}

permissions:
contents: read # for checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup R
uses: r-lib/actions/setup-r@4e1feaf90520ec1215d1882fdddfe3411c08e492
with:
r-version: 4.2.1
use-public-rspm: true

- name: restore renv
uses: r-lib/actions/setup-renv@v2

- name: Install lintr
shell: Rscript {0}
run: |
renv::install("lintr")

- name: Run lintr
run: lintr::sarif_output(lintr::lint_dir("."), "lintr-results.sarif")
shell: Rscript {0}
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: lintr-results.sarif
wait-for-processing: true
64 changes: 0 additions & 64 deletions .github/workflows/shiny-tests.yaml

This file was deleted.

39 changes: 7 additions & 32 deletions .github/workflows/tidyCode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,22 @@ name: tidyCode

jobs:
tidyCode:
runs-on: ${{ matrix.config.os }}

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

strategy:
fail-fast: false
matrix:
config:
# Running on mac as it's quicker to build
- {os: macOS-latest, r: 'release'}
runs-on: ubuntu-latest

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
RENV_PATHS_ROOT: ~/.local/share/renv
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

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

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

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
- name: Install git2r dependencies
run: sudo apt-get install -y libgit2-dev

- name: Cache renv packages
uses: actions/cache@v1
with:
path: ${{ env.RENV_PATHS_ROOT }}
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}
restore-keys: |
${{ runner.os }}-renv-

- name: Restore renv snapshot
shell: Rscript {0}
run: |
Expand All @@ -56,9 +33,7 @@ jobs:
- name: Tidy code
shell: Rscript {0}
run: |
source("global.R")

codeChecks <- tidy_code_function()
codeChecks <- dfeshiny::tidy_code()

if(any(is.na(codeChecks))) {
stop("There is a breaking error in the code.")
Expand Down
2 changes: 1 addition & 1 deletion .hooks/pre-commit.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if (error_flag) {
}


tidy_output <- tidy_code()
tidy_output <- dfeshiny::tidy_code()
if(any(tidy_output)){
error_flag <- TRUE
}
Expand Down
Loading
Loading