-
Notifications
You must be signed in to change notification settings - Fork 4
147 lines (128 loc) · 5.3 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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: read # to checkout repo
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
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 artifact
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 }}
check_latest_note:
name: Check latest note
runs-on: ubuntu-latest
outputs:
do_post: ${{ steps.mastodon_note_check.outputs.do_post }}
latest_note_id: ${{ steps.mastodon_note_check.outputs.latest_note_id }}
latest_note_path: ${{ steps.mastodon_note_check.outputs.latest_note_path }}
steps:
- name: Checkout code
uses: actions/checkout@v4
# TODO Bail if latest note is draft
- name: Check if latest note is already posted
id: mastodon_note_check
timeout-minutes: 10
run: |
latest="$NOTES_DIR/$(ls -r1 "$NOTES_DIR" | grep -v "_" | head -n 1)"
note_id=$(./script/check-mastodon-note.sh "$latest")
[ -z "$note_id" ] && echo "Latest note $latest is posted. Bail." || echo "Latest note $latest is not posted. Do post."
[ ! -z "$note_id" ] && echo "do_post=true" >> "$GITHUB_OUTPUT"
echo "latest_note_id=$note_id" >> "$GITHUB_OUTPUT"
echo "latest_note_path=$latest" >> "$GITHUB_OUTPUT"
cat "$GITHUB_OUTPUT"
env:
NOTES_DIR: ${{ env.NOTES_DIR }}
post_mastodon:
name: Post to Mastodon
needs: [deploy, check_latest_note] # can't send post with permalink until site is deployed
runs-on: ubuntu-latest
if: needs.check_latest_note.outputs.do_post == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Wait for site to deploy
timeout-minutes: 5
run: ./script/wait-for-status.sh "$LATEST_NOTE_PATH"
env:
LATEST_NOTE_PATH: ${{ needs.check_latest_note.outputs.latest_note_path }}
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: ${{ env.DENO_VERSION }}
- name: Post to Mastodon API
run: deno run --allow-net --allow-read --allow-write --allow-env script/mastodon.ts "$LATEST_NOTE_PATH"
env:
MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }}
LATEST_NOTE_PATH: ${{ needs.check_latest_note.outputs.latest_note_path }}
- name: Write to log
run: |
echo "$LATEST_UNPOSTED" >> $MASTODON_LOG_FILE
cat "$MASTODON_LOG_FILE"
env:
MASTODON_LOG_FILE: ${{ env.MASTODON_LOG_FILE }}
LATEST_UNPOSTED: ${{ needs.check_latest_note.outputs.latest_note_id }}
- 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 $MASTODON_LOG_FILE
timestamp=$(date -u)
git commit -m "Latest post to Mastodon: $timestamp [skip-ci]" || exit 0
git push
env:
MASTODON_LOG_FILE: ${{ env.MASTODON_LOG_FILE }}