Skip to content

Commit 1aec6f7

Browse files
committed
πŸ”§ Fix GitHub Pages deployment permissions
πŸ› Fixed Issues: - Added required permissions for actions/deploy-pages@v4 - Added id-token: write permission for OIDC token generation - Added concurrency control for deployment jobs - Fixed ACTIONS_ID_TOKEN_REQUEST_URL error πŸ”§ Changes Made: - Added permissions block to deploy.yml - Added concurrency control for branch-specific deployments - Created test-deploy.yml for testing deployment setup - Added PAGES_SETUP.md with complete setup instructions πŸ“‹ Required Permissions: - contents: read (read repository contents) - pages: write (deploy to GitHub Pages) - id-token: write (generate OIDC tokens) πŸ§ͺ Testing: - Created test-deploy.yml for safe testing - Added environment-specific deployment - Added verification steps πŸ“š Documentation: - Complete GitHub Pages setup guide - Troubleshooting common issues - Security considerations - Monitoring instructions
1 parent c8af01c commit 1aec6f7

3 files changed

Lines changed: 232 additions & 0 deletions

File tree

β€Ž.github/PAGES_SETUP.mdβ€Ž

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# πŸš€ GitHub Pages Setup Guide
2+
3+
## πŸ”§ **Required Setup Steps**
4+
5+
### **1. Enable GitHub Pages**
6+
1. Go to your repository **Settings**
7+
2. Navigate to **Pages** section
8+
3. Under **Source**, select **"GitHub Actions"**
9+
4. Save the settings
10+
11+
### **2. Create Deployment Environments**
12+
13+
#### **Production Environment:**
14+
1. Go to **Settings** β†’ **Environments**
15+
2. Click **"New environment"**
16+
3. Name: `github-pages`
17+
4. Click **"Configure environment"**
18+
5. Add protection rules if needed:
19+
- βœ… **Required reviewers** (optional)
20+
- βœ… **Wait timer** (optional)
21+
6. Click **"Save protection rules"**
22+
23+
#### **Staging Environment:**
24+
1. Go to **Settings** β†’ **Environments**
25+
2. Click **"New environment"**
26+
3. Name: `github-pages-staging`
27+
4. Click **"Configure environment"**
28+
5. Add protection rules if needed
29+
6. Click **"Save protection rules"**
30+
31+
### **3. Verify Permissions**
32+
Ensure your repository has the following permissions:
33+
- βœ… **Actions** enabled
34+
- βœ… **Pages** enabled
35+
- βœ… **Contents** read access
36+
- βœ… **Metadata** read access
37+
38+
## πŸ§ͺ **Test Deployment**
39+
40+
### **Run Test Workflow:**
41+
```bash
42+
# Test staging deployment
43+
gh workflow run test-deploy.yml -f test_environment=staging
44+
45+
# Test production deployment
46+
gh workflow run test-deploy.yml -f test_environment=production
47+
```
48+
49+
### **Check Deployment Status:**
50+
```bash
51+
# View workflow runs
52+
gh run list --workflow=test-deploy.yml
53+
54+
# View specific run
55+
gh run view <run-id> --log
56+
```
57+
58+
## πŸ” **Troubleshooting**
59+
60+
### **Common Issues:**
61+
62+
#### **1. "Unable to get ACTIONS_ID_TOKEN_REQUEST_URL"**
63+
**Solution:** Ensure the workflow has the correct permissions:
64+
```yaml
65+
permissions:
66+
contents: read
67+
pages: write
68+
id-token: write
69+
```
70+
71+
#### **2. "Environment not found"**
72+
**Solution:** Create the required environments:
73+
- `github-pages` (for production)
74+
- `github-pages-staging` (for staging)
75+
76+
#### **3. "Pages build failed"**
77+
**Solution:** Check the build output and ensure:
78+
- All required files are present
79+
- No build errors
80+
- Proper file structure
81+
82+
#### **4. "Permission denied"**
83+
**Solution:** Verify repository settings:
84+
- Actions are enabled
85+
- Pages are enabled
86+
- Correct source is selected
87+
88+
## πŸ“‹ **Deployment Workflow**
89+
90+
### **Automatic Deployment:**
91+
- **Push to `main`** β†’ Deploys to production
92+
- **Push to `next`** β†’ Deploys to staging
93+
- **Manual trigger** β†’ Choose environment
94+
95+
### **Manual Deployment:**
96+
```bash
97+
# Deploy to production
98+
gh workflow run deploy.yml -f environment=production
99+
100+
# Deploy to staging
101+
gh workflow run deploy.yml -f environment=staging
102+
```
103+
104+
## πŸ”’ **Security Considerations**
105+
106+
### **Environment Protection:**
107+
- **Production:** Consider adding required reviewers
108+
- **Staging:** Can be auto-deployed
109+
- **Secrets:** Store in environment-specific secrets if needed
110+
111+
### **Branch Protection:**
112+
- Require pull request reviews
113+
- Require status checks
114+
- Require up-to-date branches
115+
116+
## πŸ“Š **Monitoring**
117+
118+
### **Check Deployment Status:**
119+
1. Go to **Actions** tab
120+
2. Find your deployment workflow
121+
3. Check the logs for any errors
122+
4. Verify the deployment URL
123+
124+
### **View Deployed Site:**
125+
- **Production:** `https://khalilcharfi.github.io`
126+
- **Staging:** `https://khalilcharfi.github.io` (next branch)
127+
128+
## 🎯 **Next Steps**
129+
130+
1. βœ… **Enable GitHub Pages** in repository settings
131+
2. βœ… **Create environments** (github-pages, github-pages-staging)
132+
3. βœ… **Test deployment** using test-deploy.yml
133+
4. βœ… **Verify permissions** are correct
134+
5. βœ… **Run main deployment** workflow
135+
136+
---
137+
138+
*Follow these steps to set up GitHub Pages deployment* πŸš€
139+
*Last updated: $(date)*

