deploy to main mail #38
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & Deploy | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ master ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Build | |
run: make | |
- name: Archive production artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build | |
path: ./roundcubemail-1.7-git.tar.gz | |
- name: Archive production artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-complete | |
path: ./roundcubemail-1.7-git-complete.tar.gz | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
env: | |
SSH_USER: github | |
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
SSH_HOST: 194.36.146.51 | |
REPO_NAME: ${{ github.event.repository.name }} | |
steps: | |
- name: Download production artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-complete | |
- name: Install ssh key | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_KEY" > ~/.ssh/staging.key | |
chmod 600 ~/.ssh/staging.key | |
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts | |
- name: Configure SSH | |
run: | | |
cat >>~/.ssh/config <<END | |
Host staging | |
HostName $SSH_HOST | |
User $SSH_USER | |
IdentityFile ~/.ssh/staging.key | |
StrictHostKeyChecking no | |
END | |
- name: Check SSH Connection | |
run: ssh staging 'echo "It works!"' | |
- name: Delete previous deploy files | |
run: ssh staging "sudo rm -r /home/$SSH_USER/$REPO_NAME/*" | |
continue-on-error: true | |
- name: Deploy build | |
run: rsync -avz -e 'ssh -i ~/.ssh/staging.key -o StrictHostKeyChecking=no' --progress ./roundcubemail-1.7-git-complete.tar.gz $SSH_USER@$SSH_HOST:/home/$SSH_USER/$REPO_NAME | |
- name: Unzip | |
run: ssh staging "cd /home/$SSH_USER/$REPO_NAME/ && sudo tar --no-same-owner --no-same-permissions -xf roundcubemail-1.7-git-complete.tar.gz" | |
- name: Replace Config variables | |
run: | | |
ssh staging "sudo sed -i 's@!<oauth_client_id>@${{ secrets.OAUTH_CLIENT_ID }}@g' /home/$SSH_USER/$REPO_NAME/roundcubemail-1.7-git/config/config.inc.php" | |
ssh staging "sudo sed -i 's@!<oauth_client_secret>@${{ secrets.OAUTH_CLIENT_SECRET }}@g' /home/$SSH_USER/$REPO_NAME/roundcubemail-1.7-git/config/config.inc.php" | |
- name: Delete current deployed files | |
run: ssh staging 'sudo rm -r -d /var/www/mail/' | |
continue-on-error: true | |
- name: Copy files | |
run: ssh staging "sudo rsync -a --ignore-existing /home/$SSH_USER/$REPO_NAME/roundcubemail-1.7-git/ /var/www/mail/" | |
- name: Set permissions | |
run: ssh staging "sudo chown -R www-data:www-data /var/www/mail/" |