Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni committed Mar 29, 2024
1 parent 4b37167 commit 37af73d
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/example-deploys.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Deploy Examples

on:
workflow_dispatch:
push:
branches:
- main
merge_group:
pull_request:
paths-ignore:
- "**/*.md"
- ".github/ISSUE_TEMPLATE/**"

# Automatically cancel older in-progress jobs on the same branch
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash

env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
FORCE_COLOR: true
ASTRO_TELEMETRY_DISABLED: true
# 7 GiB by default on GitHub, setting to 6 GiB
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
NODE_OPTIONS: --max-old-space-size=6144

jobs:
cloudflare:
name: 'Deploy "${{ matrix.example }}" to Cloudflare'
runs-on: ubuntu-latest
timeout-minutes: 3
strategy:
matrix:
example:
- sitemap-ext
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PNPM
uses: pnpm/action-setup@v2

- name: Setup Node
uses: actions/setup-node@main
with:
node-version: 20
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- uses: schnerring/cloudflare-pages-branch-alias-action@v1
id: pages-branch-alias
with:
# git-branch input
git-branch: ${{ github.ref_name }}

- name: Build to Cloudflare
run: ./examples/deploy-cloudflare.sh ${{ matrix.example }}
env:
DEPLOY_SITE: "https://${{ steps.pages-branch-alias.outputs.branch-alias }}.inox-tools-ex-${{ matrix.example }}.pages.dev"

- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: inox-tools-ex-${{ matrix.example }}
directory: dist
# Optional: Enable this if you want to have GitHub Deployments triggered
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
# Optional: Change the working directory
workingDirectory: examples/${{ matrix.example }}
38 changes: 38 additions & 0 deletions examples/deploy-cloudflare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

###########################################
# Build an Astro Site to Cloudflare Pages #
###########################################

set -exo pipefail

PROJECT_NAME=$1

# Get the script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

# Check that the project exists
if [ ! -d "$PROJECT_NAME" ]; then
echo "Project $PROJECT_NAME does not exist" >&2
exit 1
fi

cd "$PROJECT_NAME"

# Check that the project is an Astro project
if ! jq -e '.dependencies | has("astro")' package.json >/dev/null; then
echo "Project $PROJECT_NAME is not an Astro project" >&2
exit 1
fi

# Extract Node package name from package.json
PACKAGE_NAME=$(jq -r '.name' package.json)

# Configure the Astro project to deploy to Cloudflare Pages
pnpm astro add cloudflare --yes

# Build the project
pnpm -w turbo run --filter "$PACKAGE_NAME" build

# Restore the Astro project to its original state
git restore package.json astro.config.*

0 comments on commit 37af73d

Please sign in to comment.