forked from towfiqi/serpbear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aea6137
commit f51b9fb
Showing
1 changed file
with
187 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
repository_dispatch: | ||
|
||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v18 | ||
with: | ||
node-version: 18.x | ||
- name: Use Node.js 18.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: 'npm' | ||
- run: name: Deploy | ||
- name: Use Node.js 18.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: 'npm' | ||
|
||
# Automatically get an account id via the API Token | ||
# if secrets.CLOUDFLARE_ACCOUNT_ID is not set. | ||
- name: Fetch Account ID | ||
id: fetch_account_id | ||
run: | | ||
if [[ -n "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}" ]]; then | ||
ACCOUNT_ID="${{ secrets.CLOUDFLARE_ACCOUNT_ID }}" | ||
echo "Using provided CLOUDFLARE_ACCOUNT_ID from secrets." | ||
else | ||
ACCOUNT_ID=$(curl -X GET "https://api.cloudflare.com/client/v4/accounts" -H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" -H "Content-Type:application/json" | jq ".result[0].id" -r) | ||
if [[ "$ACCOUNT_ID" == "null" ]]; then | ||
echo "Failed to get an account id, please make sure you have set up CLOUDFLARE_API_TOKEN correctly!" | ||
exit 1 | ||
fi | ||
fi | ||
echo 'account_id='$ACCOUNT_ID >> $GITHUB_OUTPUT | ||
env: | ||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
|
||
- name: Install packages | ||
run: | | ||
npm install | ||
cd worker | ||
npm install | ||
- name: Build worker | ||
run: | | ||
cd worker | ||
npx wrangler deploy src/index.ts --outdir dist --dry-run | ||
- name: Build page | ||
run: | | ||
npx @cloudflare/next-on-pages | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v18 | ||
with: | ||
node-version: 18 | ||
- run: npm install | ||
- run: next build | ||
env: | ||
NODE_ENV: production | ||
- name: Publish | ||
uses: cloudflare/wrangler-action@1.3.0 | ||
with: | ||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
preCommands: | | ||
wrangler kv:namespace create KV_STATUS_PAGE || true | ||
export KV_NAMESPACE_ID=$(npx @cloudflare/wrangler@1 kv:namespace list 2> >(tee stderr.log >&2) | head -1 | node -pe "JSON.parse(fs.readFileSync('/dev/stdin').toString()).find(kv => kv.title.includes('KV_STATUS_PAGE')).id") | ||
echo "[env.production]" >> wrangler.toml | ||
echo "kv_namespaces = [{binding=\"KV_STATUS_PAGE\", id=\"${KV_NAMESPACE_ID}\"}]" >> wrangler.toml | ||
postCommands: | | ||
npm kv-gc | ||
secrets: | ||
environment: production | ||
env: | ||
CF_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
|
||
- run: next build | ||
env: | ||
NODE_ENV: production | ||
- name: Publish | ||
uses: cloudflare/wrangler-action@1.3.0 | ||
with: | ||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
preCommands: | | ||
wrangler kv:namespace create KV_STATUS_PAGE || true | ||
export KV_NAMESPACE_ID=$(npx @cloudflare/wrangler@1 kv:namespace list 2> >(tee stderr.log >&2) | head -1 | node -pe "JSON.parse(fs.readFileSync('/dev/stdin').toString()).find(kv => kv.title.includes('KV_STATUS_PAGE')).id") | ||
echo "[env.production]" >> wrangler.toml | ||
echo "kv_namespaces = [{binding=\"KV_STATUS_PAGE\", id=\"${KV_NAMESPACE_ID}\"}]" >> wrangler.toml | ||
yarn kv-gc | ||
secrets: | ||
environment: production | ||
env: | ||
CF_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
|
||
|
||
|
||
name: Deploy to Cloudflare | ||
|
||
on: | ||
push: | ||
branches: ['main'] | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Terraform | ||
uses: hashicorp/setup-terraform@v2.0.3 | ||
with: | ||
terraform_version: 1.6.4 | ||
|
||
- name: Use Node.js 18.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: 'npm' | ||
|
||
# Automatically get an account id via the API Token | ||
# if secrets.CLOUDFLARE_ACCOUNT_ID is not set. | ||
- name: Fetch Account ID | ||
id: fetch_account_id | ||
run: | | ||
if [[ -n "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}" ]]; then | ||
ACCOUNT_ID="${{ secrets.CLOUDFLARE_ACCOUNT_ID }}" | ||
echo "Using provided CLOUDFLARE_ACCOUNT_ID from secrets." | ||
else | ||
ACCOUNT_ID=$(curl -X GET "https://api.cloudflare.com/client/v4/accounts" -H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" -H "Content-Type:application/json" | jq ".result[0].id" -r) | ||
if [[ "$ACCOUNT_ID" == "null" ]]; then | ||
echo "Failed to get an account id, please make sure you have set up CLOUDFLARE_API_TOKEN correctly!" | ||
exit 1 | ||
fi | ||
fi | ||
echo 'account_id='$ACCOUNT_ID >> $GITHUB_OUTPUT | ||
env: | ||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
|
||
- name: Install packages | ||
run: | | ||
npm install | ||
cd worker | ||
npm install | ||
- name: Build worker | ||
run: | | ||
cd worker | ||
npx wrangler deploy src/index.ts --outdir dist --dry-run | ||
- name: Build page | ||
run: | | ||
npx @cloudflare/next-on-pages | ||
- name: Upload worker | ||
run: | | ||
curl --fail-with-body -X PUT https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/workers/scripts/uptimeflare_worker/content --header 'Authorization: Bearer '$CLOUDFLARE_API_TOKEN -F 'index.js=@worker/dist/index.js;type=application/javascript+module' -F 'metadata={"main_module": "index.js"}' | ||
env: | ||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
CLOUDFLARE_ACCOUNT_ID: ${{ steps.fetch_account_id.outputs.account_id }} | ||
|
||
- name: Upload pages | ||
run: | | ||
npx wrangler pages deploy .vercel/output/static --project-name serpbear | ||
env: | ||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
CLOUDFLARE_ACCOUNT_ID: ${{ steps.fetch_account_id.outputs.account_id }} |