β€Ž.github/workflows/deploy.ymlβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ on:
1212
type: choice
1313
options: [production, staging]
1414

15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
20+
concurrency:
21+
group: "pages-${{ github.ref_name }}"
22+
cancel-in-progress: false
23+
1524
env:
1625
NODE_VERSION: '22'
1726
ULTRA_LIGHT: true
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: πŸ§ͺ Test Deploy
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
test_environment:
7+
description: 'Test environment'
8+
required: true
9+
default: 'staging'
10+
type: choice
11+
options: [staging, production]
12+
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
concurrency:
19+
group: "test-pages-${{ github.ref_name }}"
20+
cancel-in-progress: false
21+
22+
env:
23+
NODE_VERSION: '22'
24+
25+
jobs:
26+
test-deploy:
27+
name: πŸ§ͺ Test Deployment
28+
runs-on: ubuntu-latest
29+
environment:
30+
name: ${{ inputs.test_environment == 'production' && 'github-pages' || 'github-pages-staging' }}
31+
32+
steps:
33+
- name: ⚑ Checkout
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 1
37+
38+
- name: ⚑ Setup Node.js
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: ${{ env.NODE_VERSION }}
42+
cache: 'npm'
43+
44+
- name: ⚑ Install dependencies
45+
run: npm ci --prefer-offline --no-audit --no-fund --silent
46+
47+
- name: ⚑ Build project
48+
run: npm run build:prod
49+
env:
50+
NODE_ENV: production
51+
52+
- name: ⚑ Create test page
53+
run: |
54+
echo "<!DOCTYPE html>
55+
<html>
56+
<head>
57+
<title>Test Deploy - $(date)</title>
58+
<meta charset='utf-8'>
59+
</head>
60+
<body>
61+
<h1>πŸš€ Test Deployment Successful!</h1>
62+
<p>Environment: ${{ inputs.test_environment }}</p>
63+
<p>Branch: ${{ github.ref_name }}</p>
64+
<p>Commit: ${{ github.sha }}</p>
65+
<p>Time: $(date -u)</p>
66+
<p>This is a test deployment to verify GitHub Pages setup.</p>
67+
</body>
68+
</html>" > dist/index.html
69+
70+
- name: ⚑ Upload artifact
71+
uses: actions/upload-pages-artifact@v3
72+
with:
73+
path: './dist'
74+
75+
- name: ⚑ Deploy to GitHub Pages
76+
id: deployment
77+
uses: actions/deploy-pages@v4
78+
79+
- name: ⚑ Verify deployment
80+
run: |
81+
echo "πŸš€ Test deployment completed!"
82+
echo "Environment: ${{ inputs.test_environment }}"
83+
echo "URL: ${{ steps.deployment.outputs.page_url }}"
84+
echo "βœ… GitHub Pages deployment test successful!"

0 commit comments

Comments
Β (0)