fix: workflow job #10
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 to EC2 | |
on: | |
push: | |
branches: | |
- master # Replace with your branch name | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Configure SSH | |
env: | |
EC2_PRIVATE_KEY: ${{ secrets.EC2_PRIVATE_KEY }} | |
run: | | |
mkdir -p ~/.ssh | |
echo "$EC2_PRIVATE_KEY" > ~/.ssh/id_rsa | |
chmod 400 ~/.ssh/id_rsa | |
- name: Clone repository on EC2 | |
env: | |
EC2_HOST: ${{ secrets.EC2_HOST }} | |
EC2_USER: ${{ secrets.EC2_USER }} | |
run: | | |
ssh -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST ' | |
cd /home/ec2-user/rashan | |
git pull origin master | |
' | |
- name: Create .env file | |
env: | |
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
DEPLOYMENT: ${{ secrets.DEPLOYMENT }} | |
run: | | |
echo "ACCESS_TOKEN=$ACCESS_TOKEN" > .env | |
echo "DEPLOYMENT=$DEPLOYMENT" >> .env | |
- name: Upload .env file to EC2 | |
env: | |
EC2_HOST: ${{ secrets.EC2_HOST }} | |
EC2_USER: ${{ secrets.EC2_USER }} | |
run: | | |
scp -o StrictHostKeyChecking=no .env $EC2_USER@$EC2_HOST:/home/ec2-user/rashan/.env | |
- name: Run bot | |
env: | |
EC2_HOST: ${{ secrets.EC2_HOST }} | |
EC2_USER: ${{ secrets.EC2_USER }} | |
run: | | |
ssh -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST ' | |
sudo -i | |
cd /home/ec2-user/rashan | |
chmod +x install.sh | |
sh install.sh | |
' | |