Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 60 additions & 5 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: CD

on:
workflow_run:
# Deploy runs after CI on push to dev/main only; the branches filter keeps
# fork/PR heads out of this privileged context.
workflow_run: # zizmor: ignore[dangerous-triggers]
workflows: ['CI']
types: [completed]
branches: [dev, main]
Expand All @@ -13,10 +15,15 @@ jobs:
github.event.workflow_run.event == 'push' &&
!github.event.repository.is_template
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
environment: ${{ github.event.workflow_run.head_branch == 'main' && 'production' || 'development' }}
concurrency:
group: deploy-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: ${{ github.event.workflow_run.head_branch != 'main' }}
env:
SCRIPT_PROPERTIES: ${{ secrets.SCRIPT_PROPERTIES }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -33,16 +40,64 @@ jobs:
env:
DEPLOY_ENV: ${{ github.event.workflow_run.head_branch == 'main' && 'production' || 'development' }}

# Secret Manager mode: direct WIF (no service-account impersonation).
# Requires org variables GCP_WIF_PROVIDER + CLASPRC_SECRET (docs/secret-manager.md).
- name: Authenticate to Google Cloud (WIF)
if: vars.GCP_WIF_PROVIDER != ''
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0
with:
workload_identity_provider: ${{ vars.GCP_WIF_PROVIDER }}

- name: Fetch clasp credentials from Secret Manager
if: vars.GCP_WIF_PROVIDER != ''
id: gcp-secrets
uses: google-github-actions/get-secretmanager-secrets@bc9c54b29fdffb8a47776820a7d26e77b379d262 # v3.0.0
with:
secrets: |-
clasprc:${{ vars.CLASPRC_SECRET }}

- name: Setup clasp credentials
env:
WIF_ENABLED: ${{ vars.GCP_WIF_PROVIDER != '' }}
CLASPRC_GCP: ${{ steps.gcp-secrets.outputs.clasprc }}
CLASPRC_LEGACY: ${{ secrets.CLASPRC_JSON }}
CLASP_JSON: ${{ secrets.CLASP_JSON }}
run: |
echo '${{ secrets.CLASPRC_JSON }}' > ~/.clasprc.json
echo '${{ secrets.CLASP_JSON }}' > .clasp.json
if [ "$WIF_ENABLED" = "true" ]; then
# Secret Manager mode: never fall back to the legacy secret silently.
CLASPRC="$CLASPRC_GCP"
if [ -z "$CLASPRC" ]; then
echo "::error::GCP_WIF_PROVIDER is set but Secret Manager returned an empty payload. Check CLASPRC_SECRET and the secret's latest version."
exit 1
fi
else
CLASPRC="$CLASPRC_LEGACY"
if [ -z "$CLASPRC" ]; then
echo "::error::No clasp credentials. Set org variables GCP_WIF_PROVIDER + CLASPRC_SECRET (Secret Manager), or org secret CLASPRC_JSON (legacy)."
exit 1
fi
fi
if [ -z "$CLASP_JSON" ]; then
echo "::error::CLASP_JSON secret is not set for this environment."
exit 1
fi
umask 077
printf '%s' "$CLASPRC" > ~/.clasprc.json
printf '%s' "$CLASP_JSON" > .clasp.json

- name: Push to GAS
- name: Push to Apps Script
run: pnpm exec clasp push -f

- name: Deploy new version
run: pnpm exec clasp deploy -i "${{ vars.DEPLOYMENT_ID }}" --description "CD deploy from ${{ github.event.workflow_run.head_branch }}@${{ github.event.workflow_run.head_sha }}"
env:
DEPLOYMENT_ID: ${{ vars.DEPLOYMENT_ID }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: pnpm exec clasp deploy -i "$DEPLOYMENT_ID" --description "CD deploy from ${HEAD_BRANCH}@${HEAD_SHA}"

- name: Set script properties
if: vars.GCP_PROJECT_NUMBER != '' && env.SCRIPT_PROPERTIES != ''
run: ./scripts/set-properties.sh --env SCRIPT_PROPERTIES

- name: Post-deploy hook
if: always() && hashFiles('.github/hooks/post-deploy.sh') != ''
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
pull_request:
branches: [main]

permissions:
contents: read

jobs:
check:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -62,3 +65,6 @@ jobs:

actionlint:
uses: h13/.github/.github/workflows/ci-actionlint.yml@c807de1510e8d223f352555ddcbf6a1a78fe51eb # v3.1.0

zizmor:
uses: h13/.github/.github/workflows/ci-zizmor.yml@c807de1510e8d223f352555ddcbf6a1a78fe51eb # v3.1.0
4 changes: 3 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
tags:
- v*

# publish-node needs contents: write (GitHub Release) and id-token: write
# (npm OIDC trusted publishing). It takes no secrets.
permissions:
contents: write
id-token: write

jobs:
publish:
uses: h13/.github/.github/workflows/publish-node.yml@1e41d76a661e2835b0cf9df2c85d588f9f0308f7 # v3.0.0
secrets: inherit