删除 GitHub Actions 设置邮件接收步骤
This commit is contained in:
68
.github/workflows/deploy-cloudflare.yml
vendored
68
.github/workflows/deploy-cloudflare.yml
vendored
@@ -89,7 +89,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$CUSTOM_DOMAIN" ]; then
|
if [ -z "$CUSTOM_DOMAIN" ]; then
|
||||||
echo "::error:: CUSTOM_DOMAIN variable is not set."
|
echo "::warning:: CUSTOM_DOMAIN variable is not set."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CONFIG_FILE="wrangler-action.toml"
|
CONFIG_FILE="wrangler-action.toml"
|
||||||
@@ -132,9 +132,18 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "🔍 Checking if the database exists..."
|
echo "🔍 Checking if the database exists..."
|
||||||
KV_LIST=$(pnpm wrangler kv namespace list)
|
|
||||||
|
|
||||||
if echo "$KV_LIST" | jq -e ".[] | select(.title == \"$NAME\")" > /dev/null; then
|
set +e
|
||||||
|
KV_LIST=$(pnpm wrangler kv namespace list 2>&1)
|
||||||
|
STATUS=$?
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ $STATUS -ne 0 ]; then
|
||||||
|
echo "$KV_LIST"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if echo "$KV_LIST" | jq -e ".[] | select(.title == \"$NAME\")" >/dev/null; then
|
||||||
echo "✅ Database $NAME already exists."
|
echo "✅ Database $NAME already exists."
|
||||||
KV_ID=$(echo "$KV_LIST" | jq -r ".[] | select(.title == \"$NAME\") | .id")
|
KV_ID=$(echo "$KV_LIST" | jq -r ".[] | select(.title == \"$NAME\") | .id")
|
||||||
echo "KV_NAMESPACE_ID: $KV_ID"
|
echo "KV_NAMESPACE_ID: $KV_ID"
|
||||||
@@ -161,9 +170,18 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "🔍 Checking if the database exists..."
|
echo "🔍 Checking if the database exists..."
|
||||||
DB_LIST=$(pnpm wrangler d1 list --json)
|
|
||||||
|
|
||||||
if echo "$DB_LIST" | jq -e ".[] | select(.name == \"$NAME\")" > /dev/null; then
|
set +e
|
||||||
|
DB_LIST=$(pnpm wrangler d1 list --json 2>&1)
|
||||||
|
STATUS=$?
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ $STATUS -ne 0 ]; then
|
||||||
|
echo "$DB_LIST"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if echo "$DB_LIST" | jq -e ".[] | select(.name == \"$NAME\")" >/dev/null; then
|
||||||
echo "✅ Database $NAME already exists."
|
echo "✅ Database $NAME already exists."
|
||||||
D1_ID=$(echo "$DB_LIST" | jq -r ".[] | select(.name == \"$NAME\") | .uuid")
|
D1_ID=$(echo "$DB_LIST" | jq -r ".[] | select(.name == \"$NAME\") | .uuid")
|
||||||
echo "D1_DATABASE_ID: $D1_ID"
|
echo "D1_DATABASE_ID: $D1_ID"
|
||||||
@@ -182,7 +200,17 @@ jobs:
|
|||||||
working-directory: ./mail-worker
|
working-directory: ./mail-worker
|
||||||
run: |
|
run: |
|
||||||
echo "🚀 Starting deployment..."
|
echo "🚀 Starting deployment..."
|
||||||
pnpm wrangler deploy -c wrangler-action.toml | tee deploy.log | grep -v "https://.*\.workers\.dev" || true
|
pnpm wrangler deploy -c wrangler-action.toml 2>&1 \
|
||||||
|
| tee deploy.log \
|
||||||
|
| grep -v "https://.*\.workers\.dev" \
|
||||||
|
| sed -E 's/env\.domain .*/env.domain (***)/' \
|
||||||
|
|| true
|
||||||
|
|
||||||
|
DEPLOY_EXIT_CODE=${PIPESTATUS[0]}
|
||||||
|
if [ $DEPLOY_EXIT_CODE -ne 0 ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
WORKER_URL=$(grep -o "https://.*\.workers\.dev" deploy.log || echo "")
|
WORKER_URL=$(grep -o "https://.*\.workers\.dev" deploy.log || echo "")
|
||||||
|
|
||||||
if [ -n "$WORKER_URL" ]; then
|
if [ -n "$WORKER_URL" ]; then
|
||||||
@@ -215,34 +243,6 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: 📮 设置邮件接收 / Set up email receiving
|
|
||||||
run: |
|
|
||||||
|
|
||||||
echo "🛠️ Starting email receiving setup..."
|
|
||||||
|
|
||||||
WORKER_URL="${CUSTOM_DOMAIN:+https://$CUSTOM_DOMAIN}"
|
|
||||||
WORKER_URL="${WORKER_URL:-${{ steps.deploy.outputs.worker_url }}}"
|
|
||||||
|
|
||||||
HTTP_CODE=$(curl -sL --post301 --post302 --post303 -w "%{http_code}" -o response.txt \
|
|
||||||
-X POST \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"domainList\": $DOMAIN,\"accountId\":\"$CLOUDFLARE_ACCOUNT_ID\",\"token\":\"$CLOUDFLARE_API_TOKEN\",\"workerName\":\"$NAME\"}" \
|
|
||||||
"$WORKER_URL/api/initForward")
|
|
||||||
|
|
||||||
RESPONSE_BODY=$(cat response.txt)
|
|
||||||
|
|
||||||
if [ "$RESPONSE_BODY" = "success" ]; then
|
|
||||||
echo "✅ Setup completed."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$HTTP_CODE" = "200" ] && [ "$RESPONSE_BODY" != "success" ]; then
|
|
||||||
echo "::error:: Email receiving setup failed: $RESPONSE_BODY"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "::error:: Email receiving setup failed: $HTTP_CODE $RESPONSE_BODY"
|
|
||||||
|
|
||||||
- name: 🗑️ 删除运行记录 / Delete workflow runs
|
- name: 🗑️ 删除运行记录 / Delete workflow runs
|
||||||
uses: GitRML/delete-workflow-runs@main
|
uses: GitRML/delete-workflow-runs@main
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ const addForm = reactive({
|
|||||||
})
|
})
|
||||||
let skeletonRows = 10
|
let skeletonRows = 10
|
||||||
const queryParams = {
|
const queryParams = {
|
||||||
size: 10
|
size: 30
|
||||||
}
|
}
|
||||||
|
|
||||||
const mySelect = ref()
|
const mySelect = ref()
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
import app from '../hono/hono';
|
import app from '../hono/hono';
|
||||||
import { dbInit } from '../init/init';
|
import { dbInit } from '../init/init';
|
||||||
import { initForward } from "../init/forward";
|
|
||||||
|
|
||||||
app.get('/init/:secret', (c) => {
|
app.get('/init/:secret', (c) => {
|
||||||
return dbInit.init(c);
|
return dbInit.init(c);
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('/initForward', async (c) => {
|
|
||||||
return initForward(c, await c.req.json());
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,124 +0,0 @@
|
|||||||
export async function initForward(c, params) {
|
|
||||||
|
|
||||||
const { workerName, domainList, token } = params;
|
|
||||||
|
|
||||||
let headers = {
|
|
||||||
Authorization: `Bearer ${token}`
|
|
||||||
};
|
|
||||||
|
|
||||||
let mainList = [];
|
|
||||||
const childList = [];
|
|
||||||
|
|
||||||
//查询DOMAIN变量对应域名
|
|
||||||
for (let domain of domainList) {
|
|
||||||
|
|
||||||
// 提取一级域名(主域名 + 顶级域名)
|
|
||||||
const parts = domain.split('.');
|
|
||||||
|
|
||||||
let paramDomain = domain
|
|
||||||
if (parts.length > 2) {
|
|
||||||
paramDomain = parts.slice(-2).join('.');
|
|
||||||
}
|
|
||||||
|
|
||||||
//结尾匹配查询域名
|
|
||||||
const res = await fetch(`https://api.cloudflare.com/client/v4/zones?name=ends_with:${paramDomain}`, {
|
|
||||||
method: 'GET',
|
|
||||||
headers
|
|
||||||
});
|
|
||||||
|
|
||||||
const body = await res.json();
|
|
||||||
|
|
||||||
if(!res.ok) {
|
|
||||||
return c.json(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { result } = body;
|
|
||||||
|
|
||||||
result.forEach(item => {
|
|
||||||
|
|
||||||
if (domain === item.name) {
|
|
||||||
mainList.push({ domain: item.name, domainId: item.id });
|
|
||||||
} else if (domain.includes(item.name)) {
|
|
||||||
mainList.push({ domain: item.name, domainId: item.id });
|
|
||||||
childList.push({ domain, domainId: item.id });
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
mainList = [...new Set(mainList)];
|
|
||||||
|
|
||||||
if (mainList.length === 0) {
|
|
||||||
return c.text('DOMAIN does not exist in Cloudflare.');
|
|
||||||
}
|
|
||||||
|
|
||||||
//开启主域名电子邮件路由
|
|
||||||
for (const { domainId } of mainList) {
|
|
||||||
|
|
||||||
const res = await fetch(`https://api.cloudflare.com/client/v4/zones/${domainId}/email/routing/enable`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers
|
|
||||||
});
|
|
||||||
|
|
||||||
const body = await res.json();
|
|
||||||
const error = body.errors[0];
|
|
||||||
if(!res.ok) {
|
|
||||||
return c.text(`${error.code} ${error.message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//开启catch_all转发到worker
|
|
||||||
for (const { domainId } of mainList) {
|
|
||||||
|
|
||||||
const res = await fetch(`https://api.cloudflare.com/client/v4/zones/${domainId}/email/routing/rules/catch_all`, {
|
|
||||||
method: 'PUT',
|
|
||||||
headers,
|
|
||||||
body: JSON.stringify({
|
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
type: "worker",
|
|
||||||
value: [workerName]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
matchers: [
|
|
||||||
{
|
|
||||||
type: "all"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
enabled: true
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
const body = await res.json();
|
|
||||||
const error = body.errors[0];
|
|
||||||
if(!res.ok) {
|
|
||||||
return c.text(`${error.code} ${error.message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//开启子域名电子邮件路由
|
|
||||||
for (const { domain, domainId } of childList) {
|
|
||||||
|
|
||||||
const res = await fetch(`https://api.cloudflare.com/client/v4/zones/${domainId}/email/routing/enable`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers,
|
|
||||||
body: JSON.stringify({
|
|
||||||
name: domain
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
const body = await res.json();
|
|
||||||
const error = body.errors[0];
|
|
||||||
if(!res.ok) {
|
|
||||||
return c.text(`${error.code} ${error.message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.text('success');
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user