forked from kamat/blog
fix workflow 3
This commit is contained in:
@@ -8,55 +8,58 @@ on:
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
CF_PAGES_PROJECT: ${{ vars.CF_PAGES_PROJECT }} # 例: blog
|
||||
PROD_BRANCH: "main" # Pages 側の本番ブランチ名
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
CI: "1"
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
# Giteaは絶対URLでの外部Action取得に対応。:contentReference[oaicite:6]{index=6}
|
||||
|
||||
- name: Setup Node for Wrangler
|
||||
uses: https://github.com/actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
|
||||
- name: Install cobalt (prebuilt via eget)
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
apt-get update
|
||||
apt-get install -y ca-certificates curl tar
|
||||
apt-get update && apt-get install -y ca-certificates curl tar git
|
||||
curl -fsSL https://zyedidia.github.io/eget.sh | sh
|
||||
./eget cobalt-org/cobalt.rs --to /usr/local/bin/cobalt
|
||||
cobalt --version
|
||||
# eget はGitHub Releasesから適切な資産を自動選択します。:contentReference[oaicite:1]{index=1}
|
||||
|
||||
- name: Build site with cobalt
|
||||
run: cobalt build
|
||||
# 既定の出力は ./_site。:contentReference[oaicite:8]{index=8}
|
||||
run: cobalt build # 既定出力: ./_site
|
||||
|
||||
- name: Install Wrangler
|
||||
run: npm i -g wrangler@latest
|
||||
|
||||
- name: Compute BRANCH_NAME
|
||||
id: branch
|
||||
- name: Compute BRANCH_NAME and COMMIT metadata
|
||||
id: meta
|
||||
shell: bash
|
||||
run: |
|
||||
bn="${GITHUB_REF_NAME:-${GITEA_REF_NAME:-}}"
|
||||
if [ -z "$bn" ] && [ -n "${GITHUB_REF:-${GITEA_REF:-}}" ]; then
|
||||
ref="${GITHUB_REF:-${GITEA_REF}}"
|
||||
bn="${ref##*/}"
|
||||
fi
|
||||
if [ -z "$bn" ]; then bn="$(git rev-parse --abbrev-ref HEAD)"; fi
|
||||
echo "BRANCH_NAME=$bn" >> "$GITHUB_ENV"
|
||||
echo "COMMIT_SHA=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
|
||||
echo "COMMIT_MSG=$(git log -1 --pretty=%s)" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Ensure Pages project exists (create if missing)
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
test -n "${CF_PAGES_PROJECT}"
|
||||
code=$(curl -sS -o /dev/null -w '%{http_code}' \
|
||||
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
|
||||
"https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/pages/projects/${CF_PAGES_PROJECT}")
|
||||
if [ "$code" != "200" ]; then
|
||||
npx --yes wrangler@latest pages project create "${CF_PAGES_PROJECT}" --production-branch "${PROD_BRANCH}"
|
||||
fi
|
||||
# APIで存在確認 → なければ非対話で作成。:contentReference[oaicite:4]{index=4}
|
||||
|
||||
- name: Deploy to Cloudflare Pages
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
CF_PAGES_PROJECT: ${{ vars.CF_PAGES_PROJECT }}
|
||||
shell: bash
|
||||
run: |
|
||||
test -n "$CF_PAGES_PROJECT"
|
||||
npx wrangler pages deploy "_site" \
|
||||
--project-name "$CF_PAGES_PROJECT" \
|
||||
--account-id "$CLOUDFLARE_ACCOUNT_ID" \
|
||||
--branch "$BRANCH_NAME"
|
||||
# CIでのwrangler deploy手順に準拠。:contentReference[oaicite:9]{index=9}
|
||||
npx --yes wrangler@latest pages deploy "_site" \
|
||||
--project-name "${CF_PAGES_PROJECT}" \
|
||||
--branch "${BRANCH_NAME}" \
|
||||
--commit-hash "${COMMIT_SHA}" \
|
||||
--commit-message "${COMMIT_MSG}"
|
||||
# 公式手順に準拠。ブランチ明示で本番/プレビューを制御。:contentReference[oaicite:5]{index=5}
|
||||
|
||||
Reference in New Issue
Block a user