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

Updating workflow scripts #1

Merged
merged 11 commits into from
Dec 13, 2024
39 changes: 7 additions & 32 deletions .github/workflows/deploy-shiny.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,23 @@ on:
branches:
- main
- development
pull_request:

name: deploy-shiny
name: shinyapps.io deploy

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
r-version: 4.4.1
use-public-rspm: true

- name: Set env vars (dev)
Expand All @@ -41,22 +31,6 @@ jobs:
run: |
echo "SHINYAPP_NAME='ks5-ready-reckoner'">> $GITHUB_ENV

- 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: 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 @@ -74,6 +48,7 @@ jobs:
# 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}}')"
Expand Down
34 changes: 4 additions & 30 deletions .github/workflows/shiny-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,25 @@ on:
push:
branches:
- main
- development
pull_request:

name: shiny-tests

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

name: shiny-tests

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:
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: 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,26 @@ on:
push:
branches:
- main
- development
pull_request:

name: tidyCode
name: tidy-code

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

name: tidyCode

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: 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 Down
25 changes: 12 additions & 13 deletions .hooks/pre-commit.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env Rscript
cat("Running commit hooks...",fill=TRUE)
cat("Running commit hooks...", fill = TRUE)
shhh <- suppressPackageStartupMessages # It's a library, so shhh!
shhh(library(dplyr))
shhh(library(xfun))
Expand All @@ -16,12 +16,12 @@ cat("Contents of the .gitignore file:")
print(ign_files)

