Merge pull request #590 from GermanZero-de/deploy-to-testing #73
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: Deploy | |
on: | |
push: | |
branches: [deploy-to-testing, newfe-to-testing, deploy-to-production] | |
workflow_dispatch: | |
jobs: | |
get-environment: | |
name: Determine the environment for the deployment from the branch name | |
runs-on: ubuntu-latest | |
outputs: | |
environment: ${{ steps.determine-environment.outputs.environment }} | |
source: ${{ steps.determine-environment.outputs.source }} | |
url: ${{ steps.determine-environment.outputs.url }} | |
steps: | |
- id: determine-environment | |
name: Determine environment | |
run: | | |
case $GITHUB_REF in | |
refs/heads/deploy-to-production) | |
echo "environment=production" | |
echo "source=main" | |
echo "url=https://monitoring.localzero.net/" | |
;; | |
refs/heads/deploy-to-testing) | |
echo "environment=testing" | |
echo "source=main" | |
echo "url=https://monitoring-test.localzero.net/" | |
;; | |
refs/heads/newfe-to-testing) | |
echo "environment=testing" | |
echo "source=newfe" | |
echo "url=https://monitoring-test.localzero.net/" | |
;; | |
*) | |
echo "not an environment: $GITHUB_REF - should be refs/heads/deploy-to-{testing|production} or refs/heads/newfe-to-testing" | |
;; | |
esac >> $GITHUB_OUTPUT | |
deploy: | |
name: Deploy to ${{ needs.get-environment.outputs.environment }} | |
runs-on: ubuntu-latest | |
needs: get-environment | |
environment: | |
name: ${{ needs.get-environment.outputs.environment }} | |
url: ${{ needs.get-environment.outputs.url }} | |
env: | |
ENVIRONMENT: ${{ needs.get-environment.outputs.environment }} | |
SOURCE: ${{ needs.get-environment.outputs.source }} | |
URL: ${{ needs.get-environment.outputs.url }} | |
DIR: ${{ vars.DEPLOY_TO_DIR }} # Set here: https://github.com/GermanZero-de/klimaschutzmonitor/settings/variables/actions | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install SSH key | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
name: id_lzm | |
key: ${{ secrets.LZM_SSH_PRIVATE_KEY }} | |
known_hosts: ${{ secrets.LZM_SSH_KNOWN_HOSTS }} | |
config: | | |
Host monitoring.localzero.net monitoring-test.localzero.net lzm | |
HostName monitoring.localzero.net | |
User monitoring | |
IdentityFile ~/.ssh/id_lzm | |
- name: Run deploy script | |
shell: bash | |
run: | | |
chmod u+x deploy.sh | |
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" | |
git config --global user.name "$GITHUB_ACTOR" | |
./deploy.sh "$ENVIRONMENT" "$SOURCE" | |
- name: Restore last production backup to testing if we deployed to testing | |
if: needs.get-environment.outputs.environment == 'testing' | |
shell: bash | |
run: | | |
ssh -tt monitoring.localzero.net /bin/bash << EOF | |
set -e | |
./start-testing-with-prod-data.sh | |
exit | |
EOF |