Skip to content

Commit 691bfcd

Browse files
committed
done
1 parent 0541d61 commit 691bfcd

File tree

7 files changed

+373
-9
lines changed

7 files changed

+373
-9
lines changed

.github/workflows/deploy.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,20 @@ jobs:
2121
- name: Add server to known hosts
2222
run: |
2323
mkdir -p ~/.ssh
24-
ssh-keyscan -H profullstack >> ~/.ssh/known_hosts
24+
ssh-keyscan -H profullstack.com >> ~/.ssh/known_hosts
2525
2626
- name: Install dependencies
2727
run: |
2828
sudo apt-get update
2929
sudo apt-get install -y rsync
30+
31+
- name: Create .env file from secret
32+
run: |
33+
# Create .env file from GitHub secret
34+
echo "${{ secrets.ENV_FILE_CONTENT }}" > .env
35+
36+
# Print confirmation (without showing the content for security)
37+
echo "Created .env file with $(grep -c '' .env) lines"
3038
3139
- name: Deploy to server
3240
run: |
@@ -38,13 +46,13 @@ jobs:
3846
echo "Files in bin directory:"
3947
ls -la ./bin
4048
41-
# Run deploy script
42-
./bin/deploy.sh
49+
# Run deploy script with full hostname
50+
DEPLOY_REMOTE_HOST=profullstack.com ./bin/deploy.sh
4351
4452
# Run test script to verify deployment
4553
echo "Running test script on remote server..."
46-
ssh profullstack "cd $DEPLOY_REMOTE_DIR && chmod +x bin/test-github-actions.sh && ./bin/test-github-actions.sh"
54+
ssh profullstack.com "cd $DEPLOY_REMOTE_DIR && chmod +x bin/test-github-actions.sh && ./bin/test-github-actions.sh"
4755
env:
48-
DEPLOY_REMOTE_HOST: profullstack
56+
DEPLOY_REMOTE_HOST: profullstack.com
4957
DEPLOY_REMOTE_DIR: www/profullstack.com/pdf
5058
INSTALL_SERVICE: true

README.md

