Skip to content
This repository was archived by the owner on Aug 10, 2024. It is now read-only.

Commit 9a4bdbf

Browse files
committed
Initial commit.
0 parents  commit 9a4bdbf

35 files changed

+3460
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: 1. Check Requirements
2+
run-name: Check Requirements
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
8+
env:
9+
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
10+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
11+
CLOUDFLARE_WORKER_NAME: ${{ vars.CLOUDFLARE_WORKER_NAME }}
12+
BLUESKY_HANDLE: ${{ vars.BLUESKY_HANDLE }}
13+
BLUESKY_APP_PASSWORD: ${{ secrets.BLUESKY_APP_PASSWORD }}
14+
15+
jobs:
16+
check_cloudflare_api_token:
17+
runs-on: ubuntu-latest
18+
name: Has Secret CLOUDFLARE_API_TOKEN
19+
steps:
20+
- run: |
21+
if [ -n "${CLOUDFLARE_API_TOKEN}" ]; then
22+
echo "Verifying CLOUDFLARE_API_TOKEN secret..."
23+
curl -f -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
24+
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
25+
-H "Content-Type:application/json"
26+
echo "Done"
27+
else
28+
echo "The CLOUDFLARE_API_TOKEN secret needs to be set."
29+
echo "Create a new token here: https://dash.cloudflare.com/profile/api-tokens"
30+
exit 1
31+
fi
32+
check_cloudflare_worker_name:
33+
runs-on: ubuntu-latest
34+
name: Has Variable CLOUDFLARE_WORKER_NAME
35+
steps:
36+
- run: |
37+
if [ -n "${CLOUDFLARE_WORKER_NAME}" ]; then
38+
echo "CLOUDFLARE_WORKER_NAME is set."
39+
else
40+
echo "The CLOUDFLARE_WORKER_NAME variable needs to be set."
41+
echo "Go to this repository's Settings > Secrets and variables > Variables."
42+
exit 1
43+
fi
44+
check_cloudflare_account_id:
45+
runs-on: ubuntu-latest
46+
name: Has Variable CLOUDFLARE_ACCOUNT_ID
47+
steps:
48+
- run: |
49+
if [ -n "${CLOUDFLARE_ACCOUNT_ID}" ]; then
50+
echo "CLOUDFLARE_ACCOUNT_ID is set."
51+
else
52+
echo "The CLOUDFLARE_ACCOUNT_ID variable needs to be set."
53+
echo "Go to this repository's Settings > Secrets and variables > Variables."
54+
exit 1
55+
fi
56+
check_bluesky_handle:
57+
runs-on: ubuntu-latest
58+
name: Has Variable BLUESKY_HANDLE
59+
steps:
60+
- run: |
61+
if [ -n "${BLUESKY_HANDLE}" ]; then
62+
echo "BLUESKY_HANDLE is set."
63+
else
64+
echo "The BLUESKY_HANDLE variable needs to be set."
65+
echo "Go to this repository's Settings > Secrets and variables > Variables."
66+
exit 1
67+
fi
68+
check_bluesky_app_password:
69+
runs-on: ubuntu-latest
70+
name: Has Secret BLUESKY_APP_PASSWORD
71+
steps:
72+
- run: |
73+
if [ -n "${BLUESKY_APP_PASSWORD}" ]; then
74+
echo "BLUESKY_APP_PASSWORD is set."
75+
else
76+
echo "The BLUESKY_APP_PASSWORD variable needs to be set."
77+
echo "Go to this repository's Settings > Secrets and variables > Variables."
78+
exit 1
79+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 2. Deploy to Cloudflare
2+
run-name: Deploy to Cloudflare
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
8+
env:
9+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
10+
CLOUDFLARE_WORKER_NAME: ${{ vars.CLOUDFLARE_WORKER_NAME }}
11+
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
12+
13+
jobs:
14+
deploy_cloudflare_worker:
15+
runs-on: ubuntu-latest
16+
name: Deploy Cloudflare Worker
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Render Config
20+
run: |
21+
python render-config.py
22+
- name: Deploy Cloudflare Worker
23+
uses: cloudflare/wrangler-action@2.0.0
24+
with:
25+
apiToken: ${{ env.CLOUDFLARE_API_TOKEN }}
26+
command: |
27+
deploy cloudflare-worker/worker.js --compatibility-date 2023-05-30 --name ${{ env.CLOUDFLARE_WORKER_NAME }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: 3. Publish Feed Generator
2+
run-name: Publish Feed Generator
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
8+
env:
9+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
10+
CLOUDFLARE_WORKER_NAME: ${{ vars.CLOUDFLARE_WORKER_NAME }}
11+
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
12+
BLUESKY_HANDLE: ${{ vars.BLUESKY_HANDLE }}
13+
BLUESKY_APP_PASSWORD: ${{ secrets.BLUESKY_APP_PASSWORD }}
14+
15+
jobs:
16+
publish_feed_generator:
17+
runs-on: ubuntu-latest
18+
name: Publish Feed
19+
steps:
20+
- name: Get Cloudflare Worker Subdomain
21+
run: |
22+
set -o pipefail;
23+
tmp=$(mktemp);
24+
curl -f \
25+
--request GET \
26+
--url "https://api.cloudflare.com/client/v4/accounts/${{ env.CLOUDFLARE_ACCOUNT_ID }}/workers/subdomain" \
27+
--header 'Content-Type: application/json' \
28+
--header 'Authorization: Bearer ${{ env.CLOUDFLARE_API_TOKEN }}' \
29+
| jq -r '.result.subdomain' > $tmp
30+
export CLOUDFLARE_WORKERS_SUBDOMAIN="$(cat $tmp)"
31+
echo "FEEDGEN_HOSTNAME=${CLOUDFLARE_WORKER_NAME}.${CLOUDFLARE_WORKERS_SUBDOMAIN}.workers.dev" >> "$GITHUB_ENV"
32+
- uses: actions/checkout@v3
33+
- name: Render Config
34+
run: |
35+
python render-config.py
36+
- uses: actions/setup-node@v3
37+
- name: Publish Feed Generator
38+
run: |
39+
cd feed-generator/
40+
npm install
41+
env | grep -E 'FEEDGEN'
42+
yarn publishFeedGenerator

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

CONFIG.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
# recordName
3+
4+
emotional-support-pets
5+
6+
# displayName
7+
8+
Emotional Support Pets
9+
10+
# description
11+
12+
Cute animals feed
13+
14+
# searchTerms
15+
16+
- cats
17+
- dogs
18+
- penguins
19+
- red pandas
20+
- quokkas
21+
22+
# avatar
23+
24+
![](avatar.png)

INSTALL.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Full Installation Guide
2+
3+
⚠️ 70% complete - WORK IN PROGRESS ⚠️
4+
5+
## Steps
6+
7+
### 1. Fork this repository
8+
9+
1. Log into GitHub.
10+
11+
2. Navigate to the [main Contrails page](https://github.com/jcsalterego/contrails) and click the Fork button.
12+
13+
![](docs/github-fork.png)
14+
15+
3. Proceed with instructions until your GitHub user has a fork of Contrails.
16+
17+
### 2. Create Cloudflare API Token
18+
19+
_These instructions are an excerpt from [Running Wrangler in CI/CD](https://developers.cloudflare.com/workers/wrangler/ci-cd/)._
20+
21+
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/).
22+
At the top-right, navigate to [My Profile](https://dash.cloudflare.com/profile), and then [API Tokens](https://dash.cloudflare.com/profile/api-tokens). Click on **Create Token**.
23+
24+
2. Select **Use template** next to **Edit Cloudflare Workers**.
25+
26+
![](docs/cloudflare-api-tokens-edit-cloudflare-workers.png)
27+
28+
3. Set the Account Resources. If this Cloudflare account is only for this project, you can choose "All accounts" and "All zones."
29+
30+
![](docs/cloudflare-api-tokens-edit-cloudflare-workers-all-accounts-all-zones.png)
31+
32+
4. Click on **Continue to summary**.
33+
34+
![](docs/cloudflare-api-tokens-continue-to-summary.png)
35+
36+
5. Click on **Create Token**.
37+
38+
![](docs/cloudflare-api-tokens-summary.png)
39+
40+
6. Copy and save the token, as you will need it in the next step.
41+
42+
![](docs/cloudflare-api-tokens-final.png)
43+
44+
### 3. Save Cloudflare API Token to Repository Secrets
45+
46+
In your GitHub repository, go to `Settings > Secrets and variables > Actions`.
47+
48+
![](docs/github-settings-secrets.png)
49+
50+
Click on **New repository secret**, and add `CLOUDFLARE_API_TOKEN`.
51+
52+
![](docs/github-settings-secrets-cloudflare-api-token.png)
53+
54+
### 4. Create Cloudflare Application
55+
56+
1. Go to `Cloudflare Dashboard > Workers & Pages`.
57+
58+
![](docs/cloudflare-workers.png)
59+
60+
2. Click on **Create Application**.
61+
62+
![](docs/cloudflare-create-an-application.png)
63+
64+
![](docs/cloudflare-create-hello-world-script.png)
65+
66+
Click Deploy
67+
68+
3. set `CLOUDFLARE_WORKER_NAME`
69+
70+
![](docs/github-settings-variables-set-cloudflare-worker-name.png)
71+
72+
4. set CLOUDFLARE_ACCOUNT_ID
73+
74+
![](docs/cloudflare-workers-account-id.png)
75+
76+
![](docs/github-settings-variables-set-cloudflare-account-id.png)
77+

LICENSE

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Copyright 2023 Jerry Chen. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above
11+
copyright notice, this list of conditions and the following
12+
disclaimer in the documentation and/or other materials provided
13+
with the distribution.
14+
15+
THIS SOFTWARE IS PROVIDED BY JERRY CHEN ``AS IS'' AND ANY EXPRESS OR
16+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL JERRY CHEN OR CONTRIBUTORS BE LIABLE FOR
19+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
The views and conclusions contained in the software and documentation
28+
are those of the authors and should not be interpreted as representing
29+
official policies, either expressed or implied, of Jerry Chen.

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
# Contrails
3+
4+
Contrails is an [ATProto Feed Generator](https://github.com/bluesky-social/feed-generator) backed by
5+
[Cloudflare Workers](https://workers.cloudflare.com) and Bluesky Search.
6+
7+
Edit `CONFIG.md` to define your feed generator.
8+
9+
Deploy right from [GitHub Actions](https://github.com/features/actions).
10+
11+
## A Post
12+
13+
![](docs/thecloud.png)
14+
15+
## Requirements
16+
17+
- Bluesky Social account
18+
- GitHub account ([Sign up](https://github.com/signup) or [Login](https://github.com/login))
19+
- Cloudflare account ([Sign up](https://dash.cloudflare.com/sign-up) or [Login](https://dash.cloudflare.com/login/))
20+
- A moderate-to-high tolerance for adventure
21+
22+
## Installation & Configuration: The Short Version
23+
24+
1. Create a Cloudflare Worker
25+
2. Create a Cloudflare API Token (the Edit Workers template is fine)
26+
3. Create a Bluesky App Password
27+
4. Fork this repository
28+
5. Set the following in your fork:
29+
* Variables: `BLUESKY_HANDLE`, `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_WORKER_NAME`
30+
* Secrets: `BLUESKY_APP_PASSWORD`, `CLOUDFLARE_API_TOKEN`
31+
6. Edit [CONFIG.md](CONFIG.md) in your fork
32+
7. Run **Check Requirements** GitHub Action in your fork
33+
8. Run **Deploy to Cloudflare** GitHub Action in your fork
34+
9. Run **Publish Feed Generator** GitHub Action in your fork
35+
36+
## Installation & Configuration: Director's Cut
37+
38+
[INSTALL.md](INSTALL.md) `under-construction.gif`
39+
40+
## LICENSE
41+
42+
[2-Clause BSD](LICENSE)

avatar.png

201 KB
Loading

0 commit comments

Comments
 (0)