Skip to content

Commit

Permalink
Merge pull request #1 from rhino-site/action
Browse files Browse the repository at this point in the history
add push action
  • Loading branch information
rhino-site authored Jan 8, 2025
2 parents 0709782 + f7b9daf commit 6d66543
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/site-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Rebuild and Push Site Changes

permissions:
contents: write
pull-requests: write

on:
workflow_dispatch:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v4
with:
ref: main

- name: Set up SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H "${{ secrets.SSH_IP }}" >> ~/.ssh/known_hosts
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install deps
run: pnpm install

- name: Build
run: pnpm run build

- name: Upload static files
uses: actions/upload-artifact@v4
with:
name: site-build
path: out/

- name: Upload to server
run: |
SSH_LOCATION="${{ secrets.SSH_USER }}@${{ secrets.SSH_IP }}"
if [ -n "${{ secrets.SSH_DIR }}" ]; then
ssh -i ~/.ssh/id_ed25519 "${SSH_LOCATION}" "rm -rf ${{ secrets.SSH_DIR }}/*"
scp -i ~/.ssh/id_ed25519 -rp out/* "${SSH_LOCATION}:${{ secrets.SSH_DIR }}"
else
echo "Error: SSH_DIR not set"
exit 1
fi
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,38 @@ The `pages/api` directory is mapped to `/api/*`. Files in this directory are tre

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Deploying

### Deploy with Vercel
Deploy using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/nextjs-portfolio-starter&project-name=portfolio&repository-name=portfolio)

### Deploy without Vercel

Set the following repository secrets for GitHub Actions:
- generate an ssh keygen pair and set `SSH_USER`, `SSH_IP`, `SSH_DIR`, and `SSH_KEY`:
- `SSH_USER` - the host user
- `SSH_IP` - the IP of the server
- `SSH_DIR` - the desired directory to copy to
- `SSH_KEY` - the contents of the generated `site_build_key` file:
```bash
# generate key
ssh-keygen -t ed25519 -C "github-actions@site-build" -f site_build_key < /dev/null

# allow key to login to user
mkdir -p ~/.ssh
cat site_build_key.pub >> ~/.ssh/authorized_keys

# print key result to set SSH_KEY - DO NOT SHARE!!
cat site_build_key
```

- The workflow will run:
- On any changes to the `main` branch
- Manually on dispatch
- For security, it will always checkout from `main`, even if requesting dispatch on an alternate branch

## Learn More

To learn more about Next.js, take a look at the following resources:
Expand Down
4 changes: 4 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
images: {
unoptimized: true,
},
reactStrictMode: true,
async redirects() {
return [
Expand Down

0 comments on commit 6d66543

Please sign in to comment.