try using env instead of output #821
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: | ||
check-post: | ||
name: Check latest post date | ||
if: github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
outputs: | ||
ANNOUNCE: ${{ steps.check_date.outputs.ANNOUNCE }} | ||
POST: ${{ steps.check_post.outputs.POST }} | ||
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_ENV | ||
# extract date | ||
date=$(grep "^date:" "${latest_post}" | sed 's/^date: //' | sed 's/["'\'']//g') | ||
echo "POST_DATE=${date}" >> $GITHUB_ENV | ||
- name: Check post date | ||
id: check_date | ||
run: | | ||
post_date=$(date -d "${{ env.POST_DATE }}" +%Y%m%d) | ||
two_days_ago=$(date -d "-4 days" +%Y%m%d) | ||
echo "ANNOUNCE=false" >> $GITHUB_ENV | ||
if (( post_date > two_days_ago )); then | ||
echo "Post date is within the last 2 days" | ||
echo "ANNOUNCE=true" >> $GITHUB_ENV | ||
fi | ||
# Does the post need a DOI? | ||
echo "DOI=true" > $GITHUB_OUTPUT | ||
if head -n 10 "${{ env.POST }}" | grep -q "doi:"; then | ||
echo "DOI=false" > $GITHUB_OUTPUT | ||
fi | ||
build: | ||
name: Build site | ||
runs-on: ubuntu-latest | ||
needs: check-post | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
RENV_PROFILE: zenodo | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: true | ||
- name: Install cURL Headers | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install libcurl4-openssl-dev | ||
- name: Get software versions | ||
id: version | ||
run: | | ||
ver=$(cat .Rprofile | grep hugo.version | cut -d'"' -f2 ) | ||
echo ".Rprofile sets hugo version to $ver" | ||
echo "hugo_v=${ver}" >> $GITHUB_ENV | ||
nalias=$(echo ${{ github.head_ref }} | sed 's/_/-/g') | ||
echo "nalias=${nalias}" >> $GITHUB_ENV | ||
rver=$(cat renv.lock | jq '.R.Version' | tr -d '"') | ||
echo "rver=${rver}" >> $GITHUB_ENV | ||
- name: Install pdf svg handler | ||
if: github.ref == 'refs/heads/main' && needs.check-post.outputs.DOI == 'true' | ||
run: sudo apt-get install librsvg2-dev | ||
- name: Setup R | ||
if: github.ref == 'refs/heads/main' && needs.check-post.outputs.DOI == 'true' | ||
uses: r-lib/actions/setup-r@v2 | ||
with: | ||
r-version: ${{ env.rver }} | ||
- name: Setup renv | ||
if: github.ref == 'refs/heads/main' && needs.check-post.outputs.DOI == 'true' | ||
uses: r-lib/actions/setup-renv@v2 | ||
- name: Setuo Quarto | ||
if: github.ref == 'refs/heads/main' && needs.check-post.outputs.DOI == 'true' | ||
uses: quarto-dev/quarto-actions/setup@v2 | ||
- name: Setup Tinytex | ||
if: github.ref == 'refs/heads/main' && needs.check-post.outputs.DOI == 'true' | ||
uses: r-lib/actions/setup-tinytex@v2 | ||
- name: Add doi | ||
if: github.ref == 'refs/heads/main' && needs.check-post.outputs.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 | ||
if: env.ANNOUNCE == 'true' | ||
Check failure on line 173 in .github/workflows/build-site.yaml GitHub Actions / Update websiteInvalid workflow file
|
||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
RENV_PROFILE: social_media | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup R | ||
uses: r-lib/actions/setup-r@v2 | ||
with: | ||
r-version: ${{ env.rver }} | ||
- name: Setup renv | ||
uses: r-lib/actions/setup-renv@v2 | ||
- name: Announce the post | ||
env: | ||
RTOOT_DEFAULT_TOKEN: ${{ secrets.RTOOT_TOKEN }} | ||
BLUESKY_APP_PASS: ${{ secrets.BLUESKY_PWD }} | ||
KIT_SECRET: ${{ secrets.KIT_KEY }} | ||
run: | | ||
Rscript .github/scripts/announce.R ${{ env.POST }} | ||