Don't delete the GITHUB_WORKSPACE directory at the end #25
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: GopherCoders_Build_And_Deploy | |
on: [push, pull_request] | |
jobs: | |
deploy: | |
name: "Deploy to senpaid" | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' && github.ref == 'refs/heads/master' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 # the repo will be checked out to ~/work/website/website - subsequent commands run inside this directory. This is the GITHUB_WORKSPACE env var value | |
- name: Listing | |
run: | | |
ls -al | |
- name: Download and install hugo | |
run: | | |
RELEASE=`curl "https://api.github.com/repos/gohugoio/hugo/tags" | jq -r '.[0].name'` | |
echo $RELEASE | |
RELEASENOV="${RELEASE:1}" | |
echo $RELEASENOV | |
curl -L "https://github.com/gohugoio/hugo/releases/download/${RELEASE}/hugo_${RELEASENOV}_linux-amd64.deb" --output ./hugo_${RELEASENOV}_linux-amd64.deb | |
sudo apt-get install ./hugo_${RELEASENOV}_linux-amd64.deb | |
- name: Build Website | |
run: | | |
pwd | |
ls -l ~/ | |
hugo | |
ls -l ./public | |
- name: Configure SSH | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_KEY" > ~/.ssh/gophercoders.key | |
chmod 600 ~/.ssh/gophercoders.key | |
cat >>~/.ssh/config <<END | |
Host gophercoders.com | |
HostName $SSH_HOST | |
User $SSH_USER | |
Port $SSH_PORT | |
IdentityFile ~/.ssh/gophercoders.key | |
StrictHostKeyChecking no | |
ProxyCommand openssl s_client -quiet -connect senpaid.com:$SSH_PORT -servername www.gophercoders.com | |
END | |
env: | |
SSH_KEY: ${{ secrets.SENPAID_SERVER_SSH_KEY }} | |
SSH_USER: ${{ secrets.SENPAID_SERVER_USERNAME }} | |
SSH_HOST: ${{ secrets.SENPAID_SERVER_HOSTNAME }} | |
SSH_PORT: ${{ secrets.SENPAID_SERVER_PORT }} | |
- name: List public dir | |
run: ssh gophercoders.com 'whoami; ls -l ~/public' | |
- name: Delete gophercoders.com on remote | |
run: ssh gophercoders.com 'rm -rf ~/gophercoders.com' | |
- name: Make gophercoders.com on the remote | |
run: ssh gophercoders.com 'mkdir ~/gophercoders.com' | |
- name: Copy website pages and assets | |
run: scp -r ./public/* gophercoders.com:~/gophercoders.com/ | |
- name: Stop nginx | |
run: ssh gophercoders.com 'sudo service nginx stop' | |
- name: Copy website pages and assets to /www on remote | |
run: ssh gophercoders.com 'sudo cp -r ~/gophercoders.com/* /www/gophercoders.com/' | |
- name: Restart nginx | |
if: ${{ always() }} | |
run: ssh gophercoders.com 'sudo service nginx restart' | |
- name: Delete ssh dir | |
if: ${{ always() }} | |
run: | | |
rm -rf ~/.ssh |