Skip to content
Draft
Show file tree
Hide file tree
Changes from 9 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
37 changes: 37 additions & 0 deletions .github/scripts/create-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,43 @@ async function createGitHubRelease() {
console.log(`\n🚀 Pushing changes...`);
execSync("git push origin prod", { stdio: "inherit" });
console.log(`✅ Successfully pushed changes`);

// Trigger the deployment workflow via repository_dispatch
console.log(`\n🔔 Triggering deployment workflow...`);
try {
// Validate GITHUB_TOKEN is available
if (!process.env.GITHUB_TOKEN) {
throw new Error(
"GITHUB_TOKEN is required to trigger deployment workflow",
);
}

const dispatchOctokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});

await dispatchOctokit.rest.repos.createDispatchEvent({
owner,
repo,
event_type: "deploy-to-pages",
client_payload: {
source: "release-workflow",
branch: "prod",
},
});
console.log(`✅ Deployment workflow triggered successfully`);
} catch (dispatchError) {
const errorMessage =
dispatchError instanceof Error
? dispatchError.message
: String(dispatchError);
console.warn(
`⚠️ Failed to trigger deployment workflow: ${errorMessage}`,
);
console.log(
"You can manually trigger the deployment from the Actions tab",
);
}
} catch (gitError) {
console.error("❌ Git operation failed:", gitError);
process.exit(1);
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
push:
branches: ["prod"]

# Triggered by repository dispatch event from Release workflow
repository_dispatch:
types: [deploy-to-pages]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

Expand All @@ -30,6 +34,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v6
with:
# Checkout prod branch for repository_dispatch events, otherwise use default
ref: ${{ github.event_name == 'repository_dispatch' && 'prod' || github.ref }}
- name: Setup Node
uses: actions/setup-node@v6
with:
Expand All @@ -46,6 +53,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v6
with:
# Checkout prod branch for repository_dispatch events, otherwise use default
ref: ${{ github.event_name == 'repository_dispatch' && 'prod' || github.ref }}
- name: Detect package manager
id: detect-package-manager
run: |
Expand Down
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,32 @@ npm run dev

## 📦 Build & Deploy

Build for production:
### Production Build (for GitHub Pages)

Build for production deployment:

```bash
npm run build
```

The app is automatically deployed to GitHub Pages on every push to the `main` branch.
This creates an optimized static export in the `out` directory with the `/geo-invaders` base path configured for GitHub Pages.

### Local Testing Build

To build and test the production build locally:

```bash
npm run build:local
npm run start
```

The `build:local` script creates a build without the GitHub Pages base path, making it suitable for local testing at `http://localhost:3000`.

**Note:** Don't use `npm run build` followed by `npm run start` for local testing, as the production build includes the `/geo-invaders` base path and won't work correctly on localhost.

### Deployment

The app is automatically deployed to GitHub Pages on every push to the `prod` branch.

## 🤝 Contributing

Expand Down
Loading