Skip to content

Commit 254a029

Browse files
Update README.md
1 parent 67b7060 commit 254a029

File tree

1 file changed

+84
-8
lines changed

1 file changed

+84
-8
lines changed

README.md

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,23 @@ The chmod command just makes the .sh files executable.
8080

8181
• Both files can be found on the tutorial’s repository. Here are the links to [setup.sh](https://github.com/opencobra/COBRA.tutorials/blob/master/setup.sh) and [build.sh](https://github.com/opencobra/COBRA.tutorials/blob/master/build.sh)
8282

83-
![image](https://github.com/opencobra/cobratoolbox/assets/68754265/b9a748df-c94c-45bb-bedd-1d84482ea14a)
84-
83+
```
84+
- name: Sync with Destination Repo
85+
run: |
86+
counter=0
87+
for file in ${{ steps.getfile.outputs.file }}; do
88+
if [ $counter -eq 0 ]
89+
then
90+
# This is the first iteration, handle the file differently
91+
./setup.sh opencobra/cobratoolbox ${{ secrets.DEST_REPO_TOKEN }} $file
92+
./build.sh opencobra/cobratoolbox ${{ secrets.DEST_REPO_TOKEN }} $file
93+
else
94+
./build.sh openCOBRA/cobratoolbox ${{ secrets.DEST_REPO_TOKEN }}
95+
fi
96+
counter=$((counter+1))
97+
done
98+
if: steps.getfile.outputs.file != ''
99+
```
85100

86101
Here is the code to run the setup.sh and build.sh. We loop through all the .mlx files that were pushed. If it is the first file we are looking at we also run setup.sh to create the folder locations in the cobratoolbox – ghpages branch repository. Then afterwards build,sh is ran to convert the file to html and push to the created folder location
87102

@@ -101,31 +116,92 @@ In a similar fashion to the first step a .yml file is in the .github/workflows f
101116

102117
The main.yml can be explained as follows:
103118

104-
![image](https://github.com/opencobra/cobratoolbox/assets/68754265/36885564-4f94-4615-a85e-5e2acb388e25)
119+
```
120+
on:
121+
push:
122+
branches: [ gh-pages ]
123+
paths:
124+
- '**.html'
125+
```
105126

106127

107128
This specifies that the .yml file will run if a .html file is pushed to the gh-pages branch.
108129

109-
![image](https://github.com/opencobra/cobratoolbox/assets/68754265/c9ebbeec-1699-40ce-88bd-97005fd7f39b)
130+
```
131+
jobs:
132+
extract-info:
133+
runs-on: ubuntu-latest
134+
steps:
135+
- name: Checkout Repository
136+
uses: actions/checkout@v2
137+
with:
138+
token: ${{ secrets.GITHUB_TOKEN }}
139+
fetch-depth: 0
140+
```
110141

111142
Here the second step is to checkout the repository and find any changes that were made. Also note that we are now running on ‘ubuntu-latest’ and not ‘self-hosted’ as there is no need to use King for this part.
112143

113-
![image](https://github.com/opencobra/cobratoolbox/assets/68754265/9005eef6-820c-4e61-96b1-e450296b122d)
144+
```
145+
- name: Check Commit Message
146+
id: check_msg
147+
run: |
148+
commit_msg=$(git log --format=%B -n 1)
149+
if [[ "$commit_msg" == "Sync files from source repo" ]]; then
150+
echo "::set-output name=run_job::true"
151+
else
152+
echo "::set-output name=run_job::false"
153+
fi
154+
```
114155

115156

116157
In the tutorials repo we push to the gh-pages branch with the particular comment: ‘Sync files from source repo’. This helps distinguish between slight edits made to pages on the website and tutorial pushes from the tutorials repo. Here this piece of code checks this.
117158

118-
![image](https://github.com/opencobra/cobratoolbox/assets/68754265/e7b7338c-87e3-4f34-83a7-57b2cbe8b0a0)
159+
```
160+
- name: Set up Python
161+
uses: actions/setup-python@v2
162+
if: steps.check_msg.outputs.run_job == 'true'
163+
with:
164+
python-version: '3.x'
165+
166+
- name: Install Dependencies
167+
if: steps.check_msg.outputs.run_job == 'true'
168+
run: |
169+
python -m pip install --upgrade pip
170+
pip install beautifulsoup4
119171
172+
- name: Get Changed HTML Files
173+
id: getfile
174+
if: steps.check_msg.outputs.run_job == 'true'
175+
run: |
176+
changed_files=$(git diff --name-only HEAD~1 HEAD | grep '\.html')
177+
echo "::set-output name=file::$changed_files"
178+
```
120179

121180
Here are some basic steps such as 1. Set up python got github actions 2. Install Python dependencies needed 3. Get the html files that were pushed to the repository.
122181

123-
![image](https://github.com/opencobra/cobratoolbox/assets/68754265/b0a063ed-5172-42a5-83de-47f3cb5d1ae1)
182+
```
183+
- name: Extract Info from HTML Files
184+
if: steps.check_msg.outputs.run_job == 'true'
185+
run: |
186+
for file in ${{ steps.getfile.outputs.file }}
187+
do
188+
python extract_info.py $file
189+
done
190+
```
124191

125192

126193
Now we run the python file to configure the website to adjust to the added tutorial.
127194

128-
![image](https://github.com/opencobra/cobratoolbox/assets/68754265/5eeda5b7-e8d3-4bb8-9ae6-79676ddfbf4a)
195+
```
196+
- name: Commit and Push New File
197+
if: steps.check_msg.outputs.run_job == 'true'
198+
run: |
199+
git config user.name "GitHub Action"
200+
git config user.email "[email protected]"
201+
git add .
202+
git commit -m "Sync files from source repo" || echo "No changes to commit"
203+
git push -f origin gh-pages
204+
```
129205

130206
After changing and adding the folders/files around in the repo we push the changes to the repository
131207

0 commit comments

Comments
 (0)