Skip to content

Copy R Shiny app to cloud-gov branch and request push to dev #10

Copy R Shiny app to cloud-gov branch and request push to dev

Copy R Shiny app to cloud-gov branch and request push to dev #10

name: Copy R Shiny app to cloud-gov branch and request push to dev
on:
workflow_dispatch:
inputs:
build_deps:
description: 'Also build R dependencies?'
required: true
default: true
type: boolean
build_bins:
description: 'Also build binaries?'
required: true
default: false
type: boolean
permissions:
contents: write
jobs:
copy_code_to_cloud-gov:
runs-on: ubuntu-latest
name: Copy default branch code to shiny-app folder within cloud-gov branch
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 1
ref: cloud-gov
- name: Delete shiny-app and main-branch folders if they exist
run: |
if [ -d "shiny-app" ]; then rm -fr shiny-app; fi
if [ -d "main-branch" ]; then rm -fr main-branch; fi
- name: Checkout default branch to main-branch path
uses: actions/checkout@v4
with:
fetch-depth: 1
path: main-branch
- name: Copy everything but .git*, Commit, and Push
if: ${{ success() }}
run: |
mkdir shiny-app
find main-branch/* -maxdepth 0 ! -name ".git*" -print0 ! -name ".devcontainer" -print0 | xargs -0 cp -r -t shiny-app
cp main-branch/.gitignore shiny-app/.gitignore
git config user.name github-actions
git config user.email github-actions@github.com
git add shiny-app
git diff-index --quiet HEAD || git commit -m "Automated workflow from GitHub Actions to copy R Shiny app from default branch"
git push
env:
BUILD_DEPS: ${{ inputs.build_deps }}
download_and_vendor_dependencies:
if: ${{ inputs.build_deps }}
needs: copy_code_to_cloud-gov
runs-on: ubuntu-latest
name: Compile and vendor R dependencies for cloud.gov
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 1
ref: cloud-gov
- name: Setup Git and remove problematic packages
run: |
git config --global --add safe.directory $(realpath .)
git config user.name github-actions
git config user.email github-actions@github.com
sudo apt --purge autoremove -y libmariadb-dev libmariadb-dev-compat
- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- name: Setup pandoc
uses: r-lib/actions/setup-pandoc@v2
- name: Install R dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
packages: |
stringr
devtools
rlist
sf
rjson
dplyr
- name: List R dependencies
run: |
sed -n -e 's/^.*- name: //p' r.yml | tr -d '\015' | sed -n -e 'H;${x;s/\n/,/g;s/^,//;p;}' | xargs echo packs= >> $GITHUB_ENV
- name: Download R packages
run: |
if [ -d "vendor_r" ]; then rm -fr vendor_r; fi
Rscript scripts/download_packages.R vendor_r/src/contrib ${{ env.packs }}
cd vendor_r/src/contrib
if ls sf_* >/dev/null 2>&1; then echo needs_geo=true; else echo needs_geo=false; fi >> $GITHUB_ENV
if ls rmarkdown_* >/dev/null 2>&1; then echo needs_pandoc=true; else echo needs_pandoc=false; fi >> $GITHUB_ENV
if ls *_R_x86_64-pc-linux-gnu.tar.gz >/dev/null 2>&1; then
find -name '*_R_x86_64-pc-linux-gnu.tar.gz' -print0 | sed -ze "p;s/\_R_x86_64-pc-linux-gnu//" | xargs -0 -n2 mv;
fi
cd ../../..
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
- name: Run lib_tar.sh to extract each of the libraries needed by sf
if: ${{ env.needs_geo == 'true' && inputs.build_bins }}
run: |
if [ -d "lib" ]; then rm -fr lib; fi
mkdir lib
chmod +x scripts/lib_tar.sh
for L in $LIBS
do
find / -iname $L 2>/dev/null | xargs -I {} scripts/lib_tar.sh {}
done
scripts/lib_tar.sh /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 # Another libsqlite3.so.0 exists on the image
git add lib
env:
LIBS: libudunits2.so.0 libgeos_c.so libproj.so.22 proj.db libgdal.so.30
- name: Copy pandoc executable
if: ${{ env.needs_pandoc == 'true' && inputs.build_bins }}
run: |
if [ -d "bin" ]; then rm -fr bin; fi
mkdir bin
tar -czvf bin/pandoc.tar.gz /usr/bin/pandoc
git add bin
- name: Add additional files to repo if not already there
run: |
if ! ls manifest*.yml >/dev/null 2>&1; then
mv scripts/include/manifest.yml .
git add manifest.yml
fi
if [ ! -f ".cfignore" ]; then
mv scripts/include/.cfignore .
git add .cfignore
fi
if [ ! -f "shiny.R" ]; then
mv scripts/include/shiny.R .
git add shiny.R
fi
- name: Upload folder debug-outputs to an artifact
uses: actions/upload-artifact@v4
with:
name: debug-outputs
path: debug-outputs
- name: Commit & Push
if: ${{ success() }}
run: |
git add vendor_r
git diff-index --quiet HEAD || git commit -m "Automated workflow from GitHub Actions to vendor R dependencies"
git push
request_copy:
# Note: this step will fail if OWSHINY_ACTION secret is not set up in the repo and should be removed
name: Request copy uploaded to deployment repo if permitted
needs: [copy_code_to_cloud-gov, download_and_vendor_dependencies]
if: always() && !contains(needs.*.result, 'failure')
# Needs to run even if download_and_vendor_dependencies was skipped
runs-on: ubuntu-latest
steps:
- name: Trigger Workflow to copy for deployment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.OWSHINY_ACTION }}
script: |
github.rest.actions.createWorkflowDispatch({
owner: 'USEPA',
repo: 'OWShiny',
workflow_id: 'copy_repo.yml',
ref: 'develop',
inputs: {
"repo_to_copy": context.repo.owner + "/" + context.repo.repo
}
})