Update NBIS slides for friday #202
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
name: build | |
on: | |
push: | |
branches: | |
- master | |
- main | |
env: | |
REGISTRY: ghcr.io | |
ORG: nbisweden | |
IMAGE: workshop-ngsintro:latest | |
jobs: | |
quarto-render-job: | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: write | |
steps: | |
- name: Set time zone | |
uses: szenius/set-timezone@v1.0 | |
with: | |
timezoneLinux: "Europe/Stockholm" | |
timezoneMacos: "Europe/Stockholm" | |
timezoneWindows: "W. Europe Standard Time" | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Pull image | |
run: docker pull ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE }} | |
- name: Define variables | |
run: | | |
echo "PATH_REPO=$(pwd)" >> $GITHUB_ENV | |
echo "PATH_EXPORT=$(grep -E 'output-dir' _quarto.yml | xargs | sed 's/output-dir://' | xargs)" >> $GITHUB_ENV | |
echo "REPO=$(basename ${GITHUB_REPOSITORY})" >> $GITHUB_ENV | |
- name: Check docker and variables | |
run: | | |
docker run --rm -u $(id -u ${USER}):$(id -g ${USER}) -v ${PWD}:/qmd ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE }} Rscript -e "print('R in docker works!')" | |
echo "GITHUB_ACTOR: ${GITHUB_ACTOR}" | |
echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" | |
echo "REPO: ${REPO}" | |
echo "env.PATH_REPO: ${{ env.PATH_REPO }}" | |
echo "PATH_EXPORT: ${PATH_EXPORT}" | |
echo "GITHUB_REPOSITORY_OWNER: ${GITHUB_REPOSITORY_OWNER}" | |
echo "---------------------------------------------------------------------------------------------" | |
echo "Folder contents at $(pwd):" | |
ls -lh | |
echo "---------------------------------------------------------------------------------------------" | |
printenv | |
sed --version | |
- name: Render site, pull repo, copy folder, create index, push repo | |
run: | | |
# Add git info | |
git config --global user.email "do_not_email@example.com" | |
git config --global user.name "gh_action" | |
# Render website | |
echo "Rendering qmd files ..." | |
echo "PWD: ${PWD}" | |
ls -l . | |
docker run --rm -u $(id -u ${USER}):$(id -g ${USER}) -v ${PWD}:/qmd ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE }} | |
# List folder contents | |
echo "Folder contents at $(pwd):" | |
ls -lh | |
echo "Folder contents at ${PATH_REPO}/${PATH_EXPORT}:" | |
ls -lh ${PATH_REPO}/${PATH_EXPORT} | |
# Clone gh-pages branch and remove old directories with same name | |
git clone --depth 1 --single-branch --branch gh-pages "https://${{ secrets.TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" tmprepo | |
cd tmprepo | |
if [ -d ${PATH_EXPORT} ]; then | |
echo "Directory ${PATH_EXPORT} already exists. Removing the directory." | |
git rm -r ${PATH_EXPORT} | |
git commit -m "Old directory ${PATH_EXPORT} deleted." | |
fi | |
cd ${PATH_REPO} | |
cp -r ${PATH_EXPORT} tmprepo/ | |
cd tmprepo | |
echo "Folder contents at $(pwd):" | |
ls -lh | |
# create index file | |
printf "<div class='wrapper-logo'><img class='logo' src='assets/logo.svg'></div>" > index.md | |
printf "The current and all previous instances of this workshop are listed below.\n" >> index.md | |
printf "<hr>\n" >> index.md | |
printf "<div class='workshop-list'>\n" >> index.md | |
dirs=$(ls -d [0-9]*[0-9]/ | sed 's/\///' | tac) | |
for i in ${dirs[@]} | |
do | |
if [ ${i:2:2} -lt 1 ] || [ ${i:2:2} -gt 12 ] | |
then echo "Month: ${i:2:2}. Last 2 values in output_dir must be a month between 01 and 12." | |
fi | |
# This code works for year 2000 and later | |
printf -v thedate '2000-01-01 +%s years +%s months -1 day' "${i:0:2}" "${i:2}" | |
dt=$(date -d "$thedate" +'%Y %b') | |
echo $dt | |
printf "<h3><a href='https://${GITHUB_REPOSITORY_OWNER}.github.io/${REPO}/${i}/'>$dt</a></h3>" >> index.md | |
done | |
printf "</div>\n" >> index.md | |
# printf "<hr>\n" >> index.md | |
# printf "$(date +'%Y') • NBIS\n" >> index.md | |
echo "Folder contents at $(pwd):" | |
ls -lh | |
# Push changes back | |
git add . | |
git commit -m "Updated contents at $(date +%Y%m%d-%H%M%S)" | |
git push origin |