Skip to content

Instantly share code, notes, and snippets.

@walidmahade
Last active February 22, 2024 04:29
Show Gist options
  • Save walidmahade/e59c157624ac102c3100285d392b37b6 to your computer and use it in GitHub Desktop.
Save walidmahade/e59c157624ac102c3100285d392b37b6 to your computer and use it in GitHub Desktop.
Github actions example - Deploy react app using SFTP
# Optional - The name of the workflow, appears in the "Actions" tab of the GitHub repository. If this field is omitted, the name of the workflow file will be used instead.
name: deploy-app-to-production
# Optional - The name for workflow runs generated from the workflow.
# This example uses an expression with the `github` context to display the username."
# See full list of available context objects: https://docs.github.com/en/actions/learn-github-actions/contexts
run-name: ${{ github.actor }} is deploying to cpanel
# The trigger for this workflow
# you can target multiple branches by adding one branch per line
on:
push:
branches:
- "main"
# Groups together all the jobs that run in the `deploy-app-to-production` workflow.
jobs:
# JOB_ID, you can use this ID to reference the job in other parts of the workflow
deploy_job:
runs-on: ubuntu-latest # Configures the job to run on the latest version of an Ubuntu Linux runner.
name: deploy # Optional - The name of the job, appears in the "Actions" tab of the GitHub repository.
# Groups together all the steps that run in the `check-bats-version` job. Each item nested under this section is a separate action or shell script.
steps:
# STEP 1
# The `uses` keyword specifies that this step will run `v4` of the `actions/checkout` action.
- name: Checkout # Optional - The name of the step, appears in the "Actions" tab of the GitHub repository.
uses: actions/checkout@v4 # The `uses` keyword specifies the action or shell script to run for this step.
# STEP 2
# This step uses the `actions/setup-node@v3` action to install the specified version of the Node.js.
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
# STEP 3
- name: Install dependencies
run: yarn --frozen-lockfile
# STEP 4
- name: Build the app # Optional - The name of the step, appears in the "Actions" tab of the GitHub repository.
run: yarn build # The `run` keyword specifies the shell commands to run for this step.
# STEP 5
- name: deploy app to server
uses: wlixcc/SFTP-Deploy-Action@v1.2.4
with:
username: "CPANEL_USER_NAME"
server: "00.00.000.000"
port: ${{ secrets.SFTP_PORT }}
local_path: "./dist/*"
remote_path: "/full/path/to/target/folder"
sftp_only: true
password: ${{ secrets.SFTP_PASSWORD }}
# THE END
name: learn-github-actions
run-name: ${{ github.actor }} is deploying to cpanel
on:
push:
branches:
- "main"
jobs:
deploy_job:
runs-on: ubuntu-latest
name: deploy
steps:
- name: Checkout
uses: actions/checkout@v4
- name: deploy file
uses: wlixcc/SFTP-Deploy-Action@v1.2.4
with:
username: "CPANEL_USER_NAME"
server: "00.000.00.000"
port: ${{ secrets.SFTP_PORT }}
local_path: "./*"
remote_path: "/full/path/to/target/folder"
sftp_only: true
password: ${{ secrets.SFTP_PASSWORD }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment