Skip to content

Create images directory #329

Create images directory

Create images directory #329

name: Deploy to GitHub Pages
on:
push:
branches: [ main ]
pull_request:
env:
BASE_BRANCH_NAME: main
HOSTING_BRANCH_NAME: gh-pages
LOCAL_BRANCH_NAME: gh-pages-local
jobs:
Build-and-deploy:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.6.7'
- name: Check branch
if: github.event_name == 'pull_request'
# github.head_ref: source branch of the pull request in a workflow run https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
run: |
echo "BASE_BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
- name: Setup git
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
cd $GITHUB_WORKSPACE
git fetch
- name: Clean up
# The reason why we don't use origin/gh-pages and just merge to it is, to prevent git complains gh-pages and the base branch have unrelated histories and conflicts on merge (it should never happen. idk why this happens)
continue-on-error: true
run: |
git branch -d $LOCAL_BRANCH_NAME
- name: Checkout
run: |
git fetch
git checkout $BASE_BRANCH_NAME
git pull
git checkout -b $LOCAL_BRANCH_NAME
- name: Build
id: build_step
run: |
python -m pip install --upgrade pip
pip install markdown
python 12DaysAlife.py
python makeAllEditions.py
- name: Deploy
if: github.ref == 'refs/heads/main' # It only runs on main branch (not in a Pull Request)
run: |
git add .
git commit -m 'Generated static html files'
git push -f origin $LOCAL_BRANCH_NAME:$HOSTING_BRANCH_NAME
- name: Teardown when the workflow failed
if: failure() && steps.build_step.outcome == 'failure'
run: |
git stash -u
# for using Python in workflow, see following links:
# - https://docs.github.com/actions/automating-builds-and-tests/building-and-testing-python#using-the-python-starter-workflow
# - https://github.com/actions/setup-python