Skip to content

Create and remove the emailformgateway dir as separate steps #23

Create and remove the emailformgateway dir as separate steps

Create and remove the emailformgateway dir as separate steps #23

# Copyright (c) 2024 Owen Waller. All rights reserved.
name: Email_Form_Gateway_Build_Test_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
- name: Download and install go
uses: actions/setup-go@v5
with:
go-version: '1.22.0'
- name: Print Go version
run: go version
- name: Run tests
run: go test -skip=SendEmail github.com/owenwaller/emailformgateway/...
- name: Build emailer test
run: go test -c -o ./emailer.test -run=SendEmail github.com/owenwaller/emailformgateway/emailer
- name: Build server test
run: go test -c -o ./server.test -run=SendEmail github.com/owenwaller/emailformgateway/server
- name: Build emailformgateway server
run: go build -o ./emailformgateway ./cmd/main.go
- name: Listing
run: 'ls -al'
- 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
END
env:
SSH_KEY: ${{ secrets.GOPHERCODERS_SERVER_SSH_KEY }}
SSH_USER: ${{ secrets.GOPHERCODERS_SERVER_USERNAME }}
SSH_HOST: ${{ secrets.GOPHERCODERS_SERVER_HOSTNAME }}
SSH_PORT: ${{ secrets.GOPHERCODERS_SERVER_PORT }}
- name: List public dir
run: ssh gophercoders.com 'whoami; ls -l ~/'
- name: Create env file
run: |
cat >> ./test_envs.sh <<END
export TEST_CUSTOMER_TO_EMAIL_ADDRESS=$TEST_CUSTOMER_TO_EMAIL_ADDRESS
export TEST_SYSTEM_TO_EMAIL_ADDRESS=$TEST_SYSTEM_TO_EMAIL_ADDRESS
export TEST_CONFIG_FILE=$TEST_CONFIG_FILE
export TEST_SMTP_HOST=$TEST_SMTP_HOST
export TEST_SMTP_PORT=$TEST_SMTP_PORT
export TEST_AUTH_USERNAME=$TEST_AUTH_USERNAME
export TEST_AUTH_PASSWORD=$TEST_AUTH_PASSWORD
END
env:
TEST_CUSTOMER_TO_EMAIL_ADDRESS: ${{ secrets.TEST_CUSTOMER_TO_EMAIL_ADDRESS }}
TEST_SYSTEM_TO_EMAIL_ADDRESS: ${{ secrets.TEST_SYSTEM_TO_EMAIL_ADDRESS }}
TEST_CONFIG_FILE: ${{ secrets.TEST_CONFIG_FILE }}
TEST_SMTP_HOST: ${{ secrets.TEST_SMTP_HOST }}
TEST_SMTP_PORT: ${{ secrets.TEST_SMTP_PORT }}
TEST_AUTH_USERNAME: ${{ secrets.TEST_AUTH_USERNAME }}
TEST_AUTH_PASSWORD: ${{ secrets.TEST_AUTH_PASSWORD }}
- name: Create emailformgateway directory on server
run: ssh gophercoders.com 'mkdir -p emailformgateway' # directory is relative to home directory on the server
- name: Copy files to server
run: |
scp ./emailformgateway ./test_envs.sh ./emailer.test ./server.test ./*.template ./gophercoders-config.toml $TEST_CONFIG_FILE.toml gophercoders.com:emailformgateway
env:
TEST_CONFIG_FILE: ${{ secrets.TEST_CONFIG_FILE }}
- name: Run emailer.test test
run: |
ssh gophercoders.com 'source ./test_envs.sh; TEST_TEMPLATES_DIR=$PWD TEST_DOMAIN=gophercoders.com ./emailer.test'
- name: Run server.test test
run: |
ssh gophercoders.com 'source ./test_envs.sh; TEST_TEMPLATES_DIR=$PWD TEST_DOMAIN=example.com ./server.test'
- name: Stop emailformgateway service
run: ssh gophercoders.com 'sudo /usr/bin/systemctl stop emailfromgateway-gophercoders.service'
- name: Copy the emailformgateway binary to /usr/local/bin
run: ssh gophercoders.com 'sudo /usr/bin/cp ~/emailformgateway/emailformgateway /usr/local/bin' # ASSUMES config is in /etc/emailformgateway. This has to be done externally
- name: Remove emailformgateway directory from server
run: ssh gophercoders.com 'sudo 'rm -rf emailformgateway'
- name: Restart emailformgateway service
if: ${{ always() }}
run: ssh gophercoders.com 'sudo /usr/bin/systemctl restart emailfromgateway-gophercoders.service'
- name: Delete dirs
if: ${{ always() }}
run: |
rm -rf ~/.ssh
rm ./test_envs.sh