update #7
This file contains hidden or 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 homepage | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'website/**' | |
| - '.github/workflows/deploy-homepage.yml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: homepage-production | |
| cancel-in-progress: true | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| env: | |
| DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} | |
| DEPLOY_USER: ${{ secrets.DEPLOY_USER }} | |
| DEPLOY_PORT: ${{ secrets.DEPLOY_PORT || '22' }} | |
| DEPLOY_PATH: ${{ secrets.DEPLOY_PATH || '/www/wwwroot/homepage/homepage-1.3' }} | |
| steps: | |
| - name: Check out repository with Git LFS | |
| uses: actions/checkout@v4 | |
| with: | |
| lfs: true | |
| - name: Configure SSH | |
| shell: bash | |
| env: | |
| DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} | |
| DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }} | |
| run: | | |
| set -euo pipefail | |
| test -n "$DEPLOY_HOST" | |
| test -n "$DEPLOY_USER" | |
| test -n "$DEPLOY_SSH_KEY" | |
| test -n "$DEPLOY_KNOWN_HOSTS" | |
| install -m 700 -d "$HOME/.ssh" | |
| printf '%s\n' "$DEPLOY_SSH_KEY" > "$HOME/.ssh/id_ed25519" | |
| printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$HOME/.ssh/known_hosts" | |
| chmod 600 "$HOME/.ssh/id_ed25519" "$HOME/.ssh/known_hosts" | |
| - name: Deploy homepage to production | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| test "$DEPLOY_PATH" = '/www/wwwroot/homepage/homepage-1.3' | |
| ssh_options=( | |
| -p "$DEPLOY_PORT" | |
| -i "$HOME/.ssh/id_ed25519" | |
| -o IdentitiesOnly=yes | |
| -o StrictHostKeyChecking=yes | |
| ) | |
| target="$DEPLOY_USER@$DEPLOY_HOST" | |
| staging_dir="$DEPLOY_PATH/.deploy-staging-$GITHUB_RUN_ID" | |
| ssh "${ssh_options[@]}" "$target" "rm -rf '$staging_dir' && mkdir -p '$staging_dir'" | |
| tar -C website -czf - . | ssh "${ssh_options[@]}" "$target" "tar -xzf - -C '$staging_dir'" | |
| ssh "${ssh_options[@]}" "$target" "find '$DEPLOY_PATH' -mindepth 1 -maxdepth 1 ! -name '.deploy-staging-$GITHUB_RUN_ID' -exec rm -rf {} + && find '$staging_dir' -mindepth 1 -maxdepth 1 -exec mv -t '$DEPLOY_PATH' {} + && rmdir '$staging_dir'" |