From 883a8767fe030129972b3779d2314c578917799f Mon Sep 17 00:00:00 2001 From: x-wei Date: Sat, 17 Oct 2020 19:32:56 +0200 Subject: [PATCH] update entrypoint.sh - Remove duplicated lines to add locales - Run different commands for local docker and gh-actions --- Dockerfile | 14 +++---------- entrypoint.sh | 58 ++++++++++++++++++++++++--------------------------- 2 files changed, 30 insertions(+), 42 deletions(-) diff --git a/Dockerfile b/Dockerfile index 88dc4f6..a5d57a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 . @@ -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 && \ @@ -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"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index b186290..1cece93 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 ===================' \ No newline at end of file