# Run a pass through the .gitignore files and look for any issues
if(ncol(ign_files)>1){
if (ncol(ign_files) > 1) {
cat("ERROR: It looks like you've got commas in the .gitignore. Please correct the .gitignore file and try again.")
error_flag <- TRUE
} else {
for(i in 1:nrow(ign_files)){
if(grepl(' ',ign_files$filename[i])){
for (i in 1:nrow(ign_files)) {
if (grepl(" ", ign_files$filename[i])) {
cat("ERROR: It looks like you've got spaces in filenames in the .gitignore. Please rename your files if they contain spaces and update the .gitignore file accordingly.")
error_flag <- TRUE
}
Expand All @@ -41,25 +41,24 @@ for (file in current_files$files) {
} else {
file_status <- (log_files %>% filter(filename == file))$status
if (!file_status %in% c("published", "Published", "reference", "Reference", "dummy", "Dummy")) {
if (!file %in% ign_files$filename & !grepl("unpublished",file)) {
if (!file %in% ign_files$filename & !grepl("unpublished", file)) {
cat("Error:", file, "is not logged as published or reference data in datafiles_log.csv and is not found in .gitignore.\n\n")
cat("If the file contains published or reference data then update its entry in datafiles_log.csv.\n\n")
cat("If the file contains unpublished data then add it to the .gitignore file.\n\n")
error_flag <- TRUE
}
else {
cat(file,"is recorded in the logfile as unpublished data and in .gitignore and so will not be included as part of the commit.\n\n")
} else {
cat(file, "is recorded in the logfile as unpublished data and in .gitignore and so will not be included as part of the commit.\n\n")
}
}
}
}

if(grepl('G-Z967JJVQQX', htmltools::includeHTML(("google-analytics.html"))) &
!(toupper(Sys.getenv("USERNAME")) %in% c("CFOSTER4", "CRACE", "LSELBY","RBIELBY", "JMACHIN"))){
cat("Cleaning out the template's Google Analytics tag.",fill=TRUE)
if (grepl("G-Z967JJVQQX", htmltools::includeHTML(("google-analytics.html"))) &
!(toupper(Sys.getenv("USERNAME")) %in% c("CFOSTER4", "CRACE", "LSELBY", "RBIELBY", "JMACHIN"))) {
cat("Cleaning out the template's Google Analytics tag.", fill = TRUE)
gsub_file("google-analytics.html", pattern = "G-Z967JJVQQX", replacement = "G-XXXXXXXXXX")
gsub_file("ui.R", pattern = "Z967JJVQQX", replacement = "XXXXXXXXXX")
system2(command = "git", args=c("add","google-analytics.html"))
system2(command = "git", args = c("add", "google-analytics.html"))
}

if (error_flag) {
Expand All @@ -68,7 +67,7 @@ if (error_flag) {
}

tidy_output <- tidy_code()
if(any(tidy_output)){
if (any(tidy_output)) {
error_flag <- TRUE
}

Expand Down
14 changes: 13 additions & 1 deletion renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,11 @@
"Version": "0.5.2",
"Source": "GitHub",
"RemoteType": "github",
"RemoteHost": "api.github.com",
"RemoteUsername": "dfe-analytical-services",
"RemoteRepo": "dfeshiny",
"RemoteRef": "main",
"RemoteSha": "91f1eb3cbac6e1d2ba64300e22a36c95a73dda25",
"RemoteHost": "api.github.com",
"Requirements": [
"R",
"RCurl",
Expand Down Expand Up @@ -475,6 +475,18 @@
],
"Hash": "bcaa8b95f8d7d01a5dedfd959ce88ab8"
},
"diffviewer": {
"Package": "diffviewer",
"Version": "0.1.2",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
"R",
"htmlwidgets",
"jsonlite"
],
"Hash": "42c3ea48cba4a88987d55e64008d2f3b"
},
"digest": {
"Package": "digest",
"Version": "0.6.37",
Expand Down
60 changes: 10 additions & 50 deletions tests/testthat/_snaps/shinytest2-basic-checks/basic_load-001.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,17 @@
{
"input": {
"cookieAccept": 0,
"cookieLink": 0,
"cookieReject": 0,
"cookies": {

},
"hideAccept": 0,
"hideReject": 0,
"link_to_app_content_tab": 0,
"navlistPanel": "dashboard",
"selectArea": "England",
"selectBenchLAs": null,
"selectPhase": "All LA maintained schools",
"tabsetpanels": "Valuebox example"
"a": 5,
"data_source": "National data only",
"dropdown_cohort": "A level",
"dropdown_qualifications": "Applied GCE AS level",
"dropdown_sizes": "0.5",
"dropdown_subjects": "Applied ICT",
"n": 5,
"navlistPanel": "User guide and information",
"tabsetpanels": "All Students",
"upload": null
},
"output": {
"boxavgRevBal": {
"html": "<div class=\"small-box bg-blue\">\n <div class=\"inner\">\n <p id=\"vboxhead-medium\">£160,486<\/p>\n <p id=\"vboxdetail-medium\">This is the latest value for the selected inputs<\/p>\n <\/div>\n<\/div>",
"deps": [

]
},
"boxavgRevBal_large": {
"html": "<div class=\"small-box bg-green\">\n <div class=\"inner\">\n <p id=\"vboxhead-large\">£160,486<\/p>\n <p id=\"vboxdetail-large\">This is the latest value for the selected inputs<\/p>\n <\/div>\n<\/div>",
"deps": [

]
},
"boxavgRevBal_small": {
"html": "<div class=\"small-box bg-orange\">\n <div class=\"inner\">\n <p id=\"vboxhead-small\">£160,486<\/p>\n <p id=\"vboxdetail-small\">This is the latest value for the selected inputs<\/p>\n <\/div>\n<\/div>",
"deps": [

]
},
"boxpcRevBal": {
"html": "<div class=\"small-box bg-blue\">\n <div class=\"inner\">\n <p id=\"vboxhead-medium\">£49,794<\/p>\n <p id=\"vboxdetail-medium\">This is the change on previous year<\/p>\n <\/div>\n<\/div>",
"deps": [

]
},
"boxpcRevBal_large": {
"html": "<div class=\"small-box bg-green\">\n <div class=\"inner\">\n <p id=\"vboxhead-large\">£49,794<\/p>\n <p id=\"vboxdetail-large\">This is the change on previous year<\/p>\n <\/div>\n<\/div>",
"deps": [

]
},
"boxpcRevBal_small": {
"html": "<div class=\"small-box bg-orange\">\n <div class=\"inner\">\n <p id=\"vboxhead-small\">£49,794<\/p>\n <p id=\"vboxdetail-small\">This is the change on previous year<\/p>\n <\/div>\n<\/div>",
"deps": [

]
},
"dropdown_label": "Current selections: All LA maintained schools, England"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading