Skip to content

Commit

Permalink
update entrypoint.sh
Browse files Browse the repository at this point in the history
- Remove duplicated lines to add locales
- Run different commands for local docker and gh-actions
  • Loading branch information
X-Wei committed Oct 17, 2020
1 parent e4e4678 commit 883a876
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 42 deletions.
14 changes: 3 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LABEL "com.github.actions.icon"="home"
LABEL "com.github.actions.color"="red"

LABEL "Name"="Pelican for X-Wei's blog"
LABEL "Version"="0.0.1"
LABEL "Version"="0.0.3"

COPY requirements.txt .

Expand Down Expand Up @@ -38,7 +38,7 @@ RUN git clone --depth 1 https://github.com/farseerfc/opencc-bin opencc-bin && \
cd .. && \
opencc --version

# Add locale
# Add locales
# Copied from https://stackoverflow.com/a/38553499
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
Expand All @@ -52,12 +52,4 @@ RUN locale-gen zh_CN.UTF-8 && \

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

# Build blog.
# RUN mkdir -p /home/blog && cd /home/blog

# Now we can build the blog.
# RUN git clone --depth=1 --branch=master https://github.com/X-Wei/x-wei.github.com.git pelican-blog && \
# cd pelican-blog/pelican_dir && \
# make html # serve / publish
ENTRYPOINT ["/entrypoint.sh"]
58 changes: 27 additions & 31 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,33 @@
# exit when any command fails
set -e

echo "REPO: $GITHUB_REPOSITORY"
echo "ACTOR: $GITHUB_ACTOR"
if [ -z "$GITHUB_ACTOR" ]
then
# If running locally: generate html to "pelican_dir/output/" for preview.
mkdir -p /home/blog && cd /home/blog
cd pelican_dir && make html && cd ..
else
# If running on Github Actions: make html and commit to $remote_branch.
echo "REPO: $GITHUB_REPOSITORY"
echo "ACTOR: $GITHUB_ACTOR"

echo '=================== Setting locale ==================='
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
echo '=================== Building blog ==================='
cd pelican_dir && make publish && cd ..

locale-gen zh_CN.UTF-8 && \
locale-gen zh_HK.UTF-8 && \
locale-gen en_US.UTF-8 && \
locale-gen ja_JP.UTF-8 && \
locale -a

echo '=================== Building blog ==================='
cd pelican_dir && make publish && cd ..


echo '=================== Publish to GitHub Pages ==================='
remote_repo="https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
remote_branch=${GH_PAGES_BRANCH:=gh-pages}
git init
git remote add deploy "$remote_repo"
git checkout $remote_branch || git checkout --orphan $remote_branch
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add .
echo -n 'Files to Commit:' && ls -l | wc -l
timestamp=$(date +%s%3N)
git commit -m "[ci skip] Automated deployment to GitHub Pages on $timestamp"
git push deploy $remote_branch --force
rm -fr .git
cd ../
echo '=================== Publish to GitHub Pages ==================='
remote_repo="https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
remote_branch=${GH_PAGES_BRANCH:=gh-pages}
git init
git remote add deploy "$remote_repo"
git checkout $remote_branch || git checkout --orphan $remote_branch
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add .
echo -n 'Files to Commit:' && ls -l | wc -l
timestamp=$(date +%s%3N)
git commit -m "[ci skip] Automated deployment to GitHub Pages on $timestamp"
git push deploy $remote_branch --force
rm -fr .git
cd ../
fi
echo '=================== Done ==================='

0 comments on commit 883a876

Please sign in to comment.