Skip to content

Deploy to FTPS

Deploy to FTPS #37

Workflow file for this run

name: Deploy to FTPS
on:
schedule:
- cron: "15 23 * * *"
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
# 1. Checkout the repository code
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
# 2. Check for the 'deployed' tag
- name: Check Deployment Tag
run: |
LATEST_COMMIT=$(git rev-parse HEAD)
if git rev-parse -q --verify "refs/tags/deployed" > /dev/null; then
DEPLOYED_COMMIT=$(git rev-list -n 1 deployed)
echo "Last deployed commit: $DEPLOYED_COMMIT"
echo "Latest commit: $LATEST_COMMIT"
if [ "$LATEST_COMMIT" = "$DEPLOYED_COMMIT" ]; then
echo "No changes since last deployment."
echo "skip_deployment=true" >> $GITHUB_ENV
else
echo "Changes detected since last deployment."
echo "skip_deployment=false" >> $GITHUB_ENV
fi
else
echo "No previous deployment found."
echo "skip_deployment=false" >> $GITHUB_ENV
fi
# 3. Set up PHP and Composer
- name: Set up PHP
if: env.skip_deployment == 'false'
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
tools: composer
- name: Install Composer Dependencies
if: env.skip_deployment == 'false'
run: composer install --no-dev --optimize-autoloader
# 4. Prepare flags/maintenance.flag file locally
- name: Create Maintenance Flag Locally
if: env.skip_deployment == 'false'
run: |
mkdir flags
echo "Maintenance Mode Enabled" > flags/maintenance.flag
# 5. Upload maintenance.flag to /flags directory
- name: Upload Maintenance Flag
if: env.skip_deployment == 'false'
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
with:
server: ${{ secrets.FTP_HOST }}
username: ${{ secrets.FTP_LOGIN }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: ./flags/
server-dir: /flags/
dangerous-clean-slate: true
# 6. Deploy files to FTPS server
- name: Deploy to FTPS Server
if: env.skip_deployment == 'false'
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
with:
server: ${{ secrets.FTP_HOST }}
username: ${{ secrets.FTP_LOGIN }}
password: ${{ secrets.FTP_PASSWORD }}
# 7. Remove the flags/maintenance.flag file locally
- name: Remove Maintenance Flag Locally
if: env.skip_deployment == 'false'
run: |
rm flags/maintenance.flag
# 8. Upload maintenance.flag to /flags directory
- name: Remove Maintenance Flag from Server
if: env.skip_deployment == 'false'
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
with:
server: ${{ secrets.FTP_HOST }}
username: ${{ secrets.FTP_LOGIN }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: ./flags/
server-dir: /flags/
dangerous-clean-slate: true
# 9. Tag the commit as 'deployed'
- name: Update Deployment Tag
if: env.skip_deployment == 'false'
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git tag -d deployed || true
git push --delete origin refs/tags/deployed || true
git tag -a deployed -m "Deployed at $(date)"
git push origin deployed