Update website #1028
This file contains hidden or 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
on: | |
workflow_dispatch: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
name: Update website | |
jobs: | |
checks: | |
name: Set-up build params | |
runs-on: ubuntu-latest | |
outputs: | |
POST: ${{ steps.check-post.outputs.POST }} | |
POST_DATE: ${{ steps.check-date.outputs.POST_DATE }} | |
ANNOUNCE: ${{ steps.check-date.outputs.ANNOUNCE }} | |
DOI: ${{ steps.check-doi.outputs.DOI }} | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: 📝 Get latest blog post 📝 | |
id: check-post | |
env: | |
BLOG_PATH: "content/blog" | |
run: | | |
# Find the latest blog post | |
latest_post=$(find "${BLOG_PATH}" | grep /index.md$ | grep -v "XX-XX" | sort | tail -n1) | |
echo "POST=${latest_post}" >> $GITHUB_OUTPUT | |
- name: Check post date | |
id: check-date | |
run: | | |
post_date=$(grep "^date:" "${{ steps.check-post.outputs.POST }}" | sed 's/^date: //' | sed 's/["'\'']//g') | |
echo "POST_DATE=${post_date}" >> $GITHUB_OUTPUT | |
one_day_ago=$(date -d "-1 days" +%Y%m%d) | |
post_date=$(date -d "${post_date}" +%Y%m%d) | |
echo "ANNOUNCE=false" >> $GITHUB_OUTPUT | |
if [ "${post_date}" -gt "${one_day_ago}" ]; then | |
echo "ANNOUNCE=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Check if needs DOI | |
id: check-doi | |
run: | | |
# Does the post need a DOI? | |
echo "DOI=true" >> $GITHUB_OUTPUT | |
if head -n 10 "${{ steps.check-post.outputs.POST }}" | grep -q "doi:"; then | |
echo "DOI=false" >> $GITHUB_OUTPUT | |
fi | |
check-output: | |
name: check github output | |
runs-on: ubuntu-latest | |
needs: checks | |
steps: | |
- name: Debug Outputs | |
run: | | |
echo "ANNOUNCE: ${{ needs.checks.outputs.ANNOUNCE }}" | |
echo "DOI: ${{ needs.checks.outputs.DOI }}" | |
echo "POST: ${{ needs.checks.outputs.POST }}" | |
echo "POST_DATE: ${{ needs.checks.outputs.POST_DATE }}" | |
build: | |
name: Build site | |
runs-on: ubuntu-latest | |
needs: checks | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
RENV_PROFILE: zenodo | |
RUN_DOI: ${{ github.ref == 'refs/heads/main' && needs.checks.outputs.DOI == 'true' }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Setup variables | |
id: version | |
run: | | |
ver=$(cat .Rprofile | grep hugo.version | cut -d'"' -f2 ) | |
echo "hugo_v=${ver}" >> $GITHUB_ENV | |
nalias=$(echo ${{ github.head_ref }} | sed 's/_/-/g') | |
echo "nalias=${nalias}" >> $GITHUB_ENV | |
- name: Install cURL Headers | |
run: | | |
sudo apt-get update | |
sudo apt-get install libcurl4-openssl-dev | |
- name: Install pdf svg imageMagick | |
if: ${{ env.RUN_DOI == 'true' }} | |
run: sudo apt-get install librsvg2-dev | |
- name: Setup R | |
if: ${{ env.RUN_DOI == 'true' }} | |
uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: "renv" | |
- name: Setup renv | |
if: ${{ env.RUN_DOI == 'true' }} | |
uses: r-lib/actions/setup-renv@v2 | |
- name: Setup Quarto | |
if: ${{ env.RUN_DOI == 'true' }} | |
uses: quarto-dev/quarto-actions/setup@v2 | |
- name: Setup Tinytex | |
if: ${{ env.RUN_DOI == 'true' }} | |
uses: r-lib/actions/setup-tinytex@v2 | |
- name: Add doi | |
if: ${{ env.RUN_DOI == 'true' }} | |
env: | |
ZENODO_API_TOKEN: ${{ secrets.ZENODO_API_TOKEN }} | |
run: | | |
Rscript -e 'renv::restore()' | |
Rscript .github/scripts/add_doi.R | |
- name: Commit content with doi | |
if: github.ref == 'refs/heads/main' | |
run: | | |
git config --local user.email "actions@github.com" | |
git config --local user.name "GitHub Actions" | |
git commit content/blog -m 'Add doi' || echo "No changes to commit" | |
git push origin || echo "No changes to commit" | |
- name: Setup Hugo | |
uses: peaceiris/actions-hugo@v2 | |
with: | |
hugo-version: ${{ env.hugo_v }} | |
extended: true | |
- name: Build | |
run: | | |
if [[ '${{github.ref}}' == 'refs/heads/main' ]]; then | |
echo 'Building production' | |
hugo -e production | |
else | |
echo 'Building preview' | |
hugo \ | |
--buildDrafts \ | |
--buildFuture \ | |
-b https://${{ env.nalias }}--drmowinckels.netlify.app/ | |
fi | |
- name: Deploy production 🚀 | |
if: github.ref == 'refs/heads/main' | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
branch: gh-pages | |
folder: public | |
- name: Deploy to Netlify | |
id: netlify | |
if: github.event_name == 'pull_request' | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
run: | | |
npm install netlify-cli -g | |
netlify deploy --alias ${{ env.nalias }} | |
shell: sh | |
- uses: actions/github-script@v7 | |
if: steps.netlify.outcome == 'success' | |
name: "Notify about build preview" | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
await github.rest.issues.createComment({ | |
issue_number: ${{ github.event.pull_request.number }}, | |
owner: 'drmowinckels', | |
repo: 'drmowinckels.github.io', | |
body: ':tada: The preview is built! [Check it out :eyes:](https://${{ env.nalias }}--drmowinckels.netlify.app/)' | |
}) | |
announce: | |
name: Announce new blog post | |
runs-on: ubuntu-latest | |
needs: [build, checks] | |
if: needs.checks.outputs.ANNOUNCE == 'true' && github.ref == 'refs/heads/main' | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
RENV_PROFILE: social_media | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install lib deps | |
run: | | |
sudo apt-get update | |
sudo apt-get install libcurl4-openssl-dev libmagick++-dev | |
- name: Setup R | |
uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: "renv" | |
- name: Setup renv | |
uses: r-lib/actions/setup-renv@v2 | |
- name: Announce the post | |
env: | |
BLUESKY_APP_PASS: ${{ secrets.BLUESKY_PWD }} | |
BLUESKY_APP_USER: "drmowinckels.io" | |
run: | | |
echo RTOOT_DEFAULT_TOKEN="${{ secrets.RTOOT_TOKEN }}" >> .Renviron | |
echo KIT_SECRET="${{ secrets.KIT_KEY }}" >> .Renviron | |
echo LI_TOKEN="${{ secrets.LI_TOKEN }}" >> .Renviron | |
echo SHORTIO="${{ secrets.SHORTIO }}" >> .Renviron | |
Rscript .github/scripts/announce.R ${{ needs.checks.outputs.POST }} |