Update website #859
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
on: | |
workflow_dispatch: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
name: Update website | |
jobs: | |
checks: | |
name: Set-up build params | |
if: github.ref == 'refs/heads/main' | |
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 }} | |
RVER: ${{ steps.check-rver.outputs.RVER }} | |
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) | |
echo "ANNOUNCE=false" >> $GITHUB_OUTPUT | |
if (( ${post_date} < ${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 | |
- name: Get R versions | |
id: check-rver | |
run: | | |
rver=$(cat renv.lock | jq '.R.Version' | tr -d '"') | |
echo "RVER=${rver}" >> $GITHUB_OUTPUT | |
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 "RVER: ${{ needs.checks.outputs.RVER }}" | |
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 | |
echo ${{ env.RUN_DOI }} | |
- name: Install cURL Headers | |
run: | | |
sudo apt-get update | |
sudo apt-get install libcurl4-openssl-dev | |
- name: Install pdf svg handler | |
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: ${{ needs.checks.outputs.RVER }} | |
- name: Setup renv | |
if: ${{ env.RUN_DOI == 'true' }} | |
uses: r-lib/actions/setup-renv@v2 | |
- name: Setuo 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: 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 | |
hugo -e production | |
else | |
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/)' | |
}) | |
- name: Commit content with doi | |
if: github.ref == 'refs/heads/main' | |
run: | | |
git commit content/blog -m 'Add doi' || echo "No changes to commit" | |
git push origin || echo "No changes to commit" | |
announce: | |
name: Announce new blog post | |
runs-on: ubuntu-latest | |
needs: [build, checks] | |
if: needs.checks.outputs.ANNOUNCE == 'true' | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
RENV_PROFILE: social_media | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install cURL Headers | |
run: | | |
sudo apt-get update | |
sudo apt-get install libcurl4-openssl-dev | |
- name: Setup R | |
uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: ${{ needs.checks.outputs.RVER }} | |
- name: Setup renv | |
uses: r-lib/actions/setup-renv@v2 | |
- name: Announce the post | |
env: | |
BLUESKY_APP_PASS: ${{ secrets.BLUESKY_PWD }} | |
run: | | |
echo RTOOT_DEFAULT_TOKEN="${{ secrets.RTOOT_TOKEN }}" >> .Renviron | |
echo KIT_SECRET="${{ secrets.KIT_KEY }}" >> .Renviron | |
Rscript .github/scripts/announce.R ${{ needs.checks.outputs.POST }} | |