-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67b7060
commit 254a029
Showing
1 changed file
with
84 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,8 +80,23 @@ The chmod command just makes the .sh files executable. | |
|
||
• 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) | ||
|
||
 | ||
|
||
``` | ||
- name: Sync with Destination Repo | ||
run: | | ||
counter=0 | ||
for file in ${{ steps.getfile.outputs.file }}; do | ||
if [ $counter -eq 0 ] | ||
then | ||
# This is the first iteration, handle the file differently | ||
./setup.sh opencobra/cobratoolbox ${{ secrets.DEST_REPO_TOKEN }} $file | ||
./build.sh opencobra/cobratoolbox ${{ secrets.DEST_REPO_TOKEN }} $file | ||
else | ||
./build.sh openCOBRA/cobratoolbox ${{ secrets.DEST_REPO_TOKEN }} | ||
fi | ||
counter=$((counter+1)) | ||
done | ||
if: steps.getfile.outputs.file != '' | ||
``` | ||
|
||
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 | ||
|
||
|
@@ -101,31 +116,92 @@ In a similar fashion to the first step a .yml file is in the .github/workflows f | |
|
||
The main.yml can be explained as follows: | ||
|
||
 | ||
``` | ||
on: | ||
push: | ||
branches: [ gh-pages ] | ||
paths: | ||
- '**.html' | ||
``` | ||
|
||
|
||
This specifies that the .yml file will run if a .html file is pushed to the gh-pages branch. | ||
|
||
 | ||
``` | ||
jobs: | ||
extract-info: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
fetch-depth: 0 | ||
``` | ||
|
||
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. | ||
|
||
 | ||
``` | ||
- name: Check Commit Message | ||
id: check_msg | ||
run: | | ||
commit_msg=$(git log --format=%B -n 1) | ||
if [[ "$commit_msg" == "Sync files from source repo" ]]; then | ||
echo "::set-output name=run_job::true" | ||
else | ||
echo "::set-output name=run_job::false" | ||
fi | ||
``` | ||
|
||
|
||
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. | ||
|
||
 | ||
``` | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
if: steps.check_msg.outputs.run_job == 'true' | ||
with: | ||
python-version: '3.x' | ||
- name: Install Dependencies | ||
if: steps.check_msg.outputs.run_job == 'true' | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install beautifulsoup4 | ||
- name: Get Changed HTML Files | ||
id: getfile | ||
if: steps.check_msg.outputs.run_job == 'true' | ||
run: | | ||
changed_files=$(git diff --name-only HEAD~1 HEAD | grep '\.html') | ||
echo "::set-output name=file::$changed_files" | ||
``` | ||
|
||
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. | ||
|
||
 | ||
``` | ||
- name: Extract Info from HTML Files | ||
if: steps.check_msg.outputs.run_job == 'true' | ||
run: | | ||
for file in ${{ steps.getfile.outputs.file }} | ||
do | ||
python extract_info.py $file | ||
done | ||
``` | ||
|
||
|
||
Now we run the python file to configure the website to adjust to the added tutorial. | ||
|
||
 | ||
``` | ||
- name: Commit and Push New File | ||
if: steps.check_msg.outputs.run_job == 'true' | ||
run: | | ||
git config user.name "GitHub Action" | ||
git config user.email "[email protected]" | ||
git add . | ||
git commit -m "Sync files from source repo" || echo "No changes to commit" | ||
git push -f origin gh-pages | ||
``` | ||
|
||
After changing and adding the folders/files around in the repo we push the changes to the repository | ||
|
||
|