-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.yml
161 lines (159 loc) · 7.3 KB
/
config.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
version: 2
jobs:
build:
working_directory: ~/eds-lessons-website
machine:
image: ubuntu-1604:201903-01
steps:
- checkout
- run:
name: "Set Python Version"
command: pyenv global 3.7.0
- run:
name: Get latest lesson commit to master branch
working_directory: ~/eds-lessons-website
command: |
# ACMRT -- only looks at changed files, not deleted ones
changed_files=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMRT -r -m HEAD 2>&1)
# get names of changed files
echo "${changed_files} ">> changed_files.txt
# Remove unwanted files from commit and count files changed
python scripts/parse-commit.py
# Get latest commit message
echo $(git log -1 --pretty=%B) > commit_msg_latest.txt
if [[ -f website_files.txt ]]
then
echo "The following files were modified: "
cat website_files.txt
else
echo "No files were modified in the last commit."
fi
- run:
name: Get removed, renamed, or moved files
working_directory: ~/eds-lessons-website
command: |
deleted_files=$(git diff-tree --no-commit-id --name-only --diff-filter=D -r HEAD 2>&1)
# get names of changed files
echo "${deleted_files} ">> deleted_files.txt
python scripts/parse-deleted.py
ls
- run:
name: Get & print current branch
working_directory: ~/eds-lessons-website
command: |
# get the current branch
echo $(git branch | sed -n -e 's/^\* \(.*\)/\1/p') > current_branch.txt
# Print out current branch
echo "Working on this branch: "
cat current_branch.txt
- run:
name: Clone earthlab.github.io website branch NEW
working_directory: ~/
command: |
branch=$(head -1 eds-lessons-website/current_branch.txt)
# Only clone eds.org if there are files to commit
if [[ -f ~/eds-lessons-website/website_files.txt ]] || [ -f ~/eds-lessons-website/deleted_files.txt ]
then
if [ "$branch" != "master" ]
then
# check that branch exists on remote earthlab.github.io
branch_status=$(git ls-remote --heads https://${EDS_LESSONS_GITHUB_TOKEN_EL}@github.com/earthlab/earthlab.github.io.git "$branch" | wc -l)
# if branch exists, clone it
if [ $branch_status == 1 ]
then
# clone the remote branch
git clone --depth 1 https://${EDS_LESSONS_GITHUB_TOKEN_EL}@github.com/earthlab/earthlab.github.io.git -b "$branch"
echo "Looks like the branch doesn't exist on the eds.org website, created branch for you."
else
# if the branch doesn't exist, clone master and checkout the branch as a new branch
git clone --depth 1 https://${EDS_LESSONS_GITHUB_TOKEN_EL}@github.com/earthlab/earthlab.github.io.git
cd earthlab.github.io
git checkout -b "$branch"
fi
else
# if commits are on master, push to website-autobuild to avoid direct commits to live website
# check for autobuild branch on website remote
branch_status=$(git ls-remote --heads https://${EDS_LESSONS_GITHUB_TOKEN_EL}@github.com/earthlab/earthlab.github.io.git "website-autobuild" | wc -l)
# if branch exists check it out...
if [ $branch_status == 1 ]
then
# clone the remote branch
git clone -b website-autobuild --depth 1 https://${EDS_LESSONS_GITHUB_TOKEN_EL}@github.com/earthlab/earthlab.github.io.git
else
# if it does not, clone master and checkout a new branch
git clone --depth 1 https://${EDS_LESSONS_GITHUB_TOKEN_EL}@github.com/earthlab/earthlab.github.io.git
cd earthlab.github.io
git checkout -b website-autobuild
fi
fi
# Only Copy files to the live website repo if there are files to move
# This might be nice as it's own step.
if [[ -f website_files.txt ]]
then
cd ~/eds-lessons-website
python scripts/move-files.py
fi
else
echo "There are no changes, not cloning the website repo."
fi
pwd
- run:
name: Delete removed/renamed/moved images from .io website
working_directory: ~/eds-lessons-website
command: |
if [[ -f deleted_image_files.txt ]]
then
echo -e "Deleting the following images:"
cat deleted_image_files.txt | while read line
do
echo $line
image_to_delete=~/earthlab.github.io/$line
rm $image_to_delete
done
else
echo "There are no images to remove in this PR!"
fi
- run:
name: Delete removed/renamed/moved markdown files and associated image directories from .io website
working_directory: ~/eds-lessons-website
command: |
ls
if [[ -f deleted_md_files.txt ]]
then
echo -e "Deleting the following notebooks and their images:"
cat deleted_md_files.txt | while read line
do
echo $line
post_to_delete=~/earthlab.github.io/$line
rm $post_to_delete
echo "$post_to_delete"
# clear images dir associated with post
image_dir_to_delete=~/earthlab.github.io/images/${line%.*}
rm -rf $image_dir_to_delete
echo "$image_dir_to_delete"
done
else
echo "There are no lessons and associated lesson images to remove in this PR!"
fi
- run:
name: Push changes in files and images to earthlab.github.io repo
working_directory: ~/earthlab.github.io
command: |
if [[ -f ~/eds-lessons-website/website_files.txt ]] || [ -f ~/eds-lessons-website/deleted_files.txt ]
then
# Be sure to see how many files there are and only commit if there are more than 0
git status
git config credential.helper 'cache --timeout=120'
git config user.email "earth.lab@colorado.edu"
git config user.name "Deployment Bot"
OUTPUT=$( GIT_PAGER_IN_USE=true git status )
echo "$OUTPUT"
git add .
# get current commit message
commit_msg_latest=$(head -1 ~/eds-lessons-website/commit_msg_latest.txt)
git commit --allow-empty -m "$commit_msg_latest"
# Push quietly to prevent showing the token in log
git push -q https://${EDS_LESSONS_GITHUB_TOKEN_EL}@github.com/earthlab/earthlab.github.io.git
else
echo "Nothing to commit as there were no changes"
fi