Skip to content

Commit

Permalink
Merge pull request #66 from usuyuki/fix/cloudflare-wra
Browse files Browse the repository at this point in the history
fix cloudflareへのデプロイ
  • Loading branch information
usuyuki authored Mar 28, 2024
2 parents f6e2b7b + 4adb9b4 commit 5147495
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 25 deletions.
92 changes: 68 additions & 24 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,73 @@ jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy

steps:
- uses: actions/checkout@v4
- name: Publish
uses: cloudflare/wrangler-action@v3
- name: Checkout
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- uses: pnpm/action-setup@v3
name: Install pnpm
id: pnpm-install
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
preCommands: |
pnpm install
touch .env
echo "NOTION_API_KEY=${{ secrets.NOTION_API_KEY }}" >> .env
echo "GHOST_API_URL=${{ secrets.GHOST_API_URL }}" >> .env
echo "GHOST_CONTENT_KEY=${{ secrets.GHOST_CONTENT_KEY }}" >> .env
# どうやってもできないのでSEDで書き換える↓
cp wrangler.toml.example wrangler.toml
sed -i -e "s/ACCOUNT_ID/${{ secrets.CF_ACCOUNT_ID }}/" wrangler.toml
sed -i -e "s/KV_ID/${{ secrets.CF_KV_ID }}/" wrangler.toml
command: |
publish
# --config指定しても効かないので注意
# env: |
# NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }}
# GHOST_API_URL: ${{ secrets.GHOST_API_URL }}
# GHOST_CONTENT_KEY: ${{ secrets.GHOST_CONTENT_KEY }}

# 参考:https://developers.cloudflare.com/workers/wrangler/ci-cd/
version: 8
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Generate Env
run: |
echo "NOTION_API_KEY=${{ secrets.NOTION_API_KEY }}" >> .env
echo "GHOST_API_URL=${{ secrets.GHOST_API_URL }}" >> .env
echo "GHOST_CONTENT_KEY=${{ secrets.GHOST_CONTENT_KEY }}" >> .env
- name: Generate wrangler.toml
run: |
cp wrangler.toml.example wrangler.toml
sed -i -e "s/ACCOUNT_ID/${{ secrets.CF_ACCOUNT_ID }}/" wrangler.toml
sed -i -e "s/KV_ID/${{ secrets.CF_KV_ID }}/" wrangler.toml
- name: cloudflare
run: |
pnpm wrangler deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}

# cloudflare/wrangler-actionは最新でも絶妙にバージョンが古くてビルドコケるので自前で全部やる
# - name: Publish
# uses: cloudflare/wrangler-action@v3
# with:
# workingDirectory: .
# apiToken: ${{ secrets.CF_API_TOKEN }}
# accountId: ${{ secrets.CF_ACCOUNT_ID }}
# preCommands: |
# pnpm install
# command: |
# deploy
# # --config指定しても効かないので注意
# # env: |
# # NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }}
# # GHOST_API_URL: ${{ secrets.GHOST_API_URL }}
# # GHOST_CONTENT_KEY: ${{ secrets.GHOST_CONTENT_KEY }}
#
# # 参考:https://developers.cloudflare.com/workers/wrangler/ci-cd/
3 changes: 2 additions & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
</div>
<div class="w-full md:w-4/5 flex items-center flex-wrap justify-center">
{#if data.blogs.length === 0}
<p>ブログの取得に失敗しました...😢</p>
<!-- 本番だけなぜか絶対に取得に失敗する -->
<p>ぜひうすゆきブログも見てみてください!!</p>
{:else}
{#each data.blogs as article}
<a class="md:w-1/3" href={article.link} target="_blank" rel="noopener noreferrer">
Expand Down

0 comments on commit 5147495

Please sign in to comment.