More Deno conf for zed #444
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 and deploy | |
on: | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
push: | |
paths: | |
- 'src/**/*' | |
- '_config.ts' | |
- 'CNAME' | |
- '.rebuild' | |
- '.github/workflows/deploy.yml' | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: write # to checkout repo and write back log file | |
pages: write # to deploy to Pages | |
id-token: write # to verify the deployment originates from an appropriate source | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: 'pages' | |
cancel-in-progress: false | |
env: | |
DENO_VERSION: v1.42.4 | |
BUILD_FOLDER: build | |
MASTODON_LOG_FILE: .mastodon-notes | |
MASTODON_TODO: .mastodon-todo.json | |
NOTES_DIR: src/notes | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Deno | |
uses: denoland/setup-deno@v1 | |
with: | |
deno-version: ${{ env.DENO_VERSION }} | |
- name: Build site | |
run: deno task build | |
env: | |
NODE_ENV: production | |
ENV: production | |
- name: Upload site | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: ${{ env.BUILD_FOLDER }} | |
deploy: | |
name: Deploy | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.ref_name == 'main' | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
- name: Purge Cloudflare cache | |
uses: jakejarvis/cloudflare-purge-action@master | |
env: | |
CLOUDFLARE_ZONE: ${{ secrets.CLOUDFLARE_ZONE }} | |
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }} | |
# This task exists just so we can short circuit and quit early in post_mastodon | |
check_latest_note: | |
name: Check Mastodon todo | |
runs-on: ubuntu-latest | |
outputs: | |
do_post: ${{ steps.todo_file.outputs.do_post }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Check if we have something to do | |
id: todo_file | |
timeout-minutes: 10 | |
run: | | |
[ -f "$file" ] && echo "do_post=true" >> "$GITHUB_OUTPUT" | |
env: | |
file: ${{ env.MASTODON_TODO }} | |
post_mastodon: | |
name: Post to Mastodon | |
# can't send post with permalink until site is deployed | |
needs: [deploy, check_latest_note] | |
runs-on: ubuntu-latest | |
# If nothing to do, we can just skip this whole task | |
if: needs.check_latest_note.outputs.do_post == 'true' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Deno | |
uses: denoland/setup-deno@v1 | |
with: | |
deno-version: ${{ env.DENO_VERSION }} | |
- name: Wait for site to deploy | |
timeout-minutes: 5 | |
run: ./script/wait-for-status.sh --latest | |
- name: Post to Mastodon API | |
run: deno run --allow-net --allow-read --allow-env script/post-mastodon.ts | |
env: | |
MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }} | |
- name: Write to log and clear todo | |
run: | | |
id=$(cat $todo_file | jq -r ".id") | |
echo $id >> $log_file | |
cat $log_file | |
rm -rf $todo_file | |
echo "$todo_file cleared" | |
env: | |
todo_file: ${{ env.MASTODON_TODO }} | |
log_file: ${{ env.MASTODON_LOG_FILE }} | |
- name: Commit and push posted notes | |
# Pull first, since something could've been pushed in-between. | |
run: | | |
git pull | |
git config user.name "Automated" | |
git config user.email "[email protected]" | |
git add $log_file | |
timestamp=$(date -u) | |
git commit -m "Latest post to Mastodon: $timestamp [skip-ci]" || exit 0 | |
git push | |
env: | |
log_file: ${{ env.MASTODON_LOG_FILE }} |