Skip to content

Merge pull request #1 from exploded/claude/github-linode-deployment-t… #2

Merge pull request #1 from exploded/claude/github-linode-deployment-t…

Merge pull request #1 from exploded/claude/github-linode-deployment-t… #2

Workflow file for this run

name: Test and Deploy
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: true
- name: Download dependencies
run: go mod download
- name: Run tests
run: go test -v ./...
deploy:
name: Deploy to Production
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: true
- name: Download dependencies
run: go mod download
- name: Build Linux binary
run: GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o moon .
- name: Copy files to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
port: ${{ secrets.DEPLOY_PORT || 22 }}
source: "moon,index.html,about.html,calendar.html,static/"
target: "/tmp/moon-deploy"
overwrite: true
- name: Install and restart service
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
port: ${{ secrets.DEPLOY_PORT || 22 }}
script: |
set -e
DEPLOY_SRC=/tmp/moon-deploy
# Install binary
sudo cp "$DEPLOY_SRC/moon" /usr/local/bin/moon
sudo chmod +x /usr/local/bin/moon
# Update web assets
sudo cp "$DEPLOY_SRC/index.html" /var/www/moon/
sudo cp "$DEPLOY_SRC/about.html" /var/www/moon/
sudo cp "$DEPLOY_SRC/calendar.html" /var/www/moon/
sudo cp -r "$DEPLOY_SRC/static/" /var/www/moon/
sudo chown -R www-data:www-data /var/www/moon
# Restart service
sudo systemctl restart moon
# Verify it came back up
sleep 2
sudo systemctl is-active moon
# Clean up
rm -rf "$DEPLOY_SRC"
echo "Deployment complete"