forked from kamat/blog
fix workflow 3
This commit is contained in:
@@ -8,55 +8,58 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build-and-deploy:
|
build-and-deploy:
|
||||||
runs-on: ubuntu-latest
|
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:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: https://github.com/actions/checkout@v4
|
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)
|
- name: Install cobalt (prebuilt via eget)
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
apt-get update
|
apt-get update && apt-get install -y ca-certificates curl tar git
|
||||||
apt-get install -y ca-certificates curl tar
|
|
||||||
curl -fsSL https://zyedidia.github.io/eget.sh | sh
|
curl -fsSL https://zyedidia.github.io/eget.sh | sh
|
||||||
./eget cobalt-org/cobalt.rs --to /usr/local/bin/cobalt
|
./eget cobalt-org/cobalt.rs --to /usr/local/bin/cobalt
|
||||||
cobalt --version
|
cobalt --version
|
||||||
# eget はGitHub Releasesから適切な資産を自動選択します。:contentReference[oaicite:1]{index=1}
|
|
||||||
|
|
||||||
- name: Build site with cobalt
|
- name: Build site with cobalt
|
||||||
run: cobalt build
|
run: cobalt build # 既定出力: ./_site
|
||||||
# 既定の出力は ./_site。:contentReference[oaicite:8]{index=8}
|
|
||||||
|
|
||||||
- name: Install Wrangler
|
- name: Compute BRANCH_NAME and COMMIT metadata
|
||||||
run: npm i -g wrangler@latest
|
id: meta
|
||||||
|
|
||||||
- name: Compute BRANCH_NAME
|
|
||||||
id: branch
|
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
bn="${GITHUB_REF_NAME:-${GITEA_REF_NAME:-}}"
|
bn="${GITHUB_REF_NAME:-${GITEA_REF_NAME:-}}"
|
||||||
if [ -z "$bn" ] && [ -n "${GITHUB_REF:-${GITEA_REF:-}}" ]; then
|
if [ -z "$bn" ]; then bn="$(git rev-parse --abbrev-ref HEAD)"; fi
|
||||||
ref="${GITHUB_REF:-${GITEA_REF}}"
|
|
||||||
bn="${ref##*/}"
|
|
||||||
fi
|
|
||||||
echo "BRANCH_NAME=$bn" >> "$GITHUB_ENV"
|
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
|
- name: Deploy to Cloudflare Pages
|
||||||
env:
|
shell: bash
|
||||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
||||||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
||||||
CF_PAGES_PROJECT: ${{ vars.CF_PAGES_PROJECT }}
|
|
||||||
run: |
|
run: |
|
||||||
test -n "$CF_PAGES_PROJECT"
|
npx --yes wrangler@latest pages deploy "_site" \
|
||||||
npx wrangler pages deploy "_site" \
|
--project-name "${CF_PAGES_PROJECT}" \
|
||||||
--project-name "$CF_PAGES_PROJECT" \
|
--branch "${BRANCH_NAME}" \
|
||||||
--account-id "$CLOUDFLARE_ACCOUNT_ID" \
|
--commit-hash "${COMMIT_SHA}" \
|
||||||
--branch "$BRANCH_NAME"
|
--commit-message "${COMMIT_MSG}"
|
||||||
# CIでのwrangler deploy手順に準拠。:contentReference[oaicite:9]{index=9}
|
# 公式手順に準拠。ブランチ明示で本番/プレビューを制御。:contentReference[oaicite:5]{index=5}
|
||||||
|
|||||||
Reference in New Issue
Block a user