From 90ffbd0faa9d07cbf94d3dca8e746723e6434afa Mon Sep 17 00:00:00 2001 From: yankewei Date: Wed, 10 Aug 2022 00:35:34 +0800 Subject: [PATCH] Updata action --- .github/workflows/main.yml | 3 ++- .gitignore | 1 + Envoy.blade.php | 6 ------ README.md | 35 +++++++++++++++++++++++++++++++++++ action.yaml | 25 ++++++++++++++----------- deploy.php | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 .gitignore delete mode 100644 Envoy.blade.php create mode 100644 deploy.php diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d568665..9b95b2e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,4 +11,5 @@ jobs: with: host: ${{ secrets.SSH_HOST }} username: ${{ secrets.SSH_USERNAME }} - ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} \ No newline at end of file + password: ${{ secrets.SSH_PASSWORD }} + app_env_data: ${{ secrets.APP_ENV_DATA }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..757fee3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea \ No newline at end of file diff --git a/Envoy.blade.php b/Envoy.blade.php deleted file mode 100644 index f9c4467..0000000 --- a/Envoy.blade.php +++ /dev/null @@ -1,6 +0,0 @@ -@servers(['web' => '8.210.56.133']) - -@task('deploy') - cd /path/to/site - git pull origin master -@endtask \ No newline at end of file diff --git a/README.md b/README.md index 7fd9d7f..c162a9e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,37 @@ # laravel-deploy-action Automatically deploy your Laravel app to remote server + +### Step one +You need to create four environments that we need to connect the remote server, then create your workflow like below +```yaml +name: Deoloy +on: [push] + +jobs: + deploy: + runs-on: ubuntu-latest + name: A Laravel deploy action example + steps: + - name: test + uses: yankewei/laravel-deploy-action@main + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + app_env_data: ${{ secrets.APP_ENV_DATA }} +``` +Below is the environment description +```yaml + host: + description: 'The remote server ip, support IPV4 only' + required: true + username: + description: 'The ssh login user name' + required: true + password: + description: 'The ssh login password' + required: true + app_env_data: + description: 'The environment variable for application, will be written into .env file' + required: true +``` \ No newline at end of file diff --git a/action.yaml b/action.yaml index f7cc250..9fdabb0 100644 --- a/action.yaml +++ b/action.yaml @@ -7,9 +7,12 @@ inputs: username: description: 'The ssh login user name' required: true - ssh_private_key: - description: 'The ssh private key, will be stored into .ssh/github_action' - requierd: true + password: + description: 'The ssh login password' + required: true + app_env_data: + description: 'The environment variable for application, will be written into .env file' + required: true runs: using: 'composite' @@ -20,13 +23,13 @@ runs: with: php-version: '8.1' tools: composer:v2 + extensions: ssh2 - - name: deploy your application + - name: Deploy + env: + HOST: ${{ inputs.host }} + USERNAME: ${{ inputs.username }} + PASSWORD: ${{ inputs.password }} + APP_ENV_DATA: ${{ inputs.app_env_data }} shell: bash - run: | - mkdir ~/.ssh - touch ~/.ssh/github_action - echo '${{ inputs.ssh_private_key }}' >> ~/.ssh/github_action - cd ${{ github.workspace }} - composer require "laravel/envoy:^2.0" - cat Envoy.blade.php + run: php ${{ github.workspace }}/deploy.php \ No newline at end of file diff --git a/deploy.php b/deploy.php new file mode 100644 index 0000000..bd7fdf7 --- /dev/null +++ b/deploy.php @@ -0,0 +1,38 @@ + .env;'; +foreach ($env_array as $value) { + $cmd .= "echo $value >> .env;"; +} + +// Run command and deploy application +$cmd .= 'php artisan down;'; +$cmd .= 'git pull origin main;'; +$cmd .= 'composer install --no-dev;'; +$cmd .= 'php artisan migrate --force;'; +$cmd .= 'php artisan optimize;'; +$cmd .= 'php artisan up;'; + +$stream = ssh2_exec($ssh_session, $cmd); + +echo stream_get_contents($stream); + +ssh2_disconnect($ssh_session); \ No newline at end of file