-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (160 loc) · 5.83 KB
/
build-cloud-gov.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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
}
})