Copy R Shiny app to cloud-gov branch and request push to dev #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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@v3 | |
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@v3 | |
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 | xargs -0 cp -r -t shiny-app | |
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 | |
defaults: | |
run: | |
working-directory: /workspace | |
container: | |
image: cloudfoundry/cflinuxfs4 | |
volumes: | |
- ${{ github.workspace }}:/workspace | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
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: | |
r-version: 4.3.1 | |
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 | |
- 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' }} | |
# run: | | |
# if [ -d "r-lib" ]; then rm -fr r-lib; fi | |
# mkdir r-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 r-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' }} | |
# run: | | |
# if [ -d "r-bin" ]; then rm -fr r-bin; fi | |
# mkdir r-bin | |
# cp /usr/bin/pandoc r-bin | |
# git add r-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: 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@v6 | |
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 | |
} | |
}) |