Lines changed: 102 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,31 @@ This repository is configured to automatically deploy to the production server w
2424
ssh ubuntu@profullstack "echo 'your-public-key-here' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
2525
```
2626

27-
3. **Add the private key to GitHub Secrets**:
27+
3. **Add the required secrets to GitHub**:
2828
- Go to your GitHub repository
2929
- Click on "Settings" > "Secrets and variables" > "Actions"
30+
- Add the following secrets:
31+
32+
a. **SSH Private Key**:
3033
- Click "New repository secret"
3134
- Name: `SSH_PRIVATE_KEY`
3235
- Value: Copy the entire content of your private key file (`~/.ssh/id_ed25519`)
3336
- Click "Add secret"
37+
38+
b. **Environment Variables**:
39+
- Click "New repository secret"
40+
- Name: `ENV_FILE_CONTENT`
41+
- Value: Copy the entire content of your .env file
42+
- Click "Add secret"
43+
44+
4. **Important Note About SSH Configuration**:
45+
- GitHub Actions doesn't have access to your local `~/.ssh/config` file
46+
- All scripts use the full hostname `profullstack.com` instead of any aliases
47+
- If you need to use a different hostname, update it in:
48+
- `.github/workflows/deploy.yml`
49+
- `bin/deploy.sh`
50+
- `bin/check-deployment.sh`
51+
- `bin/manual-deploy.sh`
3452

3553
4. **Verify GitHub Actions is enabled**:
3654
- Go to your repository on GitHub
@@ -60,6 +78,87 @@ If the deployment fails, check the following:
6078
- Ensure the deploy script has execute permissions
6179
- Check if the user has permission to write to the deployment directory
6280

63-
4. **Script Issues**:
81+
4. **Environment Variables Issues**:
82+
- Make sure the `ENV_FILE_CONTENT` secret is properly set in GitHub Secrets
83+
- Verify that all required environment variables are included in the secret
84+
- Check if the .env file is being created correctly in the workflow logs
85+
86+
5. **Script Issues**:
6487
- Review the deploy.sh script for any errors
65-
- Check the GitHub Actions logs for detailed error messages
88+
- Check the GitHub Actions logs for detailed error messages
89+
90+
## Deployment Troubleshooting Scripts
91+
92+
This repository includes several scripts to help troubleshoot deployment issues:
93+
94+
### Check Deployment Status
95+
96+
Run the following script to check if GitHub Actions deployment is working correctly:
97+
98+
```bash
99+
./bin/check-deployment.sh
100+
```
101+
102+
This script will:
103+
- Test SSH connection to the server
104+
- Check if the remote directory exists
105+
- Look for GitHub Actions test files
106+
- Create a new test file to verify write access
107+
- Check local Git configuration
108+
109+
### Manual Deployment
110+
111+
If GitHub Actions deployment isn't working, you can manually deploy using:
112+
113+
```bash
114+
./bin/manual-deploy.sh
115+
```
116+
117+
This script will:
118+
- Deploy your code using rsync
119+
- Make scripts executable on the remote host
120+
- Run the test script to verify deployment
121+
- Reload systemd daemon
122+
- Optionally install/restart the service
123+
124+
### Test Script
125+
126+
The test script creates a timestamped file on the server to verify deployment:
127+
128+
```bash
129+
./bin/test-github-actions.sh
130+
```
131+
132+
This is automatically run by both GitHub Actions and the manual deployment script.
133+
134+
### Check GitHub Actions Status
135+
136+
To check the status of your GitHub Actions workflows:
137+
138+
```bash
139+
./bin/check-github-actions.sh
140+
```
141+
142+
This script will:
143+
- Determine your GitHub repository from git remote
144+
- Check workflow status using GitHub CLI (if installed)
145+
- Fall back to using curl with a GITHUB_TOKEN
146+
- Show recent workflow runs and their status
147+
148+
This is particularly useful for diagnosing issues with GitHub Actions not running or failing.
149+
150+
### Test File for Triggering Workflows
151+
152+
The repository includes a test file that can be modified to trigger a workflow run:
153+
154+
```
155+
github-actions-test.txt
156+
```
157+
158+
To trigger a new workflow run:
159+
1. Edit the file
160+
2. Increment the "Deployment test" number
161+
3. Commit and push to master/main
162+
4. Check the Actions tab on GitHub to see if the workflow runs
163+
164+
This provides a simple way to test if GitHub Actions is properly configured without making significant code changes.

bin/check-deployment.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/zsh
2+
3+
# This script checks if the GitHub Actions deployment is working correctly
4+
5+
# Colors for output
6+
GREEN='\033[0;32m'
7+
RED='\033[0;31m'
8+
YELLOW='\033[0;33m'
9+
NC='\033[0m' # No Color
10+
11+
echo -e "${YELLOW}Checking GitHub Actions deployment...${NC}"
12+
13+
# Define variables with fallbacks
14+
REMOTE_HOST="${DEPLOY_REMOTE_HOST:-profullstack.com}"
15+
REMOTE_DIR="${DEPLOY_REMOTE_DIR:-www/profullstack.com/pdf}"
16+
17+
echo -e "${YELLOW}Configuration:${NC}"
18+
echo -e " Remote Host: ${GREEN}$REMOTE_HOST${NC}"
19+
echo -e " Remote Directory: ${GREEN}$REMOTE_DIR${NC}"
20+
21+
# Check if we can connect to the remote host
22+
echo -e "\n${YELLOW}Testing SSH connection to $REMOTE_HOST...${NC}"
23+
if ssh -o BatchMode=yes -o ConnectTimeout=5 $REMOTE_HOST "echo Connection successful"; then
24+
echo -e "${GREEN}SSH connection successful!${NC}"
25+
else
26+
echo -e "${RED}SSH connection failed. Check your SSH keys and server configuration.${NC}"
27+
exit 1
28+
fi
29+
30+
# Check if the remote directory exists
31+
echo -e "\n${YELLOW}Checking if remote directory exists...${NC}"
32+
if ssh $REMOTE_HOST "[ -d $REMOTE_DIR ]"; then
33+
echo -e "${GREEN}Remote directory exists!${NC}"
34+
else
35+
echo -e "${RED}Remote directory does not exist: $REMOTE_HOST:$REMOTE_DIR${NC}"
36+
exit 1
37+
fi
38+
39+
# Check for test files from GitHub Actions
40+
echo -e "\n${YELLOW}Checking for GitHub Actions test files...${NC}"
41+
TEST_FILES=$(ssh $REMOTE_HOST "find $REMOTE_DIR -name 'github-actions-test-*.txt' | sort -r | head -5")
42+
43+
if [ -z "$TEST_FILES" ]; then
44+
echo -e "${RED}No GitHub Actions test files found. Deployment may not be working.${NC}"
45+
else
46+
echo -e "${GREEN}Found GitHub Actions test files:${NC}"
47+
for file in $TEST_FILES; do
48+
echo -e " - $file"
49+
echo -e " Content: $(ssh $REMOTE_HOST "cat $file")"
50+
done
51+
fi
52+
53+
# Create a new test file to verify we can write to the server
54+
echo -e "\n${YELLOW}Creating a new test file...${NC}"
55+
TEST_FILE="manual-test-$(date +%Y%m%d%H%M%S).txt"
56+
ssh $REMOTE_HOST "echo 'Manual test at $(date)' > $REMOTE_DIR/$TEST_FILE"
57+
echo -e "${GREEN}Created test file: $REMOTE_DIR/$TEST_FILE${NC}"
58+
59+
# Check GitHub repository configuration
60+
echo -e "\n${YELLOW}Checking local Git configuration...${NC}"
61+
REMOTE_URL=$(git config --get remote.origin.url)
62+
echo -e " Git remote URL: ${GREEN}$REMOTE_URL${NC}"
63+
64+
CURRENT_BRANCH=$(git branch --show-current)
65+
echo -e " Current branch: ${GREEN}$CURRENT_BRANCH${NC}"
66+
67+
# Check for .github/workflows directory
68+
if [ -d ".github/workflows" ]; then
69+
echo -e " ${GREEN}GitHub workflows directory exists${NC}"
70+
echo -e " Workflow files:"
71+
for file in .github/workflows/*; do
72+
echo -e " - $file"
73+
done
74+
else
75+
echo -e " ${RED}GitHub workflows directory does not exist${NC}"
76+
fi
77+
78+
echo -e "\n${YELLOW}Deployment check completed.${NC}"
79+
echo -e "${YELLOW}If you're still having issues, check:${NC}"
80+
echo -e " 1. GitHub repository Actions tab for workflow runs"
81+
echo -e " 2. SSH key configuration in GitHub Secrets"
82+
echo -e " 3. Server logs for any errors"
83+
echo -e " 4. Make sure your changes are committed and pushed to the correct branch (master or main)"

bin/check-github-actions.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/zsh
2+
3+
# This script checks the status of GitHub Actions workflows for the repository
4+
5+
# Colors for output
6+
GREEN='\033[0;32m'
7+
RED='\033[0;31m'
8+
YELLOW='\033[0;33m'
9+
NC='\033[0m' # No Color
10+
11+
echo -e "${YELLOW}Checking GitHub Actions workflow status...${NC}"
12+
13+
# Try to get the GitHub repository from the git remote
14+
REMOTE_URL=$(git config --get remote.origin.url)
15+
echo -e "Git remote URL: ${GREEN}$REMOTE_URL${NC}"
16+
17+
# Extract owner and repo from the remote URL
18+
if [[ $REMOTE_URL =~ github\.com[:/]([^/]+)/([^/.]+) ]]; then
19+
OWNER=${BASH_REMATCH[1]}
20+
REPO=${BASH_REMATCH[2]}
21+
22+
echo -e "Repository owner: ${GREEN}$OWNER${NC}"
23+
echo -e "Repository name: ${GREEN}$REPO${NC}"
24+
25+
# Check if GitHub CLI is installed
26+
if command -v gh &> /dev/null; then
27+
echo -e "\n${YELLOW}Using GitHub CLI to check workflow status...${NC}"
28+
29+
# Check if authenticated
30+
if gh auth status &> /dev/null; then
31+
echo -e "${GREEN}Authenticated with GitHub CLI${NC}"
32+
33+
# List workflows
34+
echo -e "\n${YELLOW}Listing workflows:${NC}"
35+
gh workflow list -R $OWNER/$REPO
36+
37+
# List recent workflow runs
38+
echo -e "\n${YELLOW}Recent workflow runs:${NC}"
39+
gh run list -R $OWNER/$REPO -L 5
40+
41+
# Get the latest workflow run
42+
echo -e "\n${YELLOW}Latest workflow run:${NC}"
43+
LATEST_RUN_ID=$(gh run list -R $OWNER/$REPO -L 1 --json databaseId --jq '.[0].databaseId')
44+
45+
if [ -n "$LATEST_RUN_ID" ]; then
46+
gh run view $LATEST_RUN_ID -R $OWNER/$REPO
47+
else
48+
echo -e "${RED}No workflow runs found${NC}"
49+
fi
50+
else
51+
echo -e "${RED}Not authenticated with GitHub CLI. Run 'gh auth login' to authenticate.${NC}"
52+
fi
53+
else
54+
echo -e "${RED}GitHub CLI not installed. Using curl to check workflow status...${NC}"
55+
56+
# Check if GITHUB_TOKEN is set
57+
if [ -n "$GITHUB_TOKEN" ]; then
58+
echo -e "${GREEN}GITHUB_TOKEN is set${NC}"
59+
60+
# List workflows
61+
echo -e "\n${YELLOW}Listing workflows:${NC}"
62+
curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$OWNER/$REPO/actions/workflows" | grep -E '"name"|"path"'
63+
64+
# List recent workflow runs
65+
echo -e "\n${YELLOW}Recent workflow runs:${NC}"
66+
curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$OWNER/$REPO/actions/runs?per_page=5" | grep -E '"id"|"name"|"status"|"conclusion"'
67+
else
68+
echo -e "${RED}GITHUB_TOKEN not set. Please set it to access the GitHub API.${NC}"
69+
echo -e "You can create a token at https://github.com/settings/tokens"
70+
echo -e "Then set it with: export GITHUB_TOKEN=your_token"
71+
fi
72+
fi
73+
else
74+
echo -e "${RED}Could not determine repository owner and name from remote URL${NC}"
75+
echo -e "${YELLOW}Please check your git configuration or provide the repository information manually${NC}"
76+
fi
77+
78+
echo -e "\n${YELLOW}GitHub Actions check completed.${NC}"
79+
echo -e "${YELLOW}If you're still having issues, check:${NC}"
80+
echo -e " 1. GitHub repository Actions tab for workflow runs"
81+
echo -e " 2. Make sure GitHub Actions is enabled for the repository"
82+
echo -e " 3. Check if the workflow file is in the correct location (.github/workflows/deploy.yml)"
83+
echo -e " 4. Verify that you have the necessary permissions to run workflows"

bin/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ else
99
fi
1010

1111
# Define variables with fallbacks
12-
REMOTE_HOST="${DEPLOY_REMOTE_HOST:-profullstack}"
12+
REMOTE_HOST="${DEPLOY_REMOTE_HOST:-profullstack.com}"
1313
REMOTE_DIR="${DEPLOY_REMOTE_DIR:-www/profullstack.com/pdf}"
1414
LOCAL_DIR="."
1515
INSTALL_SERVICE="${INSTALL_SERVICE:-false}"

0 commit comments

Comments
 (0)