-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAppend_File_On_Merged_to_Main.yml
More file actions
384 lines (271 loc) · 13.2 KB
/
Append_File_On_Merged_to_Main.yml
File metadata and controls
384 lines (271 loc) · 13.2 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
name: Adding documentation and update GitHub Page
run-name: Action on Merged main by ${{ github.actor }}
on:
workflow_call:
inputs:
image_to_use:
required: true
type: string
artifact_rid:
required: true
type: string
package_name:
required: true
type: string
r_version:
required: true
type: string
secrets:
NIDAP_TOKEN:
required: false
jobs:
Document_GitHub_Page_CD:
name: Post Merged to Main by ${{ github.actor }}
runs-on: ubuntu-latest
container:
image: ${{ inputs.image_to_use }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- run: echo "Checking in ${{ inputs.image_to_use }}"
- uses: actions/checkout@v3
with:
token: ${{secrets.GITHUB_TOKEN}}
- name: Generating files with Document
id: prepare-push
if: ${{ success() }}
run: |
bash
./root/miniconda3/etc/profile.d/conda.sh && conda init bash
export current_wd="/__w/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/}"
cd $current_wd
export MY_GIT_TOKEN=${{ secrets.GITHUB_TOKEN }}
export MY_GIT_USERNAME=${{ github.actor }}
export MY_GIT_EMAIL=${{ github.event.pusher.email }}
git config --global user.name "$MY_GIT_USERNAME"
git config --global user.email "$MY_GIT_EMAIL"
git config --global url."https://api:$MY_GIT_TOKEN@github.com/".insteadOf "https://github.com/"
git config --global url."https://ssh:$MY_GIT_TOKEN@github.com/".insteadOf "ssh://git@github.com/"
git config --global url."https://git:$MY_GIT_TOKEN@github.com/".insteadOf "git@github.com:"
git config --global --add safe.directory "$current_wd"
git clone https://github.com/fnlcr-dmap/gitflow-R.git
cd $current_wd
git clone https://github.com/${GITHUB_REPOSITORY}.git
cd ${GITHUB_REPOSITORY#*/}
BRANCH_NAME="Conda_Package"
git checkout $BRANCH_NAME
git checkout main
current_version=$(grep -oP 'Version: \K.*' DESCRIPTION)
echo "Upcoming Production Package Name: ${{ inputs.package_name }}"
echo "Upcoming Production Package Version: $current_version"
echo "\nWriting Documentations Now......\n"
R -e 'library(devtools);document()'
if [ -d "./vignettes" ]; then
HAS_VIGNETTES=True
else
HAS_VIGNETTES=False
fi
if [ "$HAS_VIGNETTES" = True ]; then
mv ./vignettes ./bk_vignettes
fi
# ls -al /renv/library/R-4.1/x86_64-pc-linux-gnu
R -e 'library(devtools);load_all();library(pkgdown);build_site_github_pages()'
if [ "$HAS_VIGNETTES" = True ]; then
mkdir -p ./docs/vignettes
if [ -n "$(find ./bk_vignettes -maxdepth 1 -type f -name '*.html')" ]; then
# HTML files exist, so copy them to ./docs/vignettes
mkdir -p ./docs/vignettes && cp ./bk_vignettes/*.html ./docs/vignettes
else
# HTML files do not exist, display an error message or take appropriate action
echo "No HTML files found in the ./bk_vignettes directory."
# You can add more error handling or actions here as needed
fi
fi
if [ "$HAS_VIGNETTES" = True ]; then
mv ./bk_vignettes ./vignettes
fi
git add ./NAMESPACE ./man/* ./DESCRIPTION ./CHANGELOG.md
echo $(git commit -a -m "docs: Adding auto-generated files") > commit_log.log
echo "Performing check now"
export nothing_for_commit="$(grep -Po "nothing to commit" commit_log.log)"
if [ -n "${nothing_for_commit}" ]; then
echo "Commit check failed with message: $nothing_for_commit"
else
echo "Pushing changes now."
git push -f origin main
fi
echo "$(git log --oneline --ancestry-path ${{github.event.pull_request.head.sha}}..HEAD)" > \
$current_wd/commit_history_log.log
commit_log_location="$current_wd/commit_history_log.log"
cp $(pwd)/Conda_Recipe/meta.yaml $current_wd
conda_recipe="$current_wd/meta.yaml"
change_log_location="$current_wd/commit_history_log.log"
echo "conda_recipe=$conda_recipe" >> $GITHUB_ENV
echo "commit_log_location=$commit_log_location" >> $GITHUB_ENV
echo "Create release tag for Continueous Deployment"
latest_commit_hash=$(git rev-parse HEAD)
TAG_NAME="continuous_deployment"
# Check if the tag exists locally
if git rev-parse -q --verify "refs/tags/$TAG_NAME" >/dev/null; then
echo "Local tag '$TAG_NAME' exists. Deleting..."
git tag -d "$TAG_NAME"
else
echo "Local tag '$TAG_NAME' does not exist."
fi
# Check if the tag exists remotely
if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME"; then
echo "Remote tag '$TAG_NAME' exists. Deleting..."
git push origin ":refs/tags/$TAG_NAME"
else
echo "Remote tag '$TAG_NAME' does not exist."
fi
git tag \
-a "$TAG_NAME" \
-m "Automatically tagged latest commit for continuous_deployment." \
$latest_commit_hash
git push origin $TAG_NAME
echo "Now pushing GitHub Page Documents"
if [ "$HAS_VIGNETTES" = True ]; then
cp ./vignettes/*.png ./docs/articles
fi
git add ./docs/*
git add ./docs/.*
if git diff --cached --name-only | grep -q 'commit_log.log'; then
git reset HEAD commit_log.log
fi
git commit -a -m "Documenting doc files."
echo $(git checkout github_page) > checkout_check.log
export no_branch="$(grep -Po "did not match any file(s) known" checkout_check.log)"
if [ -n "${no_branch}" ]; then
git checkout -b github_page
fi
git checkout -f main ./docs
echo $(git commit -a -m "Updating GitHub Page") > commit_log.log
cat commit_log.log
export nothing_for_commit="$(grep -Po "nothing to commit" commit_log.log)"
if [ -n "${nothing_for_commit}" ]; then
echo "Commit check failed with message: $nothing_for_commit"
else
echo "Pushing changes now."
git push -f origin github_page
fi
echo "Process completed."
- name: Generating Conda Package
id: prepare-conda-pkg
if: ${{ success() }}
run: |
export current_wd="/__w/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/}"
cd $current_wd/${GITHUB_REPOSITORY#*/}
git checkout main
VERSION=$(grep -oP 'Version: \K[\d.]+' DESCRIPTION)
cd ../
mkdir conda_pkg_building
cd conda_pkg_building
CONDA_DIR=$(pwd)
BRANCH_NAME="Conda_Package"
export MY_GIT_TOKEN=${{ secrets.GITHUB_TOKEN }}
export MY_GIT_USERNAME=${{ github.actor }}
export MY_GIT_EMAIL=${{ github.event.pusher.email }}
git config --global user.name "$MY_GIT_USERNAME"
git config --global user.email "$MY_GIT_EMAIL"
git config --global url."https://api:$MY_GIT_TOKEN@github.com/".insteadOf "https://github.com/"
git config --global url."https://ssh:$MY_GIT_TOKEN@github.com/".insteadOf "ssh://git@github.com/"
git config --global url."https://git:$MY_GIT_TOKEN@github.com/".insteadOf "git@github.com:"
git config --global --add safe.directory "$current_wd"
# Check if conda-build is installed
# if ! command -v conda mambabuild &> /dev/null; then
# echo "conda mambabuild is not installed. Installing..."
# conda install -c conda-forge boa
# fi
REPO_NAME_LOWERCASE=$(echo ${GITHUB_REPOSITORY#*/} | \
tr '[:upper:]' '[:lower:]')
echo "$(pwd)"
echo "$(ls)"
PACKAGE_NAME="${{ inputs.package_name }}"
echo "Package Name: $PACKAGE_NAME"
echo "New version: $VERSION"
mkdir r-$PACKAGE_NAME
cp -rf $current_wd/${GITHUB_REPOSITORY#*/}/Conda_Recipe/meta.yaml ./r-$PACKAGE_NAME/
cp $current_wd/gitflow-R/src/bld.bat ./r-$PACKAGE_NAME/
cp $current_wd/gitflow-R/src/build.sh ./r-$PACKAGE_NAME/
sed -i "s/<CURRENT_VERSION>/$VERSION/g" ./r-$PACKAGE_NAME/meta.yaml
echo "\n\n##########Current Recipe:##################\n\n"
cat ./r-$PACKAGE_NAME/meta.yaml
echo "\n\n##########################################\n\n"
# Construct the package name as "r-repository_name"
RECIPE_DIR="$(pwd)/$PACKAGE_NAME"
echo "Recipe is now in $RECIPE_DIR."
echo "#####################################################"
# Build the Conda package while ignoring tests
echo "#####################################################"
echo "Building Conda Package Now."
echo "#####################################################"
# conda config --set channel_priority strict
conda config --add channels conda-forge
conda config --append channels file:///local_channel
conda config --append channels bioconda
conda config --append channels defaults
conda config --get channels
conda clean --all
echo "#####################################################"
conda build --R="${{ inputs.r_version }}" r-$PACKAGE_NAME
echo "#####################################################"
PKG_PATH=$(find "/conda/conda-bld" -name '*.tar.bz2')
# --build-only \
echo "Package build in $PKG_PATH"
echo "#####################################################"
echo "Package Built! Uploading to $BRANCH_NAME now"
cd $current_wd/${GITHUB_REPOSITORY#*/}
BRANCH_NAME="Conda_Package"
git checkout "$BRANCH_NAME"
# Move the built package to the current directory
echo "Moving Conda Package Now."
PKG_NAME=$(basename "$PKG_PATH")
DEST_NAME="$PKG_NAME"
mv $PKG_PATH .
git add *.tar.bz2
current_pkg="$(basename "$PKG_PATH")"
echo "current_pkg="$current_pkg"" >> $GITHUB_ENV
echo "###############################################################"
echo "\nCurrent package: $current_pkg"
- name: Continuous Deployment to NIDAP
id: nidap-cd
if: ${{ success() }}
run: |
export current_wd="/__w/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/}"
cd $current_wd
cd ${GITHUB_REPOSITORY#*/}
conda install curl
echo "Package to Upload: ${{ env.current_pkg }}"
TOKEN="${{ secrets.NIDAP_TOKEN }}"
PACKAGE="${{ env.current_pkg }}"
PLATFORM="linux-64" # replace with the package platform (e.g. noarch, linux-64, osx-64)
response=$(curl \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary "@$PACKAGE" \
-XPUT "https://nidap.nih.gov/artifacts/api/repositories/ri.artifacts.main.repository.00852eef-c60b-4b78-8f14-cd48cdfde051/contents/release/conda/$PLATFORM/$PACKAGE" \
2>&1)
current_datetime="$(date +"%Y-%m-%d %H:%M:%S")"
echo "\nDatetime: $current_datetime, Version: ${{ env.current_pkg }}"
echo "\nDatetime: $current_datetime, Version: ${{ env.current_pkg }}" >> README.md
current_log_name=${{ env.current_pkg }}
current_log_name="${current_log_name%.tar.bz2}"
current_log_name="Commit_Log_$current_log_name.log"
mv "${{ env.commit_log_location }}" "$current_log_name"
git add ./$current_log_name
echo "<br>[View Commit Log]($current_log_name)" >> README.md
echo "#########################################################"
# Check if the response contains an error message
if echo "$response" | grep -q "errorCode"; then
error_name=$(echo "$response" | grep -o '"errorName":"[^"]*' | awk -F'"' '{print $4}')
echo "Error message: $error_name"
echo "<br>Deployment Status: $error_name" >> README.md
else
echo "Update Success!"
echo "Package ${{ env.current_pkg }} is now on NIDAP."
echo "<br>Deployment Status: Success" >> README.md
fi
git commit -a -m "Automatically build conda package"
git push -f origin $BRANCH_